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

[SDFAB-1054] Use p4 auto generated constants #501

Merged
merged 96 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
3b3b377
First commit
Feb 16, 2022
d5188dc
Add generation constants
Feb 17, 2022
8f87dbe
Refactor
Feb 17, 2022
2dbe6f4
Merge branch 'master' into generate-constants
EmanueleGallone Feb 17, 2022
524fdb9
Use p4 constants for tables and actions
Feb 17, 2022
f9b0df0
Remove unused methods
Feb 17, 2022
52ce4dd
Fix golint
Feb 17, 2022
a9c9a5e
Add go.sum
Feb 17, 2022
fd46518
Move script to scripts package
Feb 17, 2022
6c7c682
Merge branch 'generate-constants' of github.com:EmanueleGallone/upf-e…
Feb 17, 2022
73505c9
Fix merge conflicts
Feb 18, 2022
d76240c
Sync with latest changes
Feb 18, 2022
969f853
Remove old script
Feb 18, 2022
ad2fbf1
Merge branch 'master' into modify-translator
EmanueleGallone Feb 19, 2022
513b0ae
* make consts private
Feb 21, 2022
7791972
Refactor
Feb 21, 2022
3480521
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Feb 21, 2022
20d29bd
Refactor
Feb 21, 2022
bb18deb
Refactor
Feb 21, 2022
c24ac19
Refactor
Feb 21, 2022
2fe9a22
Refactor. Make list builder and map builder independent using differe…
Feb 21, 2022
e8d7cf1
Add CI verification step
Feb 21, 2022
295e7ce
Refactor workflow
Feb 22, 2022
793f29c
Make maps and slices immutable
Feb 22, 2022
28d8850
Refactor workflow
Feb 22, 2022
7fd27cf
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 22, 2022
e327b9d
Use latest version of p4constants
Feb 22, 2022
7905796
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Feb 22, 2022
09a7a2b
Refactor
Feb 22, 2022
07b8f7a
Refactor
Feb 22, 2022
fa8a58c
Fix golint
Feb 22, 2022
9bf4dfd
Merge branch 'master' into improve-gen-p4
Feb 23, 2022
bc1db35
Refactor. Fix case in autogenerated const names
Feb 23, 2022
fadbc9b
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 23, 2022
0f4509f
Merge branch 'master' into improve-gen-p4
EmanueleGallone Feb 24, 2022
c76b431
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 24, 2022
0e53516
Add interpreter to evaluate script output
Feb 24, 2022
3c9cec0
Split generator in multiple functions
Feb 24, 2022
aa536e9
Add test for constants and table generation
Feb 24, 2022
10c76c3
Refactor
Feb 24, 2022
8c2c393
Refactor
Feb 24, 2022
0dbebe1
Add generate Tables test
Feb 24, 2022
66bd763
Refactor
Feb 24, 2022
598219a
Add dummy action
Feb 24, 2022
e31c2f7
Refactor. One big table driven test
Feb 24, 2022
16c4da6
Refactor
Feb 24, 2022
bfc591e
Merge branch 'master' into modify-translator
EmanueleGallone Feb 24, 2022
d25c1aa
Add direct and indirect counters
Feb 25, 2022
6433d1f
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 25, 2022
f14adcd
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Feb 25, 2022
dc262e4
Add scripts folder when running tests and sync with latest changes
Feb 25, 2022
837258c
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Feb 25, 2022
f52ff3a
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 25, 2022
f135349
Restore tableID slice when clearing all tables
Feb 25, 2022
5585ba5
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Feb 25, 2022
542d321
Refactor clearAllTables in clearTables
Feb 25, 2022
fead38f
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Feb 25, 2022
c6d5bf2
Merge branch 'master' into improve-gen-p4
EmanueleGallone Feb 25, 2022
393ba4a
Cleanup
pudelkoM Feb 25, 2022
4fd1181
Merge branch 'improve-gen-p4' of https://github.com/EmanueleGallone/u…
pudelkoM Feb 25, 2022
92cdb77
Merge branch 'master' into improve-gen-p4
Feb 26, 2022
2da4ab3
Add copyright header
Feb 28, 2022
332f252
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Feb 28, 2022
3b2650c
Merge branch 'improve-gen-p4' of github.com:EmanueleGallone/upf-epc i…
Feb 28, 2022
239baef
Fix golint
Feb 28, 2022
788cdbd
Merge branch 'master' into modify-translator
pudelkoM Feb 28, 2022
119d404
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 1, 2022
a3f57a6
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 1, 2022
f97aed6
Merge branch 'master' into modify-translator
Mar 1, 2022
7b646bc
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 1, 2022
00030fe
Fix incorrect actions
Mar 1, 2022
aae604a
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 1, 2022
8062ed7
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 1, 2022
53481e2
Merge branch 'master' into modify-translator
pudelkoM Mar 1, 2022
b18924b
Merge branch 'master' into modify-translator
EmanueleGallone Mar 2, 2022
d39316e
Add applications table when clearing tables
Mar 2, 2022
0750ab2
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 2, 2022
aa150b8
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 2, 2022
eb346e8
Merge branch 'master' into modify-translator
EmanueleGallone Mar 2, 2022
7df6ee7
Don't set UP4 forwarding pipeline config
Mar 7, 2022
2ea3a8a
Fix golint
Mar 7, 2022
7409a22
Clean test code and add comment
Mar 7, 2022
5fc015d
Update logger
Mar 7, 2022
8782018
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 9, 2022
f5d8527
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 9, 2022
71c75c7
Add getMeterByID method
Mar 9, 2022
853d449
Merge branch 'dont-set-pipe-cfg' of github.com:omec-project/upf-epc i…
Mar 9, 2022
96e9878
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 10, 2022
fb93525
Add getMeterSizeByID method
Mar 11, 2022
2b84992
Merge branch 'master' of github.com:omec-project/upf-epc into modify-…
Mar 11, 2022
34e245c
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 11, 2022
91d8f73
Merge branch 'master' into modify-translator
Mar 11, 2022
2ea39a1
Sync with latest changes
Mar 11, 2022
0393ac0
Merge branch 'modify-translator' of github.com:EmanueleGallone/upf-ep…
Mar 11, 2022
d4eb1ab
Fix counter panic in integration tests
Mar 11, 2022
9ec6143
Address review comments
Mar 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
140 changes: 25 additions & 115 deletions pfcpiface/p4rt_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/bits"
"net"

