Skip to content

Commit

Permalink
Set attribute ip_protocol to IPV4 or IPV6
Browse files Browse the repository at this point in the history
  • Loading branch information
hknutzen committed Dec 1, 2022
1 parent 1ebd1d5 commit c8bf1d8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go/pkg/pass2/nsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ func printNSXRules(fd *os.File, rData *routerData) {
isDeny = rule.deny
}
rName := fmt.Sprintf("r%d", ruleNum)
ipV46 := "IPV4"
ruleNum++
// Prevent name clash between IPv4 and IPv6 rules
if rData.ipv6 {
// Prevent name clash between IPv4 and IPv6 rules
rName = "v6" + rName
ipV46 = "IPV6"
}
nsxRule := jsonMap{
"resource_type": "Rule",
Expand All @@ -145,6 +147,7 @@ func printNSXRules(fd *os.File, rData *routerData) {
"source_groups": getAddress(rule.src),
"destination_groups": getAddress(rule.dst),
"services": single(getService(rule)),
"ip_protocol": ipV46,
"scope": single(scope),
"direction": direction,
"sequence_number": seqNum,
Expand Down
2 changes: 2 additions & 0 deletions go/testdata/ipv6/convert.pl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ sub adjust_testfile {

# Convert ICMPv4 to ICMPv6 in JSON output for NSX.
$line =~ s/"ICMPv4"/"ICMPv6"/;
# Convert value of attribute 'ip_protocol' for NSX.
$line =~ s/IPV4/IPV6/;
# Convert name of ICMP protocol for NSX.
$line =~ s/([\/"]Netspoc-icmp)/$1v6/;

Expand Down
22 changes: 22 additions & 0 deletions go/testdata/ipv6/nsx_ipv6.t
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r1",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -319,6 +320,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r2",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -341,6 +343,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r3",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -363,6 +366,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "v6r4",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -385,6 +389,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "v6r5",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -413,6 +418,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r1",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -435,6 +441,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r2",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -457,6 +464,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r3",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -479,6 +487,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r4",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -501,6 +510,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r5",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -523,6 +533,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "v6r6",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -545,6 +556,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "v6r7",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -736,6 +748,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r1",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -758,6 +771,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r2",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -780,6 +794,7 @@ service:s1 = {
],
"direction": "IN",
"id": "v6r3",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -850,6 +865,7 @@ router:r1@v1 = {
],
"direction": "OUT",
"id": "v6r1",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -872,6 +888,7 @@ router:r1@v1 = {
],
"direction": "IN",
"id": "v6r2",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -931,6 +948,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r1",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -953,6 +971,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r2",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -975,6 +994,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r3",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -997,6 +1017,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "v6r4",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand All @@ -1019,6 +1040,7 @@ service:s1 = {
],
"direction": "IN",
"id": "v6r5",
"ip_protocol": "IPV6",
"profiles": [
"ANY"
],
Expand Down
22 changes: 22 additions & 0 deletions go/testdata/nsx.t
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r1",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -309,6 +310,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r2",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -331,6 +333,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r3",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -353,6 +356,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "r4",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -375,6 +379,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "r5",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -403,6 +408,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r1",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -425,6 +431,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r2",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -447,6 +454,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r3",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -469,6 +477,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r4",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -491,6 +500,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r5",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -513,6 +523,7 @@ Generated by Netspoc, version devel
],
"direction": "OUT",
"id": "r6",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -535,6 +546,7 @@ Generated by Netspoc, version devel
],
"direction": "IN",
"id": "r7",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -725,6 +737,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r1",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -747,6 +760,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r2",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -769,6 +783,7 @@ service:s1 = {
],
"direction": "IN",
"id": "r3",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -838,6 +853,7 @@ router:r1@v1 = {
],
"direction": "OUT",
"id": "r1",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -860,6 +876,7 @@ router:r1@v1 = {
],
"direction": "IN",
"id": "r2",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand Down Expand Up @@ -918,6 +935,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r1",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -940,6 +958,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r2",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -962,6 +981,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r3",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -984,6 +1004,7 @@ service:s1 = {
],
"direction": "OUT",
"id": "r4",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand All @@ -1006,6 +1027,7 @@ service:s1 = {
],
"direction": "IN",
"id": "r5",
"ip_protocol": "IPV4",
"profiles": [
"ANY"
],
Expand Down

0 comments on commit c8bf1d8

Please sign in to comment.