Committed by
Gerrit Code Review
Work toward ONOS-1268 Expose IPv6 support at the ONOS CLI level
* Automatically assign the Ethtype based on the IP address version for the "--ipSrc" and "--ipDst" arguments * Fix a typo in the --ipSrc and --ipDst description * Check whether the --ipSrc and --ipDst address versions are same Change-Id: Iaac98987b070c5fed97a7f6eb4c544f1578effcd
Showing
1 changed file
with
41 additions
and
11 deletions
... | @@ -60,11 +60,11 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -60,11 +60,11 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
60 | required = false, multiValued = false) | 60 | required = false, multiValued = false) |
61 | private String ipProtoString = null; | 61 | private String ipProtoString = null; |
62 | 62 | ||
63 | - @Option(name = "--ipSrc", description = "Source IP Address", | 63 | + @Option(name = "--ipSrc", description = "Source IP Prefix", |
64 | required = false, multiValued = false) | 64 | required = false, multiValued = false) |
65 | private String srcIpString = null; | 65 | private String srcIpString = null; |
66 | 66 | ||
67 | - @Option(name = "--ipDst", description = "Destination IP Address", | 67 | + @Option(name = "--ipDst", description = "Destination IP Prefix", |
68 | required = false, multiValued = false) | 68 | required = false, multiValued = false) |
69 | private String dstIpString = null; | 69 | private String dstIpString = null; |
70 | 70 | ||
... | @@ -109,9 +109,47 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -109,9 +109,47 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
109 | * @return traffic selector | 109 | * @return traffic selector |
110 | */ | 110 | */ |
111 | protected TrafficSelector buildTrafficSelector() { | 111 | protected TrafficSelector buildTrafficSelector() { |
112 | + IpPrefix srcIpPrefix = null; | ||
113 | + IpPrefix dstIpPrefix = null; | ||
114 | + | ||
112 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | 115 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
113 | - short ethType = EthType.IPV4.value(); | ||
114 | 116 | ||
117 | + if (!isNullOrEmpty(srcIpString)) { | ||
118 | + srcIpPrefix = IpPrefix.valueOf(srcIpString); | ||
119 | + if (srcIpPrefix.isIp4()) { | ||
120 | + selectorBuilder.matchIPSrc(srcIpPrefix); | ||
121 | + } else { | ||
122 | + selectorBuilder.matchIPv6Src(srcIpPrefix); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | + if (!isNullOrEmpty(dstIpString)) { | ||
127 | + dstIpPrefix = IpPrefix.valueOf(dstIpString); | ||
128 | + if (dstIpPrefix.isIp4()) { | ||
129 | + selectorBuilder.matchIPDst(dstIpPrefix); | ||
130 | + } else { | ||
131 | + selectorBuilder.matchIPv6Dst(dstIpPrefix); | ||
132 | + } | ||
133 | + } | ||
134 | + | ||
135 | + if ((srcIpPrefix != null) && (dstIpPrefix != null) && | ||
136 | + (srcIpPrefix.version() != dstIpPrefix.version())) { | ||
137 | + // ERROR: IP src/dst version mismatch | ||
138 | + throw new IllegalArgumentException( | ||
139 | + "IP source and destination version mismatch"); | ||
140 | + } | ||
141 | + | ||
142 | + // | ||
143 | + // Set the default EthType based on the IP version if the matching | ||
144 | + // source or destination IP prefixes. | ||
145 | + // | ||
146 | + short ethType = EthType.IPV4.value(); | ||
147 | + if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) { | ||
148 | + ethType = EthType.IPV6.value(); | ||
149 | + } | ||
150 | + if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) { | ||
151 | + ethType = EthType.IPV6.value(); | ||
152 | + } | ||
115 | if (!isNullOrEmpty(ethTypeString)) { | 153 | if (!isNullOrEmpty(ethTypeString)) { |
116 | ethType = EthType.parseFromString(ethTypeString); | 154 | ethType = EthType.parseFromString(ethTypeString); |
117 | } | 155 | } |
... | @@ -130,14 +168,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -130,14 +168,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
130 | selectorBuilder.matchIPProtocol((byte) ipProtoShort); | 168 | selectorBuilder.matchIPProtocol((byte) ipProtoShort); |
131 | } | 169 | } |
132 | 170 | ||
133 | - if (!isNullOrEmpty(srcIpString)) { | ||
134 | - selectorBuilder.matchIPSrc(IpPrefix.valueOf(srcIpString)); | ||
135 | - } | ||
136 | - | ||
137 | - if (!isNullOrEmpty(dstIpString)) { | ||
138 | - selectorBuilder.matchIPDst(IpPrefix.valueOf(dstIpString)); | ||
139 | - } | ||
140 | - | ||
141 | if (!isNullOrEmpty(srcTcpString)) { | 171 | if (!isNullOrEmpty(srcTcpString)) { |
142 | selectorBuilder.matchTcpSrc((short) Integer.parseInt(srcTcpString)); | 172 | selectorBuilder.matchTcpSrc((short) Integer.parseInt(srcTcpString)); |
143 | } | 173 | } | ... | ... |
-
Please register or login to post a comment