Jonathan Hart
Committed by Gerrit Code Review

Send PIM Join/Prune messages based on events from the McastService.

Also change Interface to return a list of addresses rather than a set
to allow applications to rely on the order of configuration

Change-Id: Ie7f62fee507639325ee0a77b8db4088dae34597e
...@@ -47,6 +47,13 @@ ...@@ -47,6 +47,13 @@
47 47
48 <dependency> 48 <dependency>
49 <groupId>org.onosproject</groupId> 49 <groupId>org.onosproject</groupId>
50 + <artifactId>onos-app-routing-api</artifactId>
51 + <version>${project.version}</version>
52 + </dependency>
53 +
54 +
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
50 <artifactId>onos-cli</artifactId> 57 <artifactId>onos-cli</artifactId>
51 <version>${project.version}</version> 58 <version>${project.version}</version>
52 </dependency> 59 </dependency>
......
...@@ -31,6 +31,7 @@ import java.util.Set; ...@@ -31,6 +31,7 @@ import java.util.Set;
31 public class PimInterfacesListCommand extends AbstractShellCommand { 31 public class PimInterfacesListCommand extends AbstractShellCommand {
32 32
33 private static final String FORMAT = "interfaceName=%s, holdTime=%s, priority=%s, genId=%s"; 33 private static final String FORMAT = "interfaceName=%s, holdTime=%s, priority=%s, genId=%s";
34 + private static final String ROUTE_FORMAT = " %s";
34 35
35 @Override 36 @Override
36 protected void execute() { 37 protected void execute() {
...@@ -38,10 +39,13 @@ public class PimInterfacesListCommand extends AbstractShellCommand { ...@@ -38,10 +39,13 @@ public class PimInterfacesListCommand extends AbstractShellCommand {
38 39
39 Set<PIMInterface> interfaces = interfaceService.getPimInterfaces(); 40 Set<PIMInterface> interfaces = interfaceService.getPimInterfaces();
40 41
41 - interfaces.forEach( 42 + interfaces.forEach(pimIntf -> {
42 - pimIntf -> print(FORMAT, pimIntf.getInterface().name(), 43 + print(FORMAT, pimIntf.getInterface().name(),
43 - pimIntf.getHoldtime(), pimIntf.getPriority(), 44 + pimIntf.getHoldtime(), pimIntf.getPriority(),
44 - pimIntf.getGenerationId())); 45 + pimIntf.getGenerationId());
46 +
47 + pimIntf.getRoutes().forEach(route -> print(ROUTE_FORMAT, route));
48 + });
45 } 49 }
46 50
47 } 51 }
......
...@@ -22,6 +22,7 @@ import org.onlab.packet.IpAddress; ...@@ -22,6 +22,7 @@ import org.onlab.packet.IpAddress;
22 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
23 import org.onlab.packet.MacAddress; 23 import org.onlab.packet.MacAddress;
24 import org.onlab.packet.PIM; 24 import org.onlab.packet.PIM;
25 +import org.onlab.packet.pim.PIMAddrUnicast;
25 import org.onlab.packet.pim.PIMHello; 26 import org.onlab.packet.pim.PIMHello;
26 import org.onlab.packet.pim.PIMHelloOption; 27 import org.onlab.packet.pim.PIMHelloOption;
27 import org.onlab.packet.pim.PIMJoinPrune; 28 import org.onlab.packet.pim.PIMJoinPrune;
...@@ -30,6 +31,7 @@ import org.onosproject.incubator.net.intf.Interface; ...@@ -30,6 +31,7 @@ import org.onosproject.incubator.net.intf.Interface;
30 import org.onosproject.net.flow.DefaultTrafficTreatment; 31 import org.onosproject.net.flow.DefaultTrafficTreatment;
31 import org.onosproject.net.flow.TrafficTreatment; 32 import org.onosproject.net.flow.TrafficTreatment;
32 import org.onosproject.net.host.InterfaceIpAddress; 33 import org.onosproject.net.host.InterfaceIpAddress;
34 +import org.onosproject.net.mcast.McastRoute;
33 import org.onosproject.net.packet.DefaultOutboundPacket; 35 import org.onosproject.net.packet.DefaultOutboundPacket;
34 import org.onosproject.net.packet.PacketService; 36 import org.onosproject.net.packet.PacketService;
35 import org.slf4j.Logger; 37 import org.slf4j.Logger;
...@@ -37,9 +39,11 @@ import org.slf4j.Logger; ...@@ -37,9 +39,11 @@ import org.slf4j.Logger;
37 import java.nio.ByteBuffer; 39 import java.nio.ByteBuffer;
38 import java.util.Collection; 40 import java.util.Collection;
39 import java.util.HashMap; 41 import java.util.HashMap;
42 +import java.util.List;
40 import java.util.Map; 43 import java.util.Map;
41 import java.util.Random; 44 import java.util.Random;
42 import java.util.Set; 45 import java.util.Set;
46 +import java.util.concurrent.ConcurrentHashMap;
43 import java.util.concurrent.TimeUnit; 47 import java.util.concurrent.TimeUnit;
44 import java.util.stream.Collectors; 48 import java.util.stream.Collectors;
45 49
...@@ -55,6 +59,9 @@ public final class PIMInterface { ...@@ -55,6 +59,9 @@ public final class PIMInterface {
55 59
56 private final Logger log = getLogger(getClass()); 60 private final Logger log = getLogger(getClass());
57 61
62 + private static final int JOIN_PERIOD = 60;
63 + private static final double HOLD_TIME_MULTIPLIER = 3.5;
64 +
58 private final PacketService packetService; 65 private final PacketService packetService;
59 66
60 private Interface onosInterface; 67 private Interface onosInterface;
...@@ -82,6 +89,8 @@ public final class PIMInterface { ...@@ -82,6 +89,8 @@ public final class PIMInterface {
82 // A map of all our PIM neighbors keyed on our neighbors IP address 89 // A map of all our PIM neighbors keyed on our neighbors IP address
83 private Map<IpAddress, PIMNeighbor> pimNeighbors = new HashMap<>(); 90 private Map<IpAddress, PIMNeighbor> pimNeighbors = new HashMap<>();
84 91
92 + private Map<McastRoute, RouteData> routes = new ConcurrentHashMap<>();
93 +
85 /** 94 /**
86 * Create a PIMInterface from an ONOS Interface. 95 * Create a PIMInterface from an ONOS Interface.
87 * 96 *
...@@ -151,8 +160,8 @@ public final class PIMInterface { ...@@ -151,8 +160,8 @@ public final class PIMInterface {
151 * 160 *
152 * @return a set of Ip Addresses on this interface 161 * @return a set of Ip Addresses on this interface
153 */ 162 */
154 - public Set<InterfaceIpAddress> getIpAddresses() { 163 + public List<InterfaceIpAddress> getIpAddresses() {
155 - return onosInterface.ipAddresses(); 164 + return onosInterface.ipAddressesList();
156 } 165 }
157 166
158 /** 167 /**
...@@ -161,12 +170,12 @@ public final class PIMInterface { ...@@ -161,12 +170,12 @@ public final class PIMInterface {
161 * @return the choosen IP address or null if none 170 * @return the choosen IP address or null if none
162 */ 171 */
163 public IpAddress getIpAddress() { 172 public IpAddress getIpAddress() {
164 - if (onosInterface.ipAddresses().isEmpty()) { 173 + if (onosInterface.ipAddressesList().isEmpty()) {
165 return null; 174 return null;
166 } 175 }
167 176
168 IpAddress ipaddr = null; 177 IpAddress ipaddr = null;
169 - for (InterfaceIpAddress ifipaddr : onosInterface.ipAddresses()) { 178 + for (InterfaceIpAddress ifipaddr : onosInterface.ipAddressesList()) {
170 ipaddr = ifipaddr.ipAddress(); 179 ipaddr = ifipaddr.ipAddress();
171 break; 180 break;
172 } 181 }
...@@ -218,6 +227,10 @@ public final class PIMInterface { ...@@ -218,6 +227,10 @@ public final class PIMInterface {
218 return pimNeighbors.values(); 227 return pimNeighbors.values();
219 } 228 }
220 229
230 + public Collection<McastRoute> getRoutes() {
231 + return routes.keySet();
232 + }
233 +
221 /** 234 /**
222 * Checks whether any of our neighbors have expired, and cleans up their 235 * Checks whether any of our neighbors have expired, and cleans up their
223 * state if they have. 236 * state if they have.
...@@ -402,6 +415,100 @@ public final class PIMInterface { ...@@ -402,6 +415,100 @@ public final class PIMInterface {
402 415
403 } 416 }
404 417
418 + public void addRoute(McastRoute route, IpAddress nextHop, MacAddress nextHopMac) {
419 + RouteData data = new RouteData(nextHop, nextHopMac);
420 + routes.put(route, data);
421 +
422 + sendJoinPrune(route, data, true);
423 + }
424 +
425 + public void removeRoute(McastRoute route) {
426 + RouteData data = routes.remove(route);
427 +
428 + if (data != null) {
429 + sendJoinPrune(route, data, false);
430 + }
431 + }
432 +
433 + public void sendJoins() {
434 + routes.entrySet().forEach(entry -> {
435 + if (entry.getValue().timestamp + TimeUnit.SECONDS.toMillis(JOIN_PERIOD) >
436 + System.currentTimeMillis()) {
437 + return;
438 + }
439 +
440 + sendJoinPrune(entry.getKey(), entry.getValue(), true);
441 + });
442 + }
443 +
444 + private void sendJoinPrune(McastRoute route, RouteData data, boolean join) {
445 + PIMJoinPrune jp = new PIMJoinPrune();
446 +
447 + jp.addJoinPrune(route.source().toIpPrefix(), route.group().toIpPrefix(), join);
448 + jp.setHoldTime(join ? (short) Math.floor(JOIN_PERIOD * HOLD_TIME_MULTIPLIER) : 0);
449 + jp.setUpstreamAddr(new PIMAddrUnicast(data.ipAddress.toString()));
450 +
451 + PIM pim = new PIM();
452 + pim.setPIMType(PIM.TYPE_JOIN_PRUNE_REQUEST);
453 + pim.setPayload(jp);
454 +
455 + IPv4 ipv4 = new IPv4();
456 + ipv4.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt());
457 + ipv4.setSourceAddress(getIpAddress().getIp4Address().toInt());
458 + ipv4.setProtocol(IPv4.PROTOCOL_PIM);
459 + ipv4.setTtl((byte) 1);
460 + ipv4.setDiffServ((byte) 0xc0);
461 + ipv4.setPayload(pim);
462 +
463 + Ethernet eth = new Ethernet();
464 + eth.setSourceMACAddress(onosInterface.mac());
465 + eth.setDestinationMACAddress(MacAddress.valueOf("01:00:5E:00:00:0d"));
466 + eth.setEtherType(Ethernet.TYPE_IPV4);
467 + eth.setPayload(ipv4);
468 +
469 + TrafficTreatment treatment = DefaultTrafficTreatment.builder()
470 + .setOutput(onosInterface.connectPoint().port())
471 + .build();
472 +
473 + packetService.emit(new DefaultOutboundPacket(onosInterface.connectPoint().deviceId(),
474 + treatment, ByteBuffer.wrap(eth.serialize())));
475 +
476 + data.timestamp = System.currentTimeMillis();
477 + }
478 +
479 + /*private void sendPrune(McastRoute route, RouteData data) {
480 + PIMJoinPrune jp = new PIMJoinPrune();
481 +
482 + jp.addJoinPrune(route.source().toIpPrefix(), route.group().toIpPrefix(), false);
483 + jp.setHoldTime((short) 0);
484 + jp.setUpstreamAddr(new PIMAddrUnicast(data.ipAddress.toString()));
485 +
486 + PIM pim = new PIM();
487 + pim.setPIMType(PIM.TYPE_JOIN_PRUNE_REQUEST);
488 + pim.setPayload(jp);
489 +
490 + IPv4 ipv4 = new IPv4();
491 + ipv4.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt());
492 + ipv4.setSourceAddress(getIpAddress().getIp4Address().toInt());
493 + ipv4.setProtocol(IPv4.PROTOCOL_PIM);
494 + ipv4.setTtl((byte) 1);
495 + ipv4.setDiffServ((byte) 0xc0);
496 + ipv4.setPayload(pim);
497 +
498 + Ethernet eth = new Ethernet();
499 + eth.setSourceMACAddress(onosInterface.mac());
500 + eth.setDestinationMACAddress(MacAddress.valueOf("01:00:5E:00:00:0d"));
501 + eth.setEtherType(Ethernet.TYPE_IPV4);
502 + eth.setPayload(ipv4);
503 +
504 + TrafficTreatment treatment = DefaultTrafficTreatment.builder()
505 + .setOutput(onosInterface.connectPoint().port())
506 + .build();
507 +
508 + packetService.emit(new DefaultOutboundPacket(onosInterface.connectPoint().deviceId(),
509 + treatment, ByteBuffer.wrap(eth.serialize())));
510 + }*/
511 +
405 /** 512 /**
406 * Returns a builder for a PIM interface. 513 * Returns a builder for a PIM interface.
407 * 514 *
...@@ -514,4 +621,16 @@ public final class PIMInterface { ...@@ -514,4 +621,16 @@ public final class PIMInterface {
514 } 621 }
515 622
516 } 623 }
624 +
625 + private static class RouteData {
626 + public final IpAddress ipAddress;
627 + public final MacAddress macAddress;
628 + public long timestamp;
629 +
630 + public RouteData(IpAddress ip, MacAddress mac) {
631 + this.ipAddress = ip;
632 + this.macAddress = mac;
633 + timestamp = System.currentTimeMillis();
634 + }
635 + }
517 } 636 }
......
...@@ -29,12 +29,22 @@ import org.onosproject.incubator.net.intf.InterfaceEvent; ...@@ -29,12 +29,22 @@ import org.onosproject.incubator.net.intf.InterfaceEvent;
29 import org.onosproject.incubator.net.intf.InterfaceListener; 29 import org.onosproject.incubator.net.intf.InterfaceListener;
30 import org.onosproject.incubator.net.intf.InterfaceService; 30 import org.onosproject.incubator.net.intf.InterfaceService;
31 import org.onosproject.net.ConnectPoint; 31 import org.onosproject.net.ConnectPoint;
32 +
33 +import org.onosproject.net.Host;
34 +
32 import org.onosproject.net.config.ConfigFactory; 35 import org.onosproject.net.config.ConfigFactory;
33 import org.onosproject.net.config.NetworkConfigEvent; 36 import org.onosproject.net.config.NetworkConfigEvent;
34 import org.onosproject.net.config.NetworkConfigListener; 37 import org.onosproject.net.config.NetworkConfigListener;
35 import org.onosproject.net.config.NetworkConfigRegistry; 38 import org.onosproject.net.config.NetworkConfigRegistry;
36 import org.onosproject.net.config.basics.SubjectFactories; 39 import org.onosproject.net.config.basics.SubjectFactories;
40 +import org.onosproject.net.host.HostService;
41 +import org.onosproject.net.mcast.McastEvent;
42 +import org.onosproject.net.mcast.McastListener;
43 +import org.onosproject.net.mcast.McastRoute;
44 +import org.onosproject.net.mcast.MulticastRouteService;
37 import org.onosproject.net.packet.PacketService; 45 import org.onosproject.net.packet.PacketService;
46 +import org.onosproject.routing.RouteEntry;
47 +import org.onosproject.routing.RoutingService;
38 import org.slf4j.Logger; 48 import org.slf4j.Logger;
39 49
40 import java.util.Map; 50 import java.util.Map;
...@@ -73,6 +83,8 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -73,6 +83,8 @@ public class PIMInterfaceManager implements PIMInterfaceService {
73 83
74 private final int timeoutTaskPeriod = DEFAULT_TASK_PERIOD_MS; 84 private final int timeoutTaskPeriod = DEFAULT_TASK_PERIOD_MS;
75 85
86 + private final int joinTaskPeriod = 10000;
87 +
76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 protected PacketService packetService; 89 protected PacketService packetService;
78 90
...@@ -82,13 +94,26 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -82,13 +94,26 @@ public class PIMInterfaceManager implements PIMInterfaceService {
82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected InterfaceService interfaceService; 95 protected InterfaceService interfaceService;
84 96
97 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 + protected HostService hostService;
99 +
100 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 + protected MulticastRouteService multicastRouteService;
102 +
103 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
104 + protected RoutingService unicastRoutingService;
105 +
85 // Store PIM Interfaces in a map key'd by ConnectPoint 106 // Store PIM Interfaces in a map key'd by ConnectPoint
86 private final Map<ConnectPoint, PIMInterface> pimInterfaces = Maps.newConcurrentMap(); 107 private final Map<ConnectPoint, PIMInterface> pimInterfaces = Maps.newConcurrentMap();
87 108
109 + private final Map<McastRoute, PIMInterface> routes = Maps.newConcurrentMap();
110 +
88 private final InternalNetworkConfigListener configListener = 111 private final InternalNetworkConfigListener configListener =
89 new InternalNetworkConfigListener(); 112 new InternalNetworkConfigListener();
90 private final InternalInterfaceListener interfaceListener = 113 private final InternalInterfaceListener interfaceListener =
91 new InternalInterfaceListener(); 114 new InternalInterfaceListener();
115 + private final InternalMulticastListener multicastListener =
116 + new InternalMulticastListener();
92 117
93 private final ConfigFactory<ConnectPoint, PimInterfaceConfig> pimConfigFactory 118 private final ConfigFactory<ConnectPoint, PimInterfaceConfig> pimConfigFactory
94 = new ConfigFactory<ConnectPoint, PimInterfaceConfig>( 119 = new ConfigFactory<ConnectPoint, PimInterfaceConfig>(
...@@ -115,6 +140,9 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -115,6 +140,9 @@ public class PIMInterfaceManager implements PIMInterfaceService {
115 140
116 networkConfig.addListener(configListener); 141 networkConfig.addListener(configListener);
117 interfaceService.addListener(interfaceListener); 142 interfaceService.addListener(interfaceListener);
143 + multicastRouteService.addListener(multicastListener);
144 +
145 + multicastRouteService.getRoutes().forEach(this::addRoute);
118 146
119 // Schedule the periodic hello sender. 147 // Schedule the periodic hello sender.
120 scheduledExecutorService.scheduleAtFixedRate( 148 scheduledExecutorService.scheduleAtFixedRate(
...@@ -128,6 +156,11 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -128,6 +156,11 @@ public class PIMInterfaceManager implements PIMInterfaceService {
128 () -> pimInterfaces.values().forEach(PIMInterface::checkNeighborTimeouts)), 156 () -> pimInterfaces.values().forEach(PIMInterface::checkNeighborTimeouts)),
129 0, timeoutTaskPeriod, TimeUnit.MILLISECONDS); 157 0, timeoutTaskPeriod, TimeUnit.MILLISECONDS);
130 158
159 + scheduledExecutorService.scheduleAtFixedRate(
160 + SafeRecurringTask.wrap(
161 + () -> pimInterfaces.values().forEach(PIMInterface::sendJoins)),
162 + 0, joinTaskPeriod, TimeUnit.MILLISECONDS);
163 +
131 log.info("Started"); 164 log.info("Started");
132 } 165 }
133 166
...@@ -135,6 +168,7 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -135,6 +168,7 @@ public class PIMInterfaceManager implements PIMInterfaceService {
135 public void deactivate() { 168 public void deactivate() {
136 interfaceService.removeListener(interfaceListener); 169 interfaceService.removeListener(interfaceListener);
137 networkConfig.removeListener(configListener); 170 networkConfig.removeListener(configListener);
171 + multicastRouteService.removeListener(multicastListener);
138 networkConfig.unregisterConfigFactory(pimConfigFactory); 172 networkConfig.unregisterConfigFactory(pimConfigFactory);
139 173
140 // Shutdown the periodic hello task. 174 // Shutdown the periodic hello task.
...@@ -202,6 +236,65 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -202,6 +236,65 @@ public class PIMInterfaceManager implements PIMInterfaceService {
202 return builder.build(); 236 return builder.build();
203 } 237 }
204 238
239 + private void addRoute(McastRoute route) {
240 + PIMInterface pimInterface = getSourceInterface(route);
241 +
242 + if (pimInterface == null) {
243 + return;
244 + }
245 +
246 + routes.put(route, pimInterface);
247 + }
248 +
249 + private void removeRoute(McastRoute route) {
250 + PIMInterface pimInterface = routes.remove(route);
251 +
252 + if (pimInterface == null) {
253 + return;
254 + }
255 +
256 + pimInterface.removeRoute(route);
257 + }
258 +
259 + private PIMInterface getSourceInterface(McastRoute route) {
260 + RouteEntry routeEntry = unicastRoutingService.getLongestMatchableRouteEntry(route.source());
261 +
262 + if (routeEntry == null) {
263 + log.warn("No route to source {}", route.source());
264 + return null;
265 + }
266 +
267 + Interface intf = interfaceService.getMatchingInterface(routeEntry.nextHop());
268 +
269 + if (intf == null) {
270 + log.warn("No interface with route to next hop {}", routeEntry.nextHop());
271 + return null;
272 + }
273 +
274 + PIMInterface pimInterface = pimInterfaces.get(intf.connectPoint());
275 +
276 + if (pimInterface == null) {
277 + log.warn("PIM is not enabled on interface {}", intf);
278 + return null;
279 + }
280 +
281 + Set<Host> hosts = hostService.getHostsByIp(routeEntry.nextHop());
282 + Host host = null;
283 + for (Host h : hosts) {
284 + if (h.vlan().equals(intf.vlan())) {
285 + host = h;
286 + }
287 + }
288 + if (host == null) {
289 + log.warn("Next hop host entry not found: {}", routeEntry.nextHop());
290 + return null;
291 + }
292 +
293 + pimInterface.addRoute(route, routeEntry.nextHop(), host.mac());
294 +
295 + return pimInterface;
296 + }
297 +
205 /** 298 /**
206 * Listener for network config events. 299 * Listener for network config events.
207 */ 300 */
...@@ -261,4 +354,26 @@ public class PIMInterfaceManager implements PIMInterfaceService { ...@@ -261,4 +354,26 @@ public class PIMInterfaceManager implements PIMInterfaceService {
261 } 354 }
262 } 355 }
263 } 356 }
357 +
358 + /**
359 + * Listener for multicast route events.
360 + */
361 + private class InternalMulticastListener implements McastListener {
362 + @Override
363 + public void event(McastEvent event) {
364 + switch (event.type()) {
365 + case ROUTE_ADDED:
366 + addRoute(event.subject().route());
367 + break;
368 + case ROUTE_REMOVED:
369 + removeRoute(event.subject().route());
370 + break;
371 + case SOURCE_ADDED:
372 + case SINK_ADDED:
373 + case SINK_REMOVED:
374 + default:
375 + break;
376 + }
377 + }
378 + }
264 } 379 }
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
15 */ 15 */
16 package org.onosproject.routing.impl; 16 package org.onosproject.routing.impl;
17 17
18 +import com.google.common.collect.Lists;
18 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
19 import com.google.common.util.concurrent.MoreExecutors; 20 import com.google.common.util.concurrent.MoreExecutors;
20 -
21 import org.junit.Before; 21 import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.onlab.junit.TestUtils; 23 import org.onlab.junit.TestUtils;
...@@ -57,6 +57,7 @@ import org.onosproject.routing.RouteEntry; ...@@ -57,6 +57,7 @@ import org.onosproject.routing.RouteEntry;
57 57
58 import java.util.Collections; 58 import java.util.Collections;
59 import java.util.HashSet; 59 import java.util.HashSet;
60 +import java.util.List;
60 import java.util.Set; 61 import java.util.Set;
61 import java.util.concurrent.ExecutorService; 62 import java.util.concurrent.ExecutorService;
62 63
...@@ -124,7 +125,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest { ...@@ -124,7 +125,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
124 * Sets up InterfaceService. 125 * Sets up InterfaceService.
125 */ 126 */
126 private void setUpInterfaceService() { 127 private void setUpInterfaceService() {
127 - Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); 128 + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
128 interfaceIpAddresses1.add(new InterfaceIpAddress( 129 interfaceIpAddresses1.add(new InterfaceIpAddress(
129 IpAddress.valueOf("192.168.10.101"), 130 IpAddress.valueOf("192.168.10.101"),
130 IpPrefix.valueOf("192.168.10.0/24"))); 131 IpPrefix.valueOf("192.168.10.0/24")));
...@@ -133,7 +134,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest { ...@@ -133,7 +134,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
133 VlanId.NONE); 134 VlanId.NONE);
134 interfaces.add(sw1Eth1); 135 interfaces.add(sw1Eth1);
135 136
136 - Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); 137 + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
137 interfaceIpAddresses2.add( 138 interfaceIpAddresses2.add(
138 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), 139 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
139 IpPrefix.valueOf("192.168.20.0/24"))); 140 IpPrefix.valueOf("192.168.20.0/24")));
...@@ -142,7 +143,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest { ...@@ -142,7 +143,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
142 VlanId.NONE); 143 VlanId.NONE);
143 interfaces.add(sw2Eth1); 144 interfaces.add(sw2Eth1);
144 145
145 - Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); 146 + List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList();
146 interfaceIpAddresses3.add( 147 interfaceIpAddresses3.add(
147 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), 148 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
148 IpPrefix.valueOf("192.168.30.0/24"))); 149 IpPrefix.valueOf("192.168.30.0/24")));
...@@ -155,7 +156,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest { ...@@ -155,7 +156,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
155 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), 156 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
156 IpPrefix.valueOf("192.168.40.0/24")); 157 IpPrefix.valueOf("192.168.40.0/24"));
157 Interface sw4Eth1 = new Interface(SW4_ETH1, 158 Interface sw4Eth1 = new Interface(SW4_ETH1,
158 - Sets.newHashSet(interfaceIpAddress4), 159 + Lists.newArrayList(interfaceIpAddress4),
159 MacAddress.valueOf("00:00:00:00:00:04"), 160 MacAddress.valueOf("00:00:00:00:00:04"),
160 VlanId.vlanId((short) 1)); 161 VlanId.vlanId((short) 1));
161 162
......
...@@ -173,7 +173,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { ...@@ -173,7 +173,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
173 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"), 173 new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
174 IpPrefix.valueOf("192.168.10.0/24")); 174 IpPrefix.valueOf("192.168.10.0/24"));
175 Interface intfsw1eth1 = new Interface(s1Eth1, 175 Interface intfsw1eth1 = new Interface(s1Eth1,
176 - Collections.singleton(ia1), 176 + Collections.singletonList(ia1),
177 MacAddress.valueOf("00:00:00:00:00:01"), 177 MacAddress.valueOf("00:00:00:00:00:01"),
178 VlanId.NONE); 178 VlanId.NONE);
179 179
...@@ -183,7 +183,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { ...@@ -183,7 +183,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
183 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), 183 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
184 IpPrefix.valueOf("192.168.20.0/24")); 184 IpPrefix.valueOf("192.168.20.0/24"));
185 Interface intfsw2eth1 = new Interface(s2Eth1, 185 Interface intfsw2eth1 = new Interface(s2Eth1,
186 - Collections.singleton(ia2), 186 + Collections.singletonList(ia2),
187 MacAddress.valueOf("00:00:00:00:00:02"), 187 MacAddress.valueOf("00:00:00:00:00:02"),
188 VlanId.NONE); 188 VlanId.NONE);
189 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); 189 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
...@@ -193,7 +193,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { ...@@ -193,7 +193,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
193 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), 193 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
194 IpPrefix.valueOf("192.168.30.0/24")); 194 IpPrefix.valueOf("192.168.30.0/24"));
195 Interface intfsw2eth1intf2 = new Interface(s2Eth1, 195 Interface intfsw2eth1intf2 = new Interface(s2Eth1,
196 - Collections.singleton(ia3), 196 + Collections.singletonList(ia3),
197 MacAddress.valueOf("00:00:00:00:00:03"), 197 MacAddress.valueOf("00:00:00:00:00:03"),
198 VlanId.NONE); 198 VlanId.NONE);
199 configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); 199 configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.sdnip; 17 package org.onosproject.sdnip;
18 18
19 +import com.google.common.collect.Lists;
19 import com.google.common.collect.Sets; 20 import com.google.common.collect.Sets;
20 import org.junit.Before; 21 import org.junit.Before;
21 import org.junit.Test; 22 import org.junit.Test;
...@@ -53,6 +54,7 @@ import org.onosproject.routing.config.RoutingConfigurationService; ...@@ -53,6 +54,7 @@ import org.onosproject.routing.config.RoutingConfigurationService;
53 import java.util.Collections; 54 import java.util.Collections;
54 import java.util.HashMap; 55 import java.util.HashMap;
55 import java.util.HashSet; 56 import java.util.HashSet;
57 +import java.util.List;
56 import java.util.Map; 58 import java.util.Map;
57 import java.util.Set; 59 import java.util.Set;
58 60
...@@ -151,7 +153,7 @@ public class SdnIpFibTest extends AbstractIntentTest { ...@@ -151,7 +153,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
151 * Sets up InterfaceService. 153 * Sets up InterfaceService.
152 */ 154 */
153 private void setUpInterfaceService() { 155 private void setUpInterfaceService() {
154 - Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); 156 + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
155 interfaceIpAddresses1.add(new InterfaceIpAddress( 157 interfaceIpAddresses1.add(new InterfaceIpAddress(
156 IpAddress.valueOf("192.168.10.101"), 158 IpAddress.valueOf("192.168.10.101"),
157 IpPrefix.valueOf("192.168.10.0/24"))); 159 IpPrefix.valueOf("192.168.10.0/24")));
...@@ -160,7 +162,7 @@ public class SdnIpFibTest extends AbstractIntentTest { ...@@ -160,7 +162,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
160 VlanId.NONE); 162 VlanId.NONE);
161 interfaces.add(sw1Eth1); 163 interfaces.add(sw1Eth1);
162 164
163 - Set<InterfaceIpAddress> interfaceIpAddresses2 = Sets.newHashSet(); 165 + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
164 interfaceIpAddresses2.add( 166 interfaceIpAddresses2.add(
165 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), 167 new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
166 IpPrefix.valueOf("192.168.20.0/24"))); 168 IpPrefix.valueOf("192.168.20.0/24")));
...@@ -169,7 +171,7 @@ public class SdnIpFibTest extends AbstractIntentTest { ...@@ -169,7 +171,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
169 VlanId.NONE); 171 VlanId.NONE);
170 interfaces.add(sw2Eth1); 172 interfaces.add(sw2Eth1);
171 173
172 - Set<InterfaceIpAddress> interfaceIpAddresses3 = Sets.newHashSet(); 174 + List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList();
173 interfaceIpAddresses3.add( 175 interfaceIpAddresses3.add(
174 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"), 176 new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
175 IpPrefix.valueOf("192.168.30.0/24"))); 177 IpPrefix.valueOf("192.168.30.0/24")));
...@@ -182,7 +184,7 @@ public class SdnIpFibTest extends AbstractIntentTest { ...@@ -182,7 +184,7 @@ public class SdnIpFibTest extends AbstractIntentTest {
182 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), 184 new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
183 IpPrefix.valueOf("192.168.40.0/24")); 185 IpPrefix.valueOf("192.168.40.0/24"));
184 Interface sw4Eth1 = new Interface(SW4_ETH1, 186 Interface sw4Eth1 = new Interface(SW4_ETH1,
185 - Sets.newHashSet(interfaceIpAddress4), 187 + Lists.newArrayList(interfaceIpAddress4),
186 MacAddress.valueOf("00:00:00:00:00:04"), 188 MacAddress.valueOf("00:00:00:00:00:04"),
187 VlanId.vlanId((short) 1)); 189 VlanId.vlanId((short) 1));
188 190
......
...@@ -137,7 +137,7 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -137,7 +137,7 @@ public class DeviceConfiguration implements DeviceProperties {
137 // skip if there is no corresponding device for this ConenctPoint 137 // skip if there is no corresponding device for this ConenctPoint
138 if (info != null) { 138 if (info != null) {
139 // Extract subnet information 139 // Extract subnet information
140 - Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses(); 140 + List<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddressesList();
141 interfaceAddresses.forEach(interfaceAddress -> { 141 interfaceAddresses.forEach(interfaceAddress -> {
142 // Do not add /0 and /32 to gateway IP list 142 // Do not add /0 and /32 to gateway IP list
143 int prefixLength = interfaceAddress.subnetAddress().prefixLength(); 143 int prefixLength = interfaceAddress.subnetAddress().prefixLength();
...@@ -495,4 +495,4 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -495,4 +495,4 @@ public class DeviceConfiguration implements DeviceProperties {
495 public Set<ConnectPoint> excludedPorts() { 495 public Set<ConnectPoint> excludedPorts() {
496 return excludedPorts; 496 return excludedPorts;
497 } 497 }
498 -}
...\ No newline at end of file ...\ No newline at end of file
498 +}
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 16
17 package org.onosproject.cli.net; 17 package org.onosproject.cli.net;
18 18
19 -import com.google.common.collect.Sets; 19 +import com.google.common.collect.Lists;
20 import org.apache.karaf.shell.commands.Argument; 20 import org.apache.karaf.shell.commands.Argument;
21 import org.apache.karaf.shell.commands.Command; 21 import org.apache.karaf.shell.commands.Command;
22 import org.apache.karaf.shell.commands.Option; 22 import org.apache.karaf.shell.commands.Option;
...@@ -28,7 +28,7 @@ import org.onosproject.incubator.net.intf.InterfaceAdminService; ...@@ -28,7 +28,7 @@ import org.onosproject.incubator.net.intf.InterfaceAdminService;
28 import org.onosproject.net.ConnectPoint; 28 import org.onosproject.net.ConnectPoint;
29 import org.onosproject.net.host.InterfaceIpAddress; 29 import org.onosproject.net.host.InterfaceIpAddress;
30 30
31 -import java.util.Set; 31 +import java.util.List;
32 32
33 /** 33 /**
34 * Adds a new interface configuration. 34 * Adds a new interface configuration.
...@@ -66,7 +66,7 @@ public class InterfaceAddCommand extends AbstractShellCommand { ...@@ -66,7 +66,7 @@ public class InterfaceAddCommand extends AbstractShellCommand {
66 protected void execute() { 66 protected void execute() {
67 InterfaceAdminService interfaceService = get(InterfaceAdminService.class); 67 InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
68 68
69 - Set<InterfaceIpAddress> ipAddresses = Sets.newHashSet(); 69 + List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
70 if (ips != null) { 70 if (ips != null) {
71 for (String strIp : ips) { 71 for (String strIp : ips) {
72 ipAddresses.add(InterfaceIpAddress.valueOf(strIp)); 72 ipAddresses.add(InterfaceIpAddress.valueOf(strIp));
......
...@@ -185,7 +185,7 @@ public class HostMonitorTest { ...@@ -185,7 +185,7 @@ public class HostMonitorTest {
185 185
186 InterfaceService interfaceService = createMock(InterfaceService.class); 186 InterfaceService interfaceService = createMock(InterfaceService.class);
187 expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR)) 187 expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR))
188 - .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE)) 188 + .andReturn(new Interface(cp, Collections.singletonList(IA1), sourceMac, VlanId.NONE))
189 .anyTimes(); 189 .anyTimes();
190 replay(interfaceService); 190 replay(interfaceService);
191 191
...@@ -253,7 +253,7 @@ public class HostMonitorTest { ...@@ -253,7 +253,7 @@ public class HostMonitorTest {
253 253
254 InterfaceService interfaceService = createMock(InterfaceService.class); 254 InterfaceService interfaceService = createMock(InterfaceService.class);
255 expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR)) 255 expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR))
256 - .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.NONE)) 256 + .andReturn(new Interface(cp, Collections.singletonList(IA2), sourceMac2, VlanId.NONE))
257 .anyTimes(); 257 .anyTimes();
258 replay(interfaceService); 258 replay(interfaceService);
259 259
...@@ -323,7 +323,7 @@ public class HostMonitorTest { ...@@ -323,7 +323,7 @@ public class HostMonitorTest {
323 323
324 InterfaceService interfaceService = createMock(InterfaceService.class); 324 InterfaceService interfaceService = createMock(InterfaceService.class);
325 expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR)) 325 expect(interfaceService.getMatchingInterface(TARGET_IPV4_ADDR))
326 - .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.vlanId(vlan))) 326 + .andReturn(new Interface(cp, Collections.singletonList(IA1), sourceMac, VlanId.vlanId(vlan)))
327 .anyTimes(); 327 .anyTimes();
328 replay(interfaceService); 328 replay(interfaceService);
329 329
...@@ -392,7 +392,7 @@ public class HostMonitorTest { ...@@ -392,7 +392,7 @@ public class HostMonitorTest {
392 392
393 InterfaceService interfaceService = createMock(InterfaceService.class); 393 InterfaceService interfaceService = createMock(InterfaceService.class);
394 expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR)) 394 expect(interfaceService.getMatchingInterface(TARGET_IPV6_ADDR))
395 - .andReturn(new Interface(cp, Collections.singleton(IA2), sourceMac2, VlanId.vlanId(vlan))) 395 + .andReturn(new Interface(cp, Collections.singletonList(IA2), sourceMac2, VlanId.vlanId(vlan)))
396 .anyTimes(); 396 .anyTimes();
397 replay(interfaceService); 397 replay(interfaceService);
398 398
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.proxyarp.impl; 16 package org.onosproject.net.proxyarp.impl;
17 17
18 +import com.google.common.collect.Lists;
18 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
19 import org.junit.Before; 20 import org.junit.Before;
20 import org.junit.Test; 21 import org.junit.Test;
...@@ -295,10 +296,10 @@ public class ProxyArpManagerTest { ...@@ -295,10 +296,10 @@ public class ProxyArpManagerTest {
295 InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4); 296 InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4);
296 297
297 // Setting up interfaces 298 // Setting up interfaces
298 - Interface intf1 = new Interface(cp, Sets.newHashSet(ia1, ia3), 299 + Interface intf1 = new Interface(cp, Lists.newArrayList(ia1, ia3),
299 MacAddress.valueOf(2 * i - 1), 300 MacAddress.valueOf(2 * i - 1),
300 VlanId.vlanId((short) 1)); 301 VlanId.vlanId((short) 1));
301 - Interface intf2 = new Interface(cp, Sets.newHashSet(ia2, ia4), 302 + Interface intf2 = new Interface(cp, Lists.newArrayList(ia2, ia4),
302 MacAddress.valueOf(2 * i), 303 MacAddress.valueOf(2 * i),
303 VlanId.NONE); 304 VlanId.NONE);
304 305
...@@ -312,7 +313,7 @@ public class ProxyArpManagerTest { ...@@ -312,7 +313,7 @@ public class ProxyArpManagerTest {
312 } 313 }
313 for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { 314 for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) {
314 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); 315 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
315 - Interface intf1 = new Interface(cp, null, 316 + Interface intf1 = new Interface(cp, Collections.emptyList(),
316 MacAddress.NONE, 317 MacAddress.NONE,
317 VlanId.vlanId((short) 1)); 318 VlanId.vlanId((short) 1));
318 319
...@@ -850,7 +851,7 @@ public class ProxyArpManagerTest { ...@@ -850,7 +851,7 @@ public class ProxyArpManagerTest {
850 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); 851 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
851 expect(interfaceService.getInterfacesByIp(ourIp)) 852 expect(interfaceService.getInterfacesByIp(ourIp))
852 .andReturn(Collections.singleton(new Interface(getLocation(1), 853 .andReturn(Collections.singleton(new Interface(getLocation(1),
853 - Collections.singleton(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))), 854 + Collections.singletonList(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))),
854 ourMac, VLAN1))); 855 ourMac, VLAN1)));
855 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); 856 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
856 replay(hostService); 857 replay(hostService);
...@@ -883,7 +884,7 @@ public class ProxyArpManagerTest { ...@@ -883,7 +884,7 @@ public class ProxyArpManagerTest {
883 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); 884 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
884 expect(interfaceService.getInterfacesByIp(ourIp)) 885 expect(interfaceService.getInterfacesByIp(ourIp))
885 .andReturn(Collections.singleton(new Interface(getLocation(1), 886 .andReturn(Collections.singleton(new Interface(getLocation(1),
886 - Collections.singleton(new InterfaceIpAddress( 887 + Collections.singletonList(new InterfaceIpAddress(
887 ourIp, 888 ourIp,
888 IpPrefix.valueOf("1000::1/64"))), 889 IpPrefix.valueOf("1000::1/64"))),
889 ourMac, 890 ourMac,
......
...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode;
20 import com.fasterxml.jackson.databind.node.ArrayNode; 20 import com.fasterxml.jackson.databind.node.ArrayNode;
21 import com.fasterxml.jackson.databind.node.ObjectNode; 21 import com.fasterxml.jackson.databind.node.ObjectNode;
22 import com.google.common.annotations.Beta; 22 import com.google.common.annotations.Beta;
23 +import com.google.common.collect.Lists;
23 import com.google.common.collect.Sets; 24 import com.google.common.collect.Sets;
24 import org.onlab.packet.MacAddress; 25 import org.onlab.packet.MacAddress;
25 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
...@@ -29,6 +30,7 @@ import org.onosproject.net.config.Config; ...@@ -29,6 +30,7 @@ import org.onosproject.net.config.Config;
29 import org.onosproject.net.host.InterfaceIpAddress; 30 import org.onosproject.net.host.InterfaceIpAddress;
30 31
31 import java.util.Iterator; 32 import java.util.Iterator;
33 +import java.util.List;
32 import java.util.Set; 34 import java.util.Set;
33 35
34 import static com.google.common.base.Preconditions.checkArgument; 36 import static com.google.common.base.Preconditions.checkArgument;
...@@ -61,7 +63,7 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -61,7 +63,7 @@ public class InterfaceConfig extends Config<ConnectPoint> {
61 for (JsonNode intfNode : array) { 63 for (JsonNode intfNode : array) {
62 String name = intfNode.path(NAME).asText(null); 64 String name = intfNode.path(NAME).asText(null);
63 65
64 - Set<InterfaceIpAddress> ips = getIps(intfNode); 66 + List<InterfaceIpAddress> ips = getIps(intfNode);
65 67
66 String mac = intfNode.path(MAC).asText(); 68 String mac = intfNode.path(MAC).asText();
67 MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac); 69 MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);
...@@ -98,7 +100,7 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -98,7 +100,7 @@ public class InterfaceConfig extends Config<ConnectPoint> {
98 } 100 }
99 101
100 if (!intf.ipAddresses().isEmpty()) { 102 if (!intf.ipAddresses().isEmpty()) {
101 - intfNode.set(IPS, putIps(intf.ipAddresses())); 103 + intfNode.set(IPS, putIps(intf.ipAddressesList()));
102 } 104 }
103 105
104 if (!intf.vlan().equals(VlanId.NONE)) { 106 if (!intf.vlan().equals(VlanId.NONE)) {
...@@ -133,8 +135,8 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -133,8 +135,8 @@ public class InterfaceConfig extends Config<ConnectPoint> {
133 return vlan; 135 return vlan;
134 } 136 }
135 137
136 - private Set<InterfaceIpAddress> getIps(JsonNode node) { 138 + private List<InterfaceIpAddress> getIps(JsonNode node) {
137 - Set<InterfaceIpAddress> ips = Sets.newHashSet(); 139 + List<InterfaceIpAddress> ips = Lists.newArrayList();
138 140
139 JsonNode ipsNode = node.get(IPS); 141 JsonNode ipsNode = node.get(IPS);
140 if (ipsNode != null) { 142 if (ipsNode != null) {
...@@ -145,7 +147,7 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -145,7 +147,7 @@ public class InterfaceConfig extends Config<ConnectPoint> {
145 return ips; 147 return ips;
146 } 148 }
147 149
148 - private ArrayNode putIps(Set<InterfaceIpAddress> intfIpAddresses) { 150 + private ArrayNode putIps(List<InterfaceIpAddress> intfIpAddresses) {
149 ArrayNode ipArray = mapper.createArrayNode(); 151 ArrayNode ipArray = mapper.createArrayNode();
150 152
151 intfIpAddresses.forEach(i -> ipArray.add(i.toString())); 153 intfIpAddresses.forEach(i -> ipArray.add(i.toString()));
......
...@@ -17,14 +17,16 @@ package org.onosproject.incubator.net.intf; ...@@ -17,14 +17,16 @@ package org.onosproject.incubator.net.intf;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 import com.google.common.base.MoreObjects; 19 import com.google.common.base.MoreObjects;
20 -import com.google.common.collect.Sets; 20 +import com.google.common.collect.Lists;
21 import org.onlab.packet.MacAddress; 21 import org.onlab.packet.MacAddress;
22 import org.onlab.packet.VlanId; 22 import org.onlab.packet.VlanId;
23 import org.onosproject.net.ConnectPoint; 23 import org.onosproject.net.ConnectPoint;
24 import org.onosproject.net.host.InterfaceIpAddress; 24 import org.onosproject.net.host.InterfaceIpAddress;
25 25
26 +import java.util.List;
26 import java.util.Objects; 27 import java.util.Objects;
27 import java.util.Set; 28 import java.util.Set;
29 +import java.util.stream.Collectors;
28 30
29 import static com.google.common.base.Preconditions.checkNotNull; 31 import static com.google.common.base.Preconditions.checkNotNull;
30 32
...@@ -38,7 +40,7 @@ public class Interface { ...@@ -38,7 +40,7 @@ public class Interface {
38 40
39 private final String name; 41 private final String name;
40 private final ConnectPoint connectPoint; 42 private final ConnectPoint connectPoint;
41 - private final Set<InterfaceIpAddress> ipAddresses; 43 + private final List<InterfaceIpAddress> ipAddresses;
42 private final MacAddress macAddress; 44 private final MacAddress macAddress;
43 private final VlanId vlan; 45 private final VlanId vlan;
44 46
...@@ -47,16 +49,38 @@ public class Interface { ...@@ -47,16 +49,38 @@ public class Interface {
47 * 49 *
48 * @param name name of the interface 50 * @param name name of the interface
49 * @param connectPoint the connect point this interface maps to 51 * @param connectPoint the connect point this interface maps to
50 - * @param ipAddresses Set of IP addresses 52 + * @param ipAddresses list of IP addresses
53 + * @param macAddress MAC address
54 + * @param vlan VLAN ID
55 + */
56 + public Interface(String name, ConnectPoint connectPoint,
57 + List<InterfaceIpAddress> ipAddresses,
58 + MacAddress macAddress, VlanId vlan) {
59 + this.name = name == null ? NO_INTERFACE_NAME : name;
60 + this.connectPoint = checkNotNull(connectPoint);
61 + this.ipAddresses = ipAddresses == null ? Lists.newArrayList() : ipAddresses;
62 + this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
63 + this.vlan = vlan == null ? VlanId.NONE : vlan;
64 + }
65 +
66 + /**
67 + * Creates new Interface with the provided configuration.
68 + *
69 + * @param name name of the interface
70 + * @param connectPoint the connect point this interface maps to
71 + * @param ipAddresses set of IP addresses
51 * @param macAddress MAC address 72 * @param macAddress MAC address
52 * @param vlan VLAN ID 73 * @param vlan VLAN ID
74 + * @deprecated in Falcon release, in favour of ordered list
53 */ 75 */
76 + @Deprecated
54 public Interface(String name, ConnectPoint connectPoint, 77 public Interface(String name, ConnectPoint connectPoint,
55 Set<InterfaceIpAddress> ipAddresses, 78 Set<InterfaceIpAddress> ipAddresses,
56 MacAddress macAddress, VlanId vlan) { 79 MacAddress macAddress, VlanId vlan) {
57 this.name = name == null ? NO_INTERFACE_NAME : name; 80 this.name = name == null ? NO_INTERFACE_NAME : name;
58 this.connectPoint = checkNotNull(connectPoint); 81 this.connectPoint = checkNotNull(connectPoint);
59 - this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses; 82 + this.ipAddresses = ipAddresses == null ? Lists.newArrayList() :
83 + ipAddresses.stream().collect(Collectors.toList());
60 this.macAddress = macAddress == null ? MacAddress.NONE : macAddress; 84 this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
61 this.vlan = vlan == null ? VlanId.NONE : vlan; 85 this.vlan = vlan == null ? VlanId.NONE : vlan;
62 } 86 }
...@@ -68,7 +92,9 @@ public class Interface { ...@@ -68,7 +92,9 @@ public class Interface {
68 * @param ipAddresses Set of IP addresses 92 * @param ipAddresses Set of IP addresses
69 * @param macAddress MAC address 93 * @param macAddress MAC address
70 * @param vlan VLAN ID 94 * @param vlan VLAN ID
95 + * @deprecated in Falcon release - use constructors with names instead
71 */ 96 */
97 + @Deprecated
72 public Interface(ConnectPoint connectPoint, 98 public Interface(ConnectPoint connectPoint,
73 Set<InterfaceIpAddress> ipAddresses, 99 Set<InterfaceIpAddress> ipAddresses,
74 MacAddress macAddress, VlanId vlan) { 100 MacAddress macAddress, VlanId vlan) {
...@@ -76,6 +102,22 @@ public class Interface { ...@@ -76,6 +102,22 @@ public class Interface {
76 } 102 }
77 103
78 /** 104 /**
105 + * Creates new Interface with the provided configuration.
106 + *
107 + * @param connectPoint the connect point this interface maps to
108 + * @param ipAddresses Set of IP addresses
109 + * @param macAddress MAC address
110 + * @param vlan VLAN ID
111 + * @deprecated in Falcon release - use constructors with names instead
112 + */
113 + @Deprecated
114 + public Interface(ConnectPoint connectPoint,
115 + List<InterfaceIpAddress> ipAddresses,
116 + MacAddress macAddress, VlanId vlan) {
117 + this(NO_INTERFACE_NAME, connectPoint, ipAddresses, macAddress, vlan);
118 + }
119 +
120 + /**
79 * Retrieves the name of the interface. 121 * Retrieves the name of the interface.
80 * 122 *
81 * @return name 123 * @return name
...@@ -97,8 +139,20 @@ public class Interface { ...@@ -97,8 +139,20 @@ public class Interface {
97 * Retrieves the set of IP addresses that are assigned to the interface. 139 * Retrieves the set of IP addresses that are assigned to the interface.
98 * 140 *
99 * @return the set of interface IP addresses 141 * @return the set of interface IP addresses
142 + * @deprecated in Falcon release in favour of an ordered list
100 */ 143 */
144 + @Deprecated
101 public Set<InterfaceIpAddress> ipAddresses() { 145 public Set<InterfaceIpAddress> ipAddresses() {
146 + return ipAddresses.stream().collect(Collectors.toSet());
147 + }
148 +
149 + /**
150 + * Retrieves a list of IP addresses that are assigned to the interface in
151 + * the order that they were configured.
152 + *
153 + * @return list of IP addresses
154 + */
155 + public List<InterfaceIpAddress> ipAddressesList() {
102 return ipAddresses; 156 return ipAddresses;
103 } 157 }
104 158
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 16
17 package org.onosproject.incubator.net.intf.impl; 17 package org.onosproject.incubator.net.intf.impl;
18 18
19 +import com.google.common.collect.Lists;
19 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
20 import com.google.common.collect.Sets; 21 import com.google.common.collect.Sets;
21 import org.junit.Before; 22 import org.junit.Before;
...@@ -35,6 +36,7 @@ import org.onosproject.net.config.NetworkConfigServiceAdapter; ...@@ -35,6 +36,7 @@ import org.onosproject.net.config.NetworkConfigServiceAdapter;
35 import org.onosproject.net.host.InterfaceIpAddress; 36 import org.onosproject.net.host.InterfaceIpAddress;
36 37
37 import java.util.Collections; 38 import java.util.Collections;
39 +import java.util.List;
38 import java.util.Map; 40 import java.util.Map;
39 import java.util.Set; 41 import java.util.Set;
40 42
...@@ -87,7 +89,7 @@ public class InterfaceManagerTest { ...@@ -87,7 +89,7 @@ public class InterfaceManagerTest {
87 InterfaceIpAddress ia = InterfaceIpAddress.valueOf("192.168." + i + ".1/24"); 89 InterfaceIpAddress ia = InterfaceIpAddress.valueOf("192.168." + i + ".1/24");
88 90
89 Interface intf = new Interface(cp, 91 Interface intf = new Interface(cp,
90 - Sets.newHashSet(ia), 92 + Collections.singletonList(ia),
91 MacAddress.valueOf(i), 93 MacAddress.valueOf(i),
92 VlanId.vlanId((short) i)); 94 VlanId.vlanId((short) i));
93 95
...@@ -150,7 +152,7 @@ public class InterfaceManagerTest { ...@@ -150,7 +152,7 @@ public class InterfaceManagerTest {
150 VlanId vlanId = VlanId.vlanId((short) 1); 152 VlanId vlanId = VlanId.vlanId((short) 1);
151 ConnectPoint cp = ConnectPoint.deviceConnectPoint("of:0000000000000001/2"); 153 ConnectPoint cp = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
152 Interface newIntf = new Interface(cp, 154 Interface newIntf = new Interface(cp,
153 - Collections.emptySet(), 155 + Collections.emptyList(),
154 MacAddress.valueOf(100), 156 MacAddress.valueOf(100),
155 vlanId); 157 vlanId);
156 158
...@@ -184,14 +186,14 @@ public class InterfaceManagerTest { ...@@ -184,14 +186,14 @@ public class InterfaceManagerTest {
184 // Create an interface that is the same as the existing one, but adds a 186 // Create an interface that is the same as the existing one, but adds a
185 // new IP address 187 // new IP address
186 Interface intf = createInterface(1); 188 Interface intf = createInterface(1);
187 - Set<InterfaceIpAddress> addresses = Sets.newHashSet(intf.ipAddresses()); 189 + List<InterfaceIpAddress> addresses = Lists.newArrayList(intf.ipAddresses());
188 addresses.add(InterfaceIpAddress.valueOf("192.168.100.1/24")); 190 addresses.add(InterfaceIpAddress.valueOf("192.168.100.1/24"));
189 intf = new Interface(intf.connectPoint(), addresses, intf.mac(), intf.vlan()); 191 intf = new Interface(intf.connectPoint(), addresses, intf.mac(), intf.vlan());
190 192
191 // Create a new interface on the same connect point as the existing one 193 // Create a new interface on the same connect point as the existing one
192 InterfaceIpAddress newAddr = InterfaceIpAddress.valueOf("192.168.101.1/24"); 194 InterfaceIpAddress newAddr = InterfaceIpAddress.valueOf("192.168.101.1/24");
193 Interface newIntf = new Interface(cp, 195 Interface newIntf = new Interface(cp,
194 - Collections.singleton(newAddr), 196 + Collections.singletonList(newAddr),
195 MacAddress.valueOf(101), 197 MacAddress.valueOf(101),
196 VlanId.vlanId((short) 101)); 198 VlanId.vlanId((short) 101));
197 199
......