"github.com/omec-project/upf-epc/internal/p4constants"
p4ConfigV1 "github.com/p4lang/p4runtime/go/p4/config/v1"
p4 "github.com/p4lang/p4runtime/go/p4/v1"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -41,27 +42,6 @@ const (
FieldSessionMeterIndex = "session_meter_idx"
FieldAppMeterIndex = "app_meter_idx"

TableInterfaces = "PreQosPipe.interfaces"
TableTunnelPeers = "PreQosPipe.tunnel_peers"
TableDownlinkTerminations = "PreQosPipe.terminations_downlink"
TableUplinkTerminations = "PreQosPipe.terminations_uplink"
TableDownlinkSessions = "PreQosPipe.sessions_downlink"
TableUplinkSessions = "PreQosPipe.sessions_uplink"
TableApplications = "PreQosPipe.applications"

ActSetSourceIface = "PreQosPipe.set_source_iface"
ActSetUplinkSession = "PreQosPipe.set_session_uplink"
ActSetDownlinkSession = "PreQosPipe.set_session_downlink"
ActSetDownlinkSessionBuff = "PreQosPipe.set_session_downlink_buff"
ActUplinkTermDrop = "PreQosPipe.uplink_term_drop"
ActUplinkTermFwd = "PreQosPipe.uplink_term_fwd"
ActUplinkTermFwdNoTC = "PreQosPipe.uplink_term_fwd_no_tc"
ActDownlinkTermDrop = "PreQosPipe.downlink_term_drop"
ActDownlinkTermFwd = "PreQosPipe.downlink_term_fwd"
ActDownlinkTermFwdNoTC = "PreQosPipe.downlink_term_fwd_no_tc"
ActLoadTunnelParams = "PreQosPipe.load_tunnel_param"
ActSetAppID = "PreQosPipe.set_app_id"

DefaultPriority = 0
DefaultApplicationID = 0
// NoTC assuming bit<2> type of TC in UP4,
Expand Down Expand Up @@ -132,36 +112,6 @@ func convertValueToBinary(value interface{}) ([]byte, error) {
}
}

