Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use P4Runtime batch to clear all P4 tables #464

Merged
merged 6 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pfcpiface/p4rtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,36 @@ func (c *P4rtClient) ClearTable(tableID uint32) error {
return c.WriteBatchReq(updates)
}

func (c *P4rtClient) ClearTables(tableIDs []uint32) error {
log.Traceln("Clearing P4 tables")

updates := []*p4.Update{}

for _, tableID := range tableIDs {
entry := &p4.TableEntry{
TableId: tableID,
Priority: DefaultPriority,
}

readRes, err := c.ReadTableEntry(entry)
if err != nil {
return err
}

for _, entity := range readRes.GetEntities() {
updateType := p4.Update_DELETE
update := &p4.Update{
Type: updateType,
Entity: entity,
}

updates = append(updates, update)
}
}

return c.WriteBatchReq(updates)
}

// InsertTableEntry .. Insert table Entry.
func (c *P4rtClient) InsertTableEntry(entry *p4.TableEntry, funcType uint8) error {
log.Println("Insert Table Entry for Table ", entry.TableId)
Expand Down Expand Up @@ -330,6 +360,7 @@ func (c *P4rtClient) ApplyTableEntries(methodType p4.Update_Type, entries ...*p4
},
}
log.Traceln("Writing table entry: ", proto.MarshalTextString(update))

updates = append(updates, update)
}

Expand Down
61 changes: 9 additions & 52 deletions pfcpiface/up4.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,62 +372,19 @@ func (up4 *UP4) setUpfInfo(u *upf, conf *Conf) {
}

func (up4 *UP4) clearAllTables() error {
sessionsUplinkTableID, err := up4.p4RtTranslator.getTableIDByName(TableUplinkSessions)
if err != nil {
return err
}

err = up4.p4client.ClearTable(sessionsUplinkTableID)
if err != nil {
return err
}

sessionsDownlinkTableID, err := up4.p4RtTranslator.getTableIDByName(TableDownlinkSessions)
if err != nil {
return err
}
tables := []string{TableUplinkSessions, TableDownlinkSessions, TableUplinkTerminations, TableDownlinkTerminations, TableTunnelPeers, TableApplications}
tableIDs := make([]uint32, len(tables))

err = up4.p4client.ClearTable(sessionsDownlinkTableID)
if err != nil {
return err
}

terminationsUplinkTableID, err := up4.p4RtTranslator.getTableIDByName(TableUplinkTerminations)
if err != nil {
return err
}

err = up4.p4client.ClearTable(terminationsUplinkTableID)
if err != nil {
return err
}

terminationsDownlinkTableID, err := up4.p4RtTranslator.getTableIDByName(TableDownlinkTerminations)
if err != nil {
return err
}

err = up4.p4client.ClearTable(terminationsDownlinkTableID)
if err != nil {
return err
}

gtpTunnelPeersTableID, err := up4.p4RtTranslator.getTableIDByName(TableTunnelPeers)
if err != nil {
return err
}

err = up4.p4client.ClearTable(gtpTunnelPeersTableID)
if err != nil {
return err
}
for _, table := range tables {
tableID, err := up4.p4RtTranslator.getTableIDByName(table)
if err != nil {
return err
}

applicationsTableID, err := up4.p4RtTranslator.getTableIDByName(TableApplications)
if err != nil {
return err
tableIDs = append(tableIDs, tableID)
}

err = up4.p4client.ClearTable(applicationsTableID)
err := up4.p4client.ClearTables(tableIDs)
osinstom marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down