Skip to content

Commit

Permalink
Move ACL entry transport configuration from `acl-entry/<ipv4/ipv6>/tr…
Browse files Browse the repository at this point in the history
…ansport` to `acl-entry/transport`, to match the current canonical OpenConfig ACL entry schema.

PiperOrigin-RevId: 659975442
  • Loading branch information
Capirca Team committed Aug 6, 2024
1 parent 4cc00b3 commit 12a9c92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
13 changes: 9 additions & 4 deletions capirca/lib/openconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,22 @@ def ConvertToDict(self):
# 'any' starts and ends with zero.
if not start == end == 0:
if start == end:
ace_dict[family]['transport']['config']['source-port'] = int(start)
ace_dict['transport']['config']['source-port'] = int(start)
else:
ace_dict[family]['transport']['config']['source-port'] = '%d..%d' % (start, end)
ace_dict['transport']['config']['source-port'] = '%d..%d' % (
start,
end,
)

# Destination Port
for start, end in dports:
if not start == end == 0:
if start == end:
ace_dict[family]['transport']['config']['destination-port'] = int(start)
ace_dict['transport']['config']['destination-port'] = int(start)
else:
ace_dict[family]['transport']['config']['destination-port'] = '%d..%d' % (start, end)
ace_dict['transport']['config']['destination-port'] = (
'%d..%d' % (start, end)
)

# Protocol
for proto in protos:
Expand Down
40 changes: 22 additions & 18 deletions tests/lib/openconfig_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@
"ipv4": {
"config": {
"protocol": 6
}
},
"transport": {
"config": {
"source-port": 53}
"source-port": 53
}
}
}
Expand All @@ -252,10 +253,11 @@
"ipv4": {
"config": {
"protocol": 6
}
},
"transport": {
"config": {
"destination-port": 53}
"destination-port": 53
}
}
}
Expand All @@ -273,10 +275,11 @@
"ipv4": {
"config": {
"protocol": 17
}
},
"transport": {
"config": {
"destination-port": 53}
"destination-port": 53
}
}
},
Expand All @@ -289,12 +292,13 @@
"ipv4": {
"config": {
"protocol": 6
},
"transport": {
"config": {
"destination-port": 53}
}
}
},
"transport": {
"config": {
"destination-port": 53
}
}
}
]
"""
Expand All @@ -312,11 +316,11 @@
"destination-address": "10.2.3.4/32",
"protocol": 17,
"source-address": "10.2.3.4/32"
},
"transport": {
"config": {
"destination-port": 53
}
}
},
"transport": {
"config": {
"destination-port": 53
}
}
},
Expand All @@ -331,11 +335,11 @@
"destination-address": "10.2.3.4/32",
"protocol": 6,
"source-address": "10.2.3.4/32"
},
"transport": {
"config": {
"destination-port": 53
}
}
},
"transport": {
"config": {
"destination-port": 53
}
}
}
Expand Down

0 comments on commit 12a9c92

Please sign in to comment.