func (t *P4rtTranslator) tableID(name string) uint32 {
for _, table := range t.p4Info.Tables {
if table.Preamble.Name == name {
return table.Preamble.Id
}
}

return invalidID
}

func (t *P4rtTranslator) meterID(name string) uint32 {
for _, meter := range t.p4Info.Meters {
if meter.Preamble.Name == name {
return meter.Preamble.Id
}
}

return invalidID
}

func (t *P4rtTranslator) actionID(name string) uint32 {
for _, action := range t.p4Info.Actions {
if action.Preamble.Name == name {
return action.Preamble.Id
}
}

return invalidID
}

func (t *P4rtTranslator) getActionByID(actionID uint32) (*p4ConfigV1.Action, error) {
for _, action := range t.p4Info.Actions {
if action.Preamble.Id == actionID {
Expand All @@ -182,36 +132,6 @@ func (t *P4rtTranslator) getTableByID(tableID uint32) (*p4ConfigV1.Table, error)
return nil, ErrNotFoundWithParam("table", "ID", tableID)
}

func (t *P4rtTranslator) getTableIDByName(name string) (uint32, error) {
for _, table := range t.p4Info.Tables {
if table.Preamble.Name == name {
return table.Preamble.Id, nil
}
}

return 0, ErrNotFoundWithParam("table", "name", name)
}

func (t *P4rtTranslator) getCounterByName(name string) (*p4ConfigV1.Counter, error) {
for _, ctr := range t.p4Info.Counters {
if ctr.Preamble.Name == name {
return ctr, nil
}
}

return nil, ErrNotFoundWithParam("counter", "name", name)
}

func (t *P4rtTranslator) getMeterByName(name string) (*p4ConfigV1.Meter, error) {
for _, mtr := range t.p4Info.Meters {
if mtr.Preamble.Name == name {
return mtr, nil
}
}

return nil, ErrNotFoundWithParam("meter", "name", name)
}

//nolint:unused
func (t *P4rtTranslator) getMatchFieldIDByName(table *p4ConfigV1.Table, fieldName string) uint32 {
for _, field := range table.MatchFields {
Expand Down Expand Up @@ -494,19 +414,15 @@ func (t *P4rtTranslator) getLPMMatchFieldValue(tableEntry *p4.TableEntry, name s
}

func (t *P4rtTranslator) BuildInterfaceTableEntryNoAction() *p4.TableEntry {
tableID := t.tableID(TableInterfaces)

entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeInterfaces,
Priority: DefaultPriority,
}

return entry
}

func (t *P4rtTranslator) BuildInterfaceTableEntry(ipNet *net.IPNet, sliceID uint8, isCore bool) (*p4.TableEntry, error) {
tableID := t.tableID(TableInterfaces)

srcIface := access
direction := DirectionUplink

Expand All @@ -516,7 +432,7 @@ func (t *P4rtTranslator) BuildInterfaceTableEntry(ipNet *net.IPNet, sliceID uint
}

entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeInterfaces,
Priority: DefaultPriority,
}

Expand All @@ -526,7 +442,7 @@ func (t *P4rtTranslator) BuildInterfaceTableEntry(ipNet *net.IPNet, sliceID uint
}

action := &p4.Action{
ActionId: t.actionID(ActSetSourceIface),
ActionId: p4constants.ActionPreQosPipeSetSourceIface,
}

if err := t.withActionParam(action, FieldSrcIface, srcIface); err != nil {
Expand Down Expand Up @@ -554,9 +470,8 @@ func (t *P4rtTranslator) BuildApplicationsTableEntry(pdr pdr, sliceID uint8, int
})
applicationsBuilderLog.Trace("Building P4rt table entry for applications table")

tableID := t.tableID(TableApplications)
entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeApplications,
// priority for UP4 cannot be greater than 65535
Priority: int32(math.MaxUint16 - pdr.precedence),
}
Expand Down Expand Up @@ -600,7 +515,7 @@ func (t *P4rtTranslator) BuildApplicationsTableEntry(pdr pdr, sliceID uint8, int
}

action := &p4.Action{
ActionId: t.actionID(ActSetAppID),
ActionId: p4constants.ActionPreQosPipeSetAppId,
}

if err := t.withActionParam(action, FieldApplicationID, internalAppID); err != nil {
Expand All @@ -624,10 +539,8 @@ func (t *P4rtTranslator) buildUplinkSessionsEntry(pdr pdr, sessMeterIdx uint32)
})
uplinkBuilderLog.Trace("Building P4rt table entry for sessions_uplink table")

tableID := t.tableID(TableUplinkSessions)

entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeSessionsUplink,
Priority: DefaultPriority,
}

