Kunihiro Ishiguro
Committed by Ray Milkey

ONOS-783 Update PeerConnectivityManager to handle IPv6.

Change-Id: I0c8558cec2f7fa5f772cc126c6b74e5d4531676b
...@@ -21,7 +21,9 @@ import java.util.List; ...@@ -21,7 +21,9 @@ import java.util.List;
21 21
22 import org.onlab.packet.Ethernet; 22 import org.onlab.packet.Ethernet;
23 import org.onlab.packet.IPv4; 23 import org.onlab.packet.IPv4;
24 +import org.onlab.packet.IPv6;
24 import org.onlab.packet.IpAddress; 25 import org.onlab.packet.IpAddress;
26 +import org.onlab.packet.Ip4Address;
25 import org.onlab.packet.IpPrefix; 27 import org.onlab.packet.IpPrefix;
26 import org.onosproject.core.ApplicationId; 28 import org.onosproject.core.ApplicationId;
27 import org.onosproject.net.ConnectPoint; 29 import org.onosproject.net.ConnectPoint;
...@@ -164,13 +166,28 @@ public class PeerConnectivityManager { ...@@ -164,13 +166,28 @@ public class PeerConnectivityManager {
164 IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); 166 IpAddress bgpdPeerAddress = bgpPeer.ipAddress();
165 ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint(); 167 ConnectPoint bgpdPeerConnectPoint = peerInterface.connectPoint();
166 168
169 + if (bgpdAddress.version() != bgpdPeerAddress.version()) {
170 + return intents;
171 + }
172 +
167 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 173 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
168 .build(); 174 .build();
169 175
170 TrafficSelector selector; 176 TrafficSelector selector;
171 177
178 + byte tcpProtocol;
179 + byte icmpProtocol;
180 +
181 + if (bgpdAddress.version() == Ip4Address.VERSION) {
182 + tcpProtocol = IPv4.PROTOCOL_TCP;
183 + icmpProtocol = IPv4.PROTOCOL_ICMP;
184 + } else {
185 + tcpProtocol = IPv6.PROTOCOL_TCP;
186 + icmpProtocol = IPv6.PROTOCOL_ICMP6;
187 + }
188 +
172 // Path from BGP speaker to BGP peer matching destination TCP port 179 189 // Path from BGP speaker to BGP peer matching destination TCP port 179
173 - selector = buildSelector(IPv4.PROTOCOL_TCP, 190 + selector = buildSelector(tcpProtocol,
174 bgpdAddress, 191 bgpdAddress,
175 bgpdPeerAddress, 192 bgpdPeerAddress,
176 null, 193 null,
...@@ -180,7 +197,7 @@ public class PeerConnectivityManager { ...@@ -180,7 +197,7 @@ public class PeerConnectivityManager {
180 bgpdConnectPoint, bgpdPeerConnectPoint)); 197 bgpdConnectPoint, bgpdPeerConnectPoint));
181 198
182 // Path from BGP speaker to BGP peer matching source TCP port 179 199 // Path from BGP speaker to BGP peer matching source TCP port 179
183 - selector = buildSelector(IPv4.PROTOCOL_TCP, 200 + selector = buildSelector(tcpProtocol,
184 bgpdAddress, 201 bgpdAddress,
185 bgpdPeerAddress, 202 bgpdPeerAddress,
186 (short) BgpConstants.BGP_PORT, 203 (short) BgpConstants.BGP_PORT,
...@@ -190,7 +207,7 @@ public class PeerConnectivityManager { ...@@ -190,7 +207,7 @@ public class PeerConnectivityManager {
190 bgpdConnectPoint, bgpdPeerConnectPoint)); 207 bgpdConnectPoint, bgpdPeerConnectPoint));
191 208
192 // Path from BGP peer to BGP speaker matching destination TCP port 179 209 // Path from BGP peer to BGP speaker matching destination TCP port 179
193 - selector = buildSelector(IPv4.PROTOCOL_TCP, 210 + selector = buildSelector(tcpProtocol,
194 bgpdPeerAddress, 211 bgpdPeerAddress,
195 bgpdAddress, 212 bgpdAddress,
196 null, 213 null,
...@@ -200,7 +217,7 @@ public class PeerConnectivityManager { ...@@ -200,7 +217,7 @@ public class PeerConnectivityManager {
200 bgpdPeerConnectPoint, bgpdConnectPoint)); 217 bgpdPeerConnectPoint, bgpdConnectPoint));
201 218
202 // Path from BGP peer to BGP speaker matching source TCP port 179 219 // Path from BGP peer to BGP speaker matching source TCP port 179
203 - selector = buildSelector(IPv4.PROTOCOL_TCP, 220 + selector = buildSelector(tcpProtocol,
204 bgpdPeerAddress, 221 bgpdPeerAddress,
205 bgpdAddress, 222 bgpdAddress,
206 (short) BgpConstants.BGP_PORT, 223 (short) BgpConstants.BGP_PORT,
...@@ -210,7 +227,7 @@ public class PeerConnectivityManager { ...@@ -210,7 +227,7 @@ public class PeerConnectivityManager {
210 bgpdPeerConnectPoint, bgpdConnectPoint)); 227 bgpdPeerConnectPoint, bgpdConnectPoint));
211 228
212 // ICMP path from BGP speaker to BGP peer 229 // ICMP path from BGP speaker to BGP peer
213 - selector = buildSelector(IPv4.PROTOCOL_ICMP, 230 + selector = buildSelector(icmpProtocol,
214 bgpdAddress, 231 bgpdAddress,
215 bgpdPeerAddress, 232 bgpdPeerAddress,
216 null, 233 null,
...@@ -220,7 +237,7 @@ public class PeerConnectivityManager { ...@@ -220,7 +237,7 @@ public class PeerConnectivityManager {
220 bgpdConnectPoint, bgpdPeerConnectPoint)); 237 bgpdConnectPoint, bgpdPeerConnectPoint));
221 238
222 // ICMP path from BGP peer to BGP speaker 239 // ICMP path from BGP peer to BGP speaker
223 - selector = buildSelector(IPv4.PROTOCOL_ICMP, 240 + selector = buildSelector(icmpProtocol,
224 bgpdPeerAddress, 241 bgpdPeerAddress,
225 bgpdAddress, 242 bgpdAddress,
226 null, 243 null,
...@@ -245,13 +262,25 @@ public class PeerConnectivityManager { ...@@ -245,13 +262,25 @@ public class PeerConnectivityManager {
245 private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, 262 private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp,
246 IpAddress dstIp, Short srcTcpPort, 263 IpAddress dstIp, Short srcTcpPort,
247 Short dstTcpPort) { 264 Short dstTcpPort) {
248 - TrafficSelector.Builder builder = DefaultTrafficSelector.builder() 265 + TrafficSelector.Builder builder = null;
266 +
267 + if (dstIp.version() == Ip4Address.VERSION) {
268 + builder = DefaultTrafficSelector.builder()
249 .matchEthType(Ethernet.TYPE_IPV4) 269 .matchEthType(Ethernet.TYPE_IPV4)
250 .matchIPProtocol(ipProto) 270 .matchIPProtocol(ipProto)
251 .matchIPSrc(IpPrefix.valueOf(srcIp, 271 .matchIPSrc(IpPrefix.valueOf(srcIp,
252 IpPrefix.MAX_INET_MASK_LENGTH)) 272 IpPrefix.MAX_INET_MASK_LENGTH))
253 .matchIPDst(IpPrefix.valueOf(dstIp, 273 .matchIPDst(IpPrefix.valueOf(dstIp,
254 IpPrefix.MAX_INET_MASK_LENGTH)); 274 IpPrefix.MAX_INET_MASK_LENGTH));
275 + } else {
276 + builder = DefaultTrafficSelector.builder()
277 + .matchEthType(Ethernet.TYPE_IPV6)
278 + .matchIPProtocol(ipProto)
279 + .matchIPv6Src(IpPrefix.valueOf(srcIp,
280 + IpPrefix.MAX_INET6_MASK_LENGTH))
281 + .matchIPv6Dst(IpPrefix.valueOf(dstIp,
282 + IpPrefix.MAX_INET6_MASK_LENGTH));
283 + }
255 284
256 if (srcTcpPort != null) { 285 if (srcTcpPort != null) {
257 builder.matchTcpSrc(srcTcpPort); 286 builder.matchTcpSrc(srcTcpPort);
......