Expand All @@ -640,7 +553,7 @@ func (t *P4rtTranslator) buildUplinkSessionsEntry(pdr pdr, sessMeterIdx uint32)
}

action := &p4.Action{
ActionId: t.actionID(ActSetUplinkSession),
ActionId: p4constants.ActionPreQosPipeSetSessionUplink,
}

if err := t.withActionParam(action, FieldSessionMeterIndex, sessMeterIdx); err != nil {
Expand All @@ -665,9 +578,8 @@ func (t *P4rtTranslator) buildDownlinkSessionsEntry(pdr pdr, sessMeterIdx uint32
})
builderLog.Trace("Building P4rt table entry for sessions_downlink table")

tableID := t.tableID(TableDownlinkSessions)
entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeSessionsDownlink,
Priority: DefaultPriority,
}

Expand All @@ -678,11 +590,11 @@ func (t *P4rtTranslator) buildDownlinkSessionsEntry(pdr pdr, sessMeterIdx uint32
var action *p4.Action
if needsBuffering {
action = &p4.Action{
ActionId: t.actionID(ActSetDownlinkSessionBuff),
ActionId: p4constants.ActionPreQosPipeSetSessionDownlinkBuff,
}
} else {
action = &p4.Action{
ActionId: t.actionID(ActSetDownlinkSession),
ActionId: p4constants.ActionPreQosPipeSetSessionDownlink,
}
if err := t.withActionParam(action, FieldTunnelPeerID, tunnelPeerID); err != nil {
return nil, err
Expand Down Expand Up @@ -721,9 +633,8 @@ func (t *P4rtTranslator) buildUplinkTerminationsEntry(pdr pdr, appMeterIdx uint3
})
builderLog.Debug("Building P4rt table entry for UP4 terminations_uplink table")

tableID := t.tableID(TableUplinkTerminations)
entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeTerminationsUplink,
Priority: DefaultPriority,
}

Expand All @@ -738,11 +649,11 @@ func (t *P4rtTranslator) buildUplinkTerminationsEntry(pdr pdr, appMeterIdx uint3
var action *p4.Action
if shouldDrop {
action = &p4.Action{
ActionId: t.actionID(ActUplinkTermDrop),
ActionId: p4constants.ActionPreQosPipeUplinkTermDrop,
}
} else if !shouldDrop && tc != NoTC {
action = &p4.Action{
ActionId: t.actionID(ActUplinkTermFwd),
ActionId: p4constants.ActionPreQosPipeUplinkTermFwd,
}

if err := t.withActionParam(action, FieldTrafficClass, tc); err != nil {
Expand All @@ -753,7 +664,7 @@ func (t *P4rtTranslator) buildUplinkTerminationsEntry(pdr pdr, appMeterIdx uint3
}
} else {
action = &p4.Action{
ActionId: t.actionID(ActUplinkTermFwdNoTC),
ActionId: p4constants.ActionPreQosPipeUplinkTermFwdNoTc,
}
if err := t.withActionParam(action, FieldAppMeterIndex, appMeterIdx); err != nil {
return nil, err
Expand Down Expand Up @@ -783,9 +694,8 @@ func (t *P4rtTranslator) buildDownlinkTerminationsEntry(pdr pdr, appMeterIdx uin
})
builderLog.Debug("Building P4rt table entry for UP4 terminations_downlink table")

tableID := t.tableID(TableDownlinkTerminations)
entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeTerminationsDownlink,
Priority: DefaultPriority,
}

Expand All @@ -800,11 +710,11 @@ func (t *P4rtTranslator) buildDownlinkTerminationsEntry(pdr pdr, appMeterIdx uin
var action *p4.Action
if relatedFAR.Drops() {
action = &p4.Action{
ActionId: t.actionID(ActDownlinkTermDrop),
ActionId: p4constants.ActionPreQosPipeDownlinkTermDrop,
}
} else if !relatedFAR.Drops() && tc != NoTC {
action = &p4.Action{
ActionId: t.actionID(ActDownlinkTermFwd),
ActionId: p4constants.ActionPreQosPipeDownlinkTermFwd,
}

if err := t.withActionParam(action, FieldTEID, relatedFAR.tunnelTEID); err != nil {
Expand All @@ -824,7 +734,7 @@ func (t *P4rtTranslator) buildDownlinkTerminationsEntry(pdr pdr, appMeterIdx uin
}
} else {
action = &p4.Action{
ActionId: t.actionID(ActDownlinkTermFwdNoTC),
ActionId: p4constants.ActionPreQosPipeDownlinkTermFwdNoTc,
}

if err := t.withActionParam(action, FieldTEID, relatedFAR.tunnelTEID); err != nil {
Expand Down Expand Up @@ -871,14 +781,13 @@ func (t *P4rtTranslator) BuildGTPTunnelPeerTableEntry(tunnelPeerID uint8, tunnel
})
builderLog.Trace("Building P4rt table entry for GTP Tunnel Peers table")

tableID := t.tableID(TableTunnelPeers)
entry := &p4.TableEntry{
TableId: tableID,
TableId: p4constants.TablePreQosPipeTunnelPeers,
Priority: DefaultPriority,
Action: &p4.TableAction{
Type: &p4.TableAction_Action{
Action: &p4.Action{
ActionId: t.actionID(ActLoadTunnelParams),
ActionId: p4constants.ActionPreQosPipeLoadTunnelParam,
},
},
},
Expand All @@ -905,14 +814,15 @@ func (t *P4rtTranslator) BuildGTPTunnelPeerTableEntry(tunnelPeerID uint8, tunnel
return entry, nil
}

func (t *P4rtTranslator) BuildMeterEntry(meter string, cellID uint32, config *p4.MeterConfig) *p4.MeterEntry {
func (t *P4rtTranslator) BuildMeterEntry(meterID uint32, cellID uint32, config *p4.MeterConfig) *p4.MeterEntry {
meterName := p4constants.GetMeterIDToNameMap()[meterID]

builderLog := log.WithFields(log.Fields{
"Meter": meter,
"Meter": meterName,
"Cell ID": cellID,
})
builderLog.Trace("Building Meter entry")

meterID := t.meterID(meter)
entry := &p4.MeterEntry{
MeterId: meterID,
Index: &p4.Index{Index: int64(cellID)},
Expand Down