Pavlin Radoslavov

Work toward common IP address classes.

 * Updated classes PortAddresses (in core/api) and Interface (in sdnip)
   to use class InterfaceIpAddress instead of IpPrefix
 * Updated corresponding unit tests and relevant code
 * Minor refactoring inside ProxyArpManager to simplify some of the
   logic and usage related to PortAddresses. Also, renamed
   method findOutsidePortInSubnet() to findPortInSubnet() and updated
   its implementation to reflect better its usage.
...@@ -35,8 +35,11 @@ import org.onlab.onos.net.ConnectPoint; ...@@ -35,8 +35,11 @@ import org.onlab.onos.net.ConnectPoint;
35 import org.onlab.onos.net.DeviceId; 35 import org.onlab.onos.net.DeviceId;
36 import org.onlab.onos.net.PortNumber; 36 import org.onlab.onos.net.PortNumber;
37 import org.onlab.onos.net.host.HostAdminService; 37 import org.onlab.onos.net.host.HostAdminService;
38 +import org.onlab.onos.net.host.InterfaceIpAddress;
38 import org.onlab.onos.net.host.PortAddresses; 39 import org.onlab.onos.net.host.PortAddresses;
40 +import org.onlab.packet.IpAddress;
39 import org.onlab.packet.IpPrefix; 41 import org.onlab.packet.IpPrefix;
42 +import org.onlab.packet.Ip4Prefix;
40 import org.onlab.packet.MacAddress; 43 import org.onlab.packet.MacAddress;
41 import org.slf4j.Logger; 44 import org.slf4j.Logger;
42 45
...@@ -72,12 +75,25 @@ public class NetworkConfigReader { ...@@ -72,12 +75,25 @@ public class NetworkConfigReader {
72 DeviceId.deviceId(dpidToUri(entry.getDpid())), 75 DeviceId.deviceId(dpidToUri(entry.getDpid())),
73 PortNumber.portNumber(entry.getPortNumber())); 76 PortNumber.portNumber(entry.getPortNumber()));
74 77
75 - Set<IpPrefix> ipAddresses = new HashSet<IpPrefix>(); 78 + Set<InterfaceIpAddress> interfaceIpAddresses = new HashSet<>();
76 79
77 for (String strIp : entry.getIpAddresses()) { 80 for (String strIp : entry.getIpAddresses()) {
81 + // Get the IP address and the subnet mask length
78 try { 82 try {
79 - IpPrefix address = IpPrefix.valueOf(strIp); 83 + String[] splits = strIp.split("/");
80 - ipAddresses.add(address); 84 + if (splits.length != 2) {
85 + throw new IllegalArgumentException("Invalid IP address and prefix length format");
86 + }
87 + //
88 + // TODO: For now we need Ip4Prefix to mask-out the
89 + // subnet address.
90 + //
91 + Ip4Prefix subnet4 = new Ip4Prefix(strIp);
92 + IpPrefix subnet = IpPrefix.valueOf(subnet4.toString());
93 + IpAddress addr = IpAddress.valueOf(splits[0]);
94 + InterfaceIpAddress ia =
95 + new InterfaceIpAddress(addr, subnet);
96 + interfaceIpAddresses.add(ia);
81 } catch (IllegalArgumentException e) { 97 } catch (IllegalArgumentException e) {
82 log.warn("Bad format for IP address in config: {}", strIp); 98 log.warn("Bad format for IP address in config: {}", strIp);
83 } 99 }
...@@ -94,7 +110,7 @@ public class NetworkConfigReader { ...@@ -94,7 +110,7 @@ public class NetworkConfigReader {
94 } 110 }
95 111
96 PortAddresses addresses = new PortAddresses(cp, 112 PortAddresses addresses = new PortAddresses(cp,
97 - ipAddresses, macAddress); 113 + interfaceIpAddresses, macAddress);
98 114
99 hostAdminService.bindAddressesToPort(addresses); 115 hostAdminService.bindAddressesToPort(addresses);
100 } 116 }
......
...@@ -24,10 +24,10 @@ import java.util.Set; ...@@ -24,10 +24,10 @@ import java.util.Set;
24 24
25 import org.onlab.onos.net.ConnectPoint; 25 import org.onlab.onos.net.ConnectPoint;
26 import org.onlab.onos.net.host.HostService; 26 import org.onlab.onos.net.host.HostService;
27 +import org.onlab.onos.net.host.InterfaceIpAddress;
27 import org.onlab.onos.net.host.PortAddresses; 28 import org.onlab.onos.net.host.PortAddresses;
28 import org.onlab.onos.sdnip.config.Interface; 29 import org.onlab.onos.sdnip.config.Interface;
29 import org.onlab.packet.IpAddress; 30 import org.onlab.packet.IpAddress;
30 -import org.onlab.packet.IpPrefix;
31 31
32 import com.google.common.collect.Sets; 32 import com.google.common.collect.Sets;
33 33
...@@ -59,7 +59,7 @@ public class HostToInterfaceAdaptor implements InterfaceService { ...@@ -59,7 +59,7 @@ public class HostToInterfaceAdaptor implements InterfaceService {
59 PortAddresses portAddresses = 59 PortAddresses portAddresses =
60 hostService.getAddressBindingsForPort(connectPoint); 60 hostService.getAddressBindingsForPort(connectPoint);
61 61
62 - if (!portAddresses.ips().isEmpty()) { 62 + if (!portAddresses.ipAddresses().isEmpty()) {
63 return new Interface(portAddresses); 63 return new Interface(portAddresses);
64 } 64 }
65 65
...@@ -71,8 +71,8 @@ public class HostToInterfaceAdaptor implements InterfaceService { ...@@ -71,8 +71,8 @@ public class HostToInterfaceAdaptor implements InterfaceService {
71 checkNotNull(ipAddress); 71 checkNotNull(ipAddress);
72 72
73 for (PortAddresses portAddresses : hostService.getAddressBindings()) { 73 for (PortAddresses portAddresses : hostService.getAddressBindings()) {
74 - for (IpPrefix p : portAddresses.ips()) { 74 + for (InterfaceIpAddress ia : portAddresses.ipAddresses()) {
75 - if (p.contains(ipAddress)) { 75 + if (ia.subnetAddress().contains(ipAddress)) {
76 return new Interface(portAddresses); 76 return new Interface(portAddresses);
77 } 77 }
78 } 78 }
......
...@@ -22,8 +22,8 @@ import java.util.Objects; ...@@ -22,8 +22,8 @@ import java.util.Objects;
22 import java.util.Set; 22 import java.util.Set;
23 23
24 import org.onlab.onos.net.ConnectPoint; 24 import org.onlab.onos.net.ConnectPoint;
25 +import org.onlab.onos.net.host.InterfaceIpAddress;
25 import org.onlab.onos.net.host.PortAddresses; 26 import org.onlab.onos.net.host.PortAddresses;
26 -import org.onlab.packet.IpPrefix;
27 import org.onlab.packet.MacAddress; 27 import org.onlab.packet.MacAddress;
28 28
29 import com.google.common.base.MoreObjects; 29 import com.google.common.base.MoreObjects;
...@@ -35,21 +35,22 @@ import com.google.common.collect.Sets; ...@@ -35,21 +35,22 @@ import com.google.common.collect.Sets;
35 */ 35 */
36 public class Interface { 36 public class Interface {
37 private final ConnectPoint connectPoint; 37 private final ConnectPoint connectPoint;
38 - private final Set<IpPrefix> ipAddresses; 38 + private final Set<InterfaceIpAddress> ipAddresses;
39 private final MacAddress macAddress; 39 private final MacAddress macAddress;
40 40
41 /** 41 /**
42 - * Creates an Interface based on a connection point, a set of IP addresses 42 + * Creates an Interface based on a connection point, a set of interface
43 - * and a MAC address. 43 + * IP addresses, and a MAC address.
44 * 44 *
45 * @param connectPoint the connect point this interface is mapped to 45 * @param connectPoint the connect point this interface is mapped to
46 - * @param prefixAddress the IP addresses for the interface 46 + * @param ipAddresses the IP addresses for the interface
47 * @param macAddress the MAC address of the interface 47 * @param macAddress the MAC address of the interface
48 */ 48 */
49 - public Interface(ConnectPoint connectPoint, Set<IpPrefix> prefixAddress, 49 + public Interface(ConnectPoint connectPoint,
50 + Set<InterfaceIpAddress> ipAddresses,
50 MacAddress macAddress) { 51 MacAddress macAddress) {
51 this.connectPoint = connectPoint; 52 this.connectPoint = connectPoint;
52 - this.ipAddresses = Sets.newHashSet(prefixAddress); 53 + this.ipAddresses = Sets.newHashSet(ipAddresses);
53 this.macAddress = macAddress; 54 this.macAddress = macAddress;
54 } 55 }
55 56
...@@ -60,7 +61,7 @@ public class Interface { ...@@ -60,7 +61,7 @@ public class Interface {
60 */ 61 */
61 public Interface(PortAddresses portAddresses) { 62 public Interface(PortAddresses portAddresses) {
62 connectPoint = portAddresses.connectPoint(); 63 connectPoint = portAddresses.connectPoint();
63 - ipAddresses = Sets.newHashSet(portAddresses.ips()); 64 + ipAddresses = Sets.newHashSet(portAddresses.ipAddresses());
64 macAddress = portAddresses.mac(); 65 macAddress = portAddresses.mac();
65 } 66 }
66 67
...@@ -76,9 +77,9 @@ public class Interface { ...@@ -76,9 +77,9 @@ public class Interface {
76 /** 77 /**
77 * Retrieves the set of IP addresses that are assigned to the interface. 78 * Retrieves the set of IP addresses that are assigned to the interface.
78 * 79 *
79 - * @return the set of IP addresses 80 + * @return the set of interface IP addresses
80 */ 81 */
81 - public Set<IpPrefix> ips() { 82 + public Set<InterfaceIpAddress> ipAddresses() {
82 return ipAddresses; 83 return ipAddresses;
83 } 84 }
84 85
......
...@@ -35,6 +35,7 @@ import org.onlab.onos.net.ConnectPoint; ...@@ -35,6 +35,7 @@ import org.onlab.onos.net.ConnectPoint;
35 import org.onlab.onos.net.DeviceId; 35 import org.onlab.onos.net.DeviceId;
36 import org.onlab.onos.net.PortNumber; 36 import org.onlab.onos.net.PortNumber;
37 import org.onlab.onos.net.host.HostService; 37 import org.onlab.onos.net.host.HostService;
38 +import org.onlab.onos.net.host.InterfaceIpAddress;
38 import org.onlab.onos.net.host.PortAddresses; 39 import org.onlab.onos.net.host.PortAddresses;
39 import org.onlab.onos.sdnip.config.Interface; 40 import org.onlab.onos.sdnip.config.Interface;
40 import org.onlab.packet.IpAddress; 41 import org.onlab.packet.IpAddress;
...@@ -76,20 +77,33 @@ public class HostToInterfaceAdaptorTest { ...@@ -76,20 +77,33 @@ public class HostToInterfaceAdaptorTest {
76 portAddresses = Sets.newHashSet(); 77 portAddresses = Sets.newHashSet();
77 interfaces = Maps.newHashMap(); 78 interfaces = Maps.newHashMap();
78 79
80 + InterfaceIpAddress ia11 =
81 + new InterfaceIpAddress(IpAddress.valueOf("192.168.1.1"),
82 + IpPrefix.valueOf("192.168.1.0/24"));
79 createPortAddressesAndInterface(CP1, 83 createPortAddressesAndInterface(CP1,
80 - Sets.newHashSet(IpPrefix.valueOf("192.168.1.1/24")), 84 + Sets.newHashSet(ia11),
81 MacAddress.valueOf("00:00:00:00:00:01")); 85 MacAddress.valueOf("00:00:00:00:00:01"));
82 86
83 // Two addresses in the same subnet 87 // Two addresses in the same subnet
88 + InterfaceIpAddress ia21 =
89 + new InterfaceIpAddress(IpAddress.valueOf("192.168.2.1"),
90 + IpPrefix.valueOf("192.168.2.0/24"));
91 + InterfaceIpAddress ia22 =
92 + new InterfaceIpAddress(IpAddress.valueOf("192.168.2.2"),
93 + IpPrefix.valueOf("192.168.2.0/24"));
84 createPortAddressesAndInterface(CP2, 94 createPortAddressesAndInterface(CP2,
85 - Sets.newHashSet(IpPrefix.valueOf("192.168.2.1/24"), 95 + Sets.newHashSet(ia21, ia22),
86 - IpPrefix.valueOf("192.168.2.2/24")),
87 MacAddress.valueOf("00:00:00:00:00:02")); 96 MacAddress.valueOf("00:00:00:00:00:02"));
88 97
89 // Two addresses in different subnets 98 // Two addresses in different subnets
99 + InterfaceIpAddress ia31 =
100 + new InterfaceIpAddress(IpAddress.valueOf("192.168.3.1"),
101 + IpPrefix.valueOf("192.168.3.0/24"));
102 + InterfaceIpAddress ia41 =
103 + new InterfaceIpAddress(IpAddress.valueOf("192.168.4.1"),
104 + IpPrefix.valueOf("192.168.4.0/24"));
90 createPortAddressesAndInterface(CP3, 105 createPortAddressesAndInterface(CP3,
91 - Sets.newHashSet(IpPrefix.valueOf("192.168.3.1/24"), 106 + Sets.newHashSet(ia31, ia41),
92 - IpPrefix.valueOf("192.168.4.1/24")),
93 MacAddress.valueOf("00:00:00:00:00:03")); 107 MacAddress.valueOf("00:00:00:00:00:03"));
94 108
95 expect(hostService.getAddressBindings()).andReturn(portAddresses).anyTimes(); 109 expect(hostService.getAddressBindings()).andReturn(portAddresses).anyTimes();
...@@ -104,16 +118,17 @@ public class HostToInterfaceAdaptorTest { ...@@ -104,16 +118,17 @@ public class HostToInterfaceAdaptorTest {
104 * places them in the correct global data stores. 118 * places them in the correct global data stores.
105 * 119 *
106 * @param cp the connect point 120 * @param cp the connect point
107 - * @param ips the set of IP addresses 121 + * @param ipAddresses the set of interface IP addresses
108 * @param mac the MAC address 122 * @param mac the MAC address
109 */ 123 */
110 private void createPortAddressesAndInterface( 124 private void createPortAddressesAndInterface(
111 - ConnectPoint cp, Set<IpPrefix> ips, MacAddress mac) { 125 + ConnectPoint cp, Set<InterfaceIpAddress> ipAddresses,
112 - PortAddresses pa = new PortAddresses(cp, ips, mac); 126 + MacAddress mac) {
127 + PortAddresses pa = new PortAddresses(cp, ipAddresses, mac);
113 portAddresses.add(pa); 128 portAddresses.add(pa);
114 expect(hostService.getAddressBindingsForPort(cp)).andReturn(pa).anyTimes(); 129 expect(hostService.getAddressBindingsForPort(cp)).andReturn(pa).anyTimes();
115 130
116 - Interface intf = new Interface(cp, ips, mac); 131 + Interface intf = new Interface(cp, ipAddresses, mac);
117 interfaces.put(cp, intf); 132 interfaces.put(cp, intf);
118 } 133 }
119 134
......
...@@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; ...@@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector;
31 import org.onlab.onos.net.flow.DefaultTrafficTreatment; 31 import org.onlab.onos.net.flow.DefaultTrafficTreatment;
32 import org.onlab.onos.net.flow.TrafficSelector; 32 import org.onlab.onos.net.flow.TrafficSelector;
33 import org.onlab.onos.net.flow.TrafficTreatment; 33 import org.onlab.onos.net.flow.TrafficTreatment;
34 +import org.onlab.onos.net.host.InterfaceIpAddress;
34 import org.onlab.onos.net.intent.IntentService; 35 import org.onlab.onos.net.intent.IntentService;
35 import org.onlab.onos.net.intent.PointToPointIntent; 36 import org.onlab.onos.net.intent.PointToPointIntent;
36 import org.onlab.onos.sdnip.bgp.BgpConstants; 37 import org.onlab.onos.sdnip.bgp.BgpConstants;
...@@ -175,14 +176,20 @@ public class PeerConnectivityManagerTest { ...@@ -175,14 +176,20 @@ public class PeerConnectivityManagerTest {
175 configuredInterfaces = new HashMap<>(); 176 configuredInterfaces = new HashMap<>();
176 177
177 String interfaceSw1Eth1 = "s1-eth1"; 178 String interfaceSw1Eth1 = "s1-eth1";
179 + InterfaceIpAddress ia1 =
180 + new InterfaceIpAddress(IpAddress.valueOf("192.168.10.1"),
181 + IpPrefix.valueOf("192.168.10.0/24"));
178 Interface intfsw1eth1 = new Interface(s1Eth1, 182 Interface intfsw1eth1 = new Interface(s1Eth1,
179 - Collections.singleton(IpPrefix.valueOf("192.168.10.0/24")), 183 + Collections.singleton(ia1),
180 MacAddress.valueOf("00:00:00:00:00:01")); 184 MacAddress.valueOf("00:00:00:00:00:01"));
181 185
182 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1); 186 configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1);
183 String interfaceSw2Eth1 = "s2-eth1"; 187 String interfaceSw2Eth1 = "s2-eth1";
188 + InterfaceIpAddress ia2 =
189 + new InterfaceIpAddress(IpAddress.valueOf("192.168.20.2"),
190 + IpPrefix.valueOf("192.168.20.0/24"));
184 Interface intfsw2eth1 = new Interface(s2Eth1, 191 Interface intfsw2eth1 = new Interface(s2Eth1,
185 - Collections.singleton(IpPrefix.valueOf("192.168.20.0/24")), 192 + Collections.singleton(ia2),
186 MacAddress.valueOf("00:00:00:00:00:02")); 193 MacAddress.valueOf("00:00:00:00:00:02"));
187 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); 194 configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1);
188 195
......
...@@ -51,6 +51,7 @@ import org.onlab.onos.net.flow.TrafficSelector; ...@@ -51,6 +51,7 @@ import org.onlab.onos.net.flow.TrafficSelector;
51 import org.onlab.onos.net.flow.TrafficTreatment; 51 import org.onlab.onos.net.flow.TrafficTreatment;
52 import org.onlab.onos.net.host.HostListener; 52 import org.onlab.onos.net.host.HostListener;
53 import org.onlab.onos.net.host.HostService; 53 import org.onlab.onos.net.host.HostService;
54 +import org.onlab.onos.net.host.InterfaceIpAddress;
54 import org.onlab.onos.net.intent.IntentService; 55 import org.onlab.onos.net.intent.IntentService;
55 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; 56 import org.onlab.onos.net.intent.MultiPointToSinglePointIntent;
56 import org.onlab.onos.net.provider.ProviderId; 57 import org.onlab.onos.net.provider.ProviderId;
...@@ -150,22 +151,31 @@ public class RouterTest { ...@@ -150,22 +151,31 @@ public class RouterTest {
150 151
151 Set<Interface> interfaces = Sets.newHashSet(); 152 Set<Interface> interfaces = Sets.newHashSet();
152 153
154 + InterfaceIpAddress ia1 =
155 + new InterfaceIpAddress(IpAddress.valueOf("192.168.10.101"),
156 + IpPrefix.valueOf("192.168.10.0/24"));
153 Interface sw1Eth1 = new Interface(SW1_ETH1, 157 Interface sw1Eth1 = new Interface(SW1_ETH1,
154 - Sets.newHashSet(IpPrefix.valueOf("192.168.10.101/24")), 158 + Sets.newHashSet(ia1),
155 MacAddress.valueOf("00:00:00:00:00:01")); 159 MacAddress.valueOf("00:00:00:00:00:01"));
156 160
157 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes(); 161 expect(interfaceService.getInterface(SW1_ETH1)).andReturn(sw1Eth1).anyTimes();
158 interfaces.add(sw1Eth1); 162 interfaces.add(sw1Eth1);
159 163
164 + InterfaceIpAddress ia2 =
165 + new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
166 + IpPrefix.valueOf("192.168.20.0/24"));
160 Interface sw2Eth1 = new Interface(SW2_ETH1, 167 Interface sw2Eth1 = new Interface(SW2_ETH1,
161 - Sets.newHashSet(IpPrefix.valueOf("192.168.20.101/24")), 168 + Sets.newHashSet(ia2),
162 MacAddress.valueOf("00:00:00:00:00:02")); 169 MacAddress.valueOf("00:00:00:00:00:02"));
163 170
164 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes(); 171 expect(interfaceService.getInterface(SW2_ETH1)).andReturn(sw2Eth1).anyTimes();
165 interfaces.add(sw2Eth1); 172 interfaces.add(sw2Eth1);
166 173
174 + InterfaceIpAddress ia3 =
175 + new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
176 + IpPrefix.valueOf("192.168.30.0/24"));
167 Interface sw3Eth1 = new Interface(SW3_ETH1, 177 Interface sw3Eth1 = new Interface(SW3_ETH1,
168 - Sets.newHashSet(IpPrefix.valueOf("192.168.30.101/24")), 178 + Sets.newHashSet(ia3),
169 MacAddress.valueOf("00:00:00:00:00:03")); 179 MacAddress.valueOf("00:00:00:00:00:03"));
170 180
171 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes(); 181 expect(interfaceService.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
......
...@@ -6,7 +6,6 @@ import java.util.Objects; ...@@ -6,7 +6,6 @@ import java.util.Objects;
6 import java.util.Set; 6 import java.util.Set;
7 7
8 import org.onlab.onos.net.ConnectPoint; 8 import org.onlab.onos.net.ConnectPoint;
9 -import org.onlab.packet.IpPrefix;
10 import org.onlab.packet.MacAddress; 9 import org.onlab.packet.MacAddress;
11 10
12 import com.google.common.base.MoreObjects; 11 import com.google.common.base.MoreObjects;
...@@ -17,24 +16,25 @@ import com.google.common.base.MoreObjects; ...@@ -17,24 +16,25 @@ import com.google.common.base.MoreObjects;
17 public class PortAddresses { 16 public class PortAddresses {
18 17
19 private final ConnectPoint connectPoint; 18 private final ConnectPoint connectPoint;
20 - // TODO: Should this be IpAddress or IpPrefix? 19 + private final Set<InterfaceIpAddress> ipAddresses;
21 - private final Set<IpPrefix> ipAddresses;
22 private final MacAddress macAddress; 20 private final MacAddress macAddress;
23 21
24 /** 22 /**
25 - * Constructs a PortAddress object for the given connection point, with a 23 + * Constructs a PortAddresses object for the given connection point, with a
26 * set of IP addresses and a MAC address. 24 * set of IP addresses and a MAC address.
27 * <p/> 25 * <p/>
28 * Both address parameters are optional and can be set to null. 26 * Both address parameters are optional and can be set to null.
29 * 27 *
30 * @param connectPoint the connection point these addresses are for 28 * @param connectPoint the connection point these addresses are for
31 - * @param ips a set of IP addresses 29 + * @param ipAddresses a set of interface IP addresses
32 * @param mac a MAC address 30 * @param mac a MAC address
33 */ 31 */
34 public PortAddresses(ConnectPoint connectPoint, 32 public PortAddresses(ConnectPoint connectPoint,
35 - Set<IpPrefix> ips, MacAddress mac) { 33 + Set<InterfaceIpAddress> ipAddresses, MacAddress mac) {
36 this.connectPoint = connectPoint; 34 this.connectPoint = connectPoint;
37 - this.ipAddresses = (ips == null) ? Collections.<IpPrefix>emptySet() : new HashSet<>(ips); 35 + this.ipAddresses = (ipAddresses == null) ?
36 + Collections.<InterfaceIpAddress>emptySet()
37 + : new HashSet<>(ipAddresses);
38 this.macAddress = mac; 38 this.macAddress = mac;
39 } 39 }
40 40
...@@ -48,11 +48,11 @@ public class PortAddresses { ...@@ -48,11 +48,11 @@ public class PortAddresses {
48 } 48 }
49 49
50 /** 50 /**
51 - * Returns the set of IP addresses. 51 + * Returns the set of interface IP addresses.
52 * 52 *
53 - * @return the IP addresses 53 + * @return the interface IP addresses
54 */ 54 */
55 - public Set<IpPrefix> ips() { 55 + public Set<InterfaceIpAddress> ipAddresses() {
56 return ipAddresses; 56 return ipAddresses;
57 } 57 }
58 58
......
...@@ -22,6 +22,7 @@ import org.onlab.onos.net.flow.TrafficTreatment; ...@@ -22,6 +22,7 @@ import org.onlab.onos.net.flow.TrafficTreatment;
22 import org.onlab.onos.net.flow.instructions.Instruction; 22 import org.onlab.onos.net.flow.instructions.Instruction;
23 import org.onlab.onos.net.flow.instructions.Instructions; 23 import org.onlab.onos.net.flow.instructions.Instructions;
24 import org.onlab.onos.net.host.HostProvider; 24 import org.onlab.onos.net.host.HostProvider;
25 +import org.onlab.onos.net.host.InterfaceIpAddress;
25 import org.onlab.onos.net.host.PortAddresses; 26 import org.onlab.onos.net.host.PortAddresses;
26 import org.onlab.onos.net.packet.DefaultOutboundPacket; 27 import org.onlab.onos.net.packet.DefaultOutboundPacket;
27 import org.onlab.onos.net.packet.OutboundPacket; 28 import org.onlab.onos.net.packet.OutboundPacket;
...@@ -161,12 +162,13 @@ public class HostMonitor implements TimerTask { ...@@ -161,12 +162,13 @@ public class HostMonitor implements TimerTask {
161 for (Device device : deviceService.getDevices()) { 162 for (Device device : deviceService.getDevices()) {
162 for (Port port : deviceService.getPorts(device.id())) { 163 for (Port port : deviceService.getPorts(device.id())) {
163 ConnectPoint cp = new ConnectPoint(device.id(), port.number()); 164 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
164 - PortAddresses addresses = hostManager.getAddressBindingsForPort(cp); 165 + PortAddresses portAddresses =
166 + hostManager.getAddressBindingsForPort(cp);
165 167
166 - for (IpPrefix prefix : addresses.ips()) { 168 + for (InterfaceIpAddress ia : portAddresses.ipAddresses()) {
167 - if (prefix.contains(targetIp)) { 169 + if (ia.subnetAddress().contains(targetIp)) {
168 sendProbe(device.id(), port, targetIp, 170 sendProbe(device.id(), port, targetIp,
169 - prefix.toIpAddress(), addresses.mac()); 171 + ia.ipAddress(), portAddresses.mac());
170 } 172 }
171 } 173 }
172 } 174 }
......
...@@ -5,7 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -5,7 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
5 import static org.slf4j.LoggerFactory.getLogger; 5 import static org.slf4j.LoggerFactory.getLogger;
6 6
7 import java.nio.ByteBuffer; 7 import java.nio.ByteBuffer;
8 -import java.util.Collections;
9 import java.util.List; 8 import java.util.List;
10 import java.util.Map.Entry; 9 import java.util.Map.Entry;
11 import java.util.Set; 10 import java.util.Set;
...@@ -29,6 +28,7 @@ import org.onlab.onos.net.device.DeviceService; ...@@ -29,6 +28,7 @@ import org.onlab.onos.net.device.DeviceService;
29 import org.onlab.onos.net.flow.DefaultTrafficTreatment; 28 import org.onlab.onos.net.flow.DefaultTrafficTreatment;
30 import org.onlab.onos.net.flow.TrafficTreatment; 29 import org.onlab.onos.net.flow.TrafficTreatment;
31 import org.onlab.onos.net.host.HostService; 30 import org.onlab.onos.net.host.HostService;
31 +import org.onlab.onos.net.host.InterfaceIpAddress;
32 import org.onlab.onos.net.host.PortAddresses; 32 import org.onlab.onos.net.host.PortAddresses;
33 import org.onlab.onos.net.link.LinkEvent; 33 import org.onlab.onos.net.link.LinkEvent;
34 import org.onlab.onos.net.link.LinkListener; 34 import org.onlab.onos.net.link.LinkListener;
...@@ -114,35 +114,37 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -114,35 +114,37 @@ public class ProxyArpManager implements ProxyArpService {
114 checkArgument(arp.getOpCode() == ARP.OP_REQUEST, NOT_ARP_REQUEST); 114 checkArgument(arp.getOpCode() == ARP.OP_REQUEST, NOT_ARP_REQUEST);
115 checkNotNull(inPort); 115 checkNotNull(inPort);
116 116
117 - // If the source address matches one of our external addresses
118 - // it could be a request from an internal host to an external
119 - // address. Forward it over to the correct port.
120 - IpAddress source = IpAddress.valueOf(arp.getSenderProtocolAddress());
121 - PortAddresses sourceAddresses = findOutsidePortInSubnet(source);
122 - if (sourceAddresses != null && !isOutsidePort(inPort)) {
123 - for (IpPrefix subnet : sourceAddresses.ips()) {
124 - if (subnet.toIpAddress().equals(source)) {
125 - sendTo(eth, sourceAddresses.connectPoint());
126 - return;
127 - }
128 - }
129 - }
130 -
131 // If the request came from outside the network, only reply if it was 117 // If the request came from outside the network, only reply if it was
132 // for one of our external addresses. 118 // for one of our external addresses.
133 if (isOutsidePort(inPort)) { 119 if (isOutsidePort(inPort)) {
134 - IpAddress target = IpAddress.valueOf(arp.getTargetProtocolAddress()); 120 + IpAddress target =
135 - PortAddresses addresses = hostService.getAddressBindingsForPort(inPort); 121 + IpAddress.valueOf(arp.getTargetProtocolAddress());
136 - 122 + PortAddresses addresses =
137 - for (IpPrefix interfaceAddress : addresses.ips()) { 123 + hostService.getAddressBindingsForPort(inPort);
138 - if (interfaceAddress.toIpAddress().equals(target)) { 124 +
139 - Ethernet arpReply = buildArpReply(interfaceAddress, 125 + for (InterfaceIpAddress ia : addresses.ipAddresses()) {
140 - addresses.mac(), eth); 126 + if (ia.ipAddress().equals(target)) {
127 + Ethernet arpReply =
128 + buildArpReply(ia.ipAddress(), addresses.mac(), eth);
141 sendTo(arpReply, inPort); 129 sendTo(arpReply, inPort);
142 } 130 }
143 } 131 }
144 -
145 return; 132 return;
133 + } else {
134 + // If the source address matches one of our external addresses
135 + // it could be a request from an internal host to an external
136 + // address. Forward it over to the correct port.
137 + IpAddress source =
138 + IpAddress.valueOf(arp.getSenderProtocolAddress());
139 + PortAddresses sourceAddresses = findPortInSubnet(source);
140 + if (sourceAddresses != null) {
141 + for (InterfaceIpAddress ia : sourceAddresses.ipAddresses()) {
142 + if (ia.ipAddress().equals(source)) {
143 + sendTo(eth, sourceAddresses.connectPoint());
144 + return;
145 + }
146 + }
147 + }
146 } 148 }
147 149
148 // Continue with normal proxy ARP case 150 // Continue with normal proxy ARP case
...@@ -168,8 +170,9 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -168,8 +170,9 @@ public class ProxyArpManager implements ProxyArpService {
168 } 170 }
169 171
170 // TODO find the correct IP address 172 // TODO find the correct IP address
171 - Ethernet arpReply = buildArpReply(dst.ipAddresses().iterator().next(), 173 + IpAddress ipAddress =
172 - dst.mac(), eth); 174 + dst.ipAddresses().iterator().next().toIpAddress();
175 + Ethernet arpReply = buildArpReply(ipAddress, dst.mac(), eth);
173 // TODO: check send status with host service. 176 // TODO: check send status with host service.
174 sendTo(arpReply, src.location()); 177 sendTo(arpReply, src.location());
175 } 178 }
...@@ -199,16 +202,14 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -199,16 +202,14 @@ public class ProxyArpManager implements ProxyArpService {
199 * Finds the port with an address in the subnet of the target address, if 202 * Finds the port with an address in the subnet of the target address, if
200 * one exists. 203 * one exists.
201 * 204 *
202 - * @param target the target address to find a matching external port for 205 + * @param target the target address to find a matching port for
203 - * @return a PortAddresses object containing the external addresses if one 206 + * @return a PortAddresses object if one was found, otherwise null
204 - * was found, otherwise null.
205 */ 207 */
206 - private PortAddresses findOutsidePortInSubnet(IpAddress target) { 208 + private PortAddresses findPortInSubnet(IpAddress target) {
207 for (PortAddresses addresses : hostService.getAddressBindings()) { 209 for (PortAddresses addresses : hostService.getAddressBindings()) {
208 - for (IpPrefix prefix : addresses.ips()) { 210 + for (InterfaceIpAddress ia : addresses.ipAddresses()) {
209 - if (prefix.contains(target)) { 211 + if (ia.subnetAddress().contains(target)) {
210 - return new PortAddresses(addresses.connectPoint(), 212 + return addresses;
211 - Collections.singleton(prefix), addresses.mac());
212 } 213 }
213 } 214 }
214 } 215 }
...@@ -223,7 +224,11 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -223,7 +224,11 @@ public class ProxyArpManager implements ProxyArpService {
223 * @return true if the port is an outside-facing port, otherwise false 224 * @return true if the port is an outside-facing port, otherwise false
224 */ 225 */
225 private boolean isOutsidePort(ConnectPoint port) { 226 private boolean isOutsidePort(ConnectPoint port) {
226 - return !hostService.getAddressBindingsForPort(port).ips().isEmpty(); 227 + //
228 + // TODO: Is this sufficient to identify outside-facing ports: just
229 + // having IP addresses on a port?
230 + //
231 + return !hostService.getAddressBindingsForPort(port).ipAddresses().isEmpty();
227 } 232 }
228 233
229 @Override 234 @Override
...@@ -335,7 +340,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -335,7 +340,7 @@ public class ProxyArpManager implements ProxyArpService {
335 * @param request the ARP request we got 340 * @param request the ARP request we got
336 * @return an Ethernet frame containing the ARP reply 341 * @return an Ethernet frame containing the ARP reply
337 */ 342 */
338 - private Ethernet buildArpReply(IpPrefix srcIp, MacAddress srcMac, 343 + private Ethernet buildArpReply(IpAddress srcIp, MacAddress srcMac,
339 Ethernet request) { 344 Ethernet request) {
340 345
341 Ethernet eth = new Ethernet(); 346 Ethernet eth = new Ethernet();
......
...@@ -31,10 +31,12 @@ import org.onlab.onos.net.host.HostListener; ...@@ -31,10 +31,12 @@ import org.onlab.onos.net.host.HostListener;
31 import org.onlab.onos.net.host.HostProvider; 31 import org.onlab.onos.net.host.HostProvider;
32 import org.onlab.onos.net.host.HostProviderRegistry; 32 import org.onlab.onos.net.host.HostProviderRegistry;
33 import org.onlab.onos.net.host.HostProviderService; 33 import org.onlab.onos.net.host.HostProviderService;
34 +import org.onlab.onos.net.host.InterfaceIpAddress;
34 import org.onlab.onos.net.host.PortAddresses; 35 import org.onlab.onos.net.host.PortAddresses;
35 import org.onlab.onos.net.provider.AbstractProvider; 36 import org.onlab.onos.net.provider.AbstractProvider;
36 import org.onlab.onos.net.provider.ProviderId; 37 import org.onlab.onos.net.provider.ProviderId;
37 import org.onlab.onos.store.trivial.impl.SimpleHostStore; 38 import org.onlab.onos.store.trivial.impl.SimpleHostStore;
39 +import org.onlab.packet.IpAddress;
38 import org.onlab.packet.IpPrefix; 40 import org.onlab.packet.IpPrefix;
39 import org.onlab.packet.MacAddress; 41 import org.onlab.packet.MacAddress;
40 import org.onlab.packet.VlanId; 42 import org.onlab.packet.VlanId;
...@@ -68,9 +70,15 @@ public class HostManagerTest { ...@@ -68,9 +70,15 @@ public class HostManagerTest {
68 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1); 70 private static final ConnectPoint CP1 = new ConnectPoint(DID1, P1);
69 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2); 71 private static final ConnectPoint CP2 = new ConnectPoint(DID2, P2);
70 72
71 - private static final IpPrefix PREFIX1 = IpPrefix.valueOf("10.0.1.0/24"); 73 + private static final InterfaceIpAddress IA1 =
72 - private static final IpPrefix PREFIX2 = IpPrefix.valueOf("10.1.0.0/16"); 74 + new InterfaceIpAddress(IpAddress.valueOf("10.1.1.1"),
73 - private static final IpPrefix PREFIX3 = IpPrefix.valueOf("5.8.2.0/23"); 75 + IpPrefix.valueOf("10.1.1.0/24"));
76 + private static final InterfaceIpAddress IA2 =
77 + new InterfaceIpAddress(IpAddress.valueOf("10.2.2.2"),
78 + IpPrefix.valueOf("10.2.0.0/16"));
79 + private static final InterfaceIpAddress IA3 =
80 + new InterfaceIpAddress(IpAddress.valueOf("10.3.3.3"),
81 + IpPrefix.valueOf("10.3.3.0/24"));
74 82
75 private HostManager mgr; 83 private HostManager mgr;
76 84
...@@ -207,23 +215,24 @@ public class HostManagerTest { ...@@ -207,23 +215,24 @@ public class HostManagerTest {
207 215
208 @Test 216 @Test
209 public void bindAddressesToPort() { 217 public void bindAddressesToPort() {
210 - PortAddresses add1 = new PortAddresses(CP1, 218 + PortAddresses add1 =
211 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 219 + new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1);
212 220
213 mgr.bindAddressesToPort(add1); 221 mgr.bindAddressesToPort(add1);
214 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 222 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
215 223
216 - assertTrue(add1.ips().equals(storedAddresses.ips())); 224 + assertTrue(add1.ipAddresses().equals(storedAddresses.ipAddresses()));
217 assertTrue(add1.mac().equals(storedAddresses.mac())); 225 assertTrue(add1.mac().equals(storedAddresses.mac()));
218 226
219 // Add some more addresses and check that they're added correctly 227 // Add some more addresses and check that they're added correctly
220 - PortAddresses add2 = new PortAddresses(CP1, Sets.newHashSet(PREFIX3), null); 228 + PortAddresses add2 =
229 + new PortAddresses(CP1, Sets.newHashSet(IA3), null);
221 230
222 mgr.bindAddressesToPort(add2); 231 mgr.bindAddressesToPort(add2);
223 storedAddresses = mgr.getAddressBindingsForPort(CP1); 232 storedAddresses = mgr.getAddressBindingsForPort(CP1);
224 233
225 - assertTrue(storedAddresses.ips().equals( 234 + assertTrue(storedAddresses.ipAddresses().equals(
226 - Sets.newHashSet(PREFIX1, PREFIX2, PREFIX3))); 235 + Sets.newHashSet(IA1, IA2, IA3)));
227 assertTrue(storedAddresses.mac().equals(MAC1)); 236 assertTrue(storedAddresses.mac().equals(MAC1));
228 237
229 PortAddresses add3 = new PortAddresses(CP1, null, MAC2); 238 PortAddresses add3 = new PortAddresses(CP1, null, MAC2);
...@@ -231,29 +240,29 @@ public class HostManagerTest { ...@@ -231,29 +240,29 @@ public class HostManagerTest {
231 mgr.bindAddressesToPort(add3); 240 mgr.bindAddressesToPort(add3);
232 storedAddresses = mgr.getAddressBindingsForPort(CP1); 241 storedAddresses = mgr.getAddressBindingsForPort(CP1);
233 242
234 - assertTrue(storedAddresses.ips().equals( 243 + assertTrue(storedAddresses.ipAddresses().equals(
235 - Sets.newHashSet(PREFIX1, PREFIX2, PREFIX3))); 244 + Sets.newHashSet(IA1, IA2, IA3)));
236 assertTrue(storedAddresses.mac().equals(MAC2)); 245 assertTrue(storedAddresses.mac().equals(MAC2));
237 } 246 }
238 247
239 @Test 248 @Test
240 public void unbindAddressesFromPort() { 249 public void unbindAddressesFromPort() {
241 - PortAddresses add1 = new PortAddresses(CP1, 250 + PortAddresses add1 =
242 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 251 + new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1);
243 252
244 mgr.bindAddressesToPort(add1); 253 mgr.bindAddressesToPort(add1);
245 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 254 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
246 255
247 - assertTrue(storedAddresses.ips().size() == 2); 256 + assertTrue(storedAddresses.ipAddresses().size() == 2);
248 assertNotNull(storedAddresses.mac()); 257 assertNotNull(storedAddresses.mac());
249 258
250 - PortAddresses rem1 = new PortAddresses(CP1, 259 + PortAddresses rem1 =
251 - Sets.newHashSet(PREFIX1), null); 260 + new PortAddresses(CP1, Sets.newHashSet(IA1), null);
252 261
253 mgr.unbindAddressesFromPort(rem1); 262 mgr.unbindAddressesFromPort(rem1);
254 storedAddresses = mgr.getAddressBindingsForPort(CP1); 263 storedAddresses = mgr.getAddressBindingsForPort(CP1);
255 264
256 - assertTrue(storedAddresses.ips().equals(Sets.newHashSet(PREFIX2))); 265 + assertTrue(storedAddresses.ipAddresses().equals(Sets.newHashSet(IA2)));
257 assertTrue(storedAddresses.mac().equals(MAC1)); 266 assertTrue(storedAddresses.mac().equals(MAC1));
258 267
259 PortAddresses rem2 = new PortAddresses(CP1, null, MAC1); 268 PortAddresses rem2 = new PortAddresses(CP1, null, MAC1);
...@@ -261,47 +270,48 @@ public class HostManagerTest { ...@@ -261,47 +270,48 @@ public class HostManagerTest {
261 mgr.unbindAddressesFromPort(rem2); 270 mgr.unbindAddressesFromPort(rem2);
262 storedAddresses = mgr.getAddressBindingsForPort(CP1); 271 storedAddresses = mgr.getAddressBindingsForPort(CP1);
263 272
264 - assertTrue(storedAddresses.ips().equals(Sets.newHashSet(PREFIX2))); 273 + assertTrue(storedAddresses.ipAddresses().equals(Sets.newHashSet(IA2)));
265 assertNull(storedAddresses.mac()); 274 assertNull(storedAddresses.mac());
266 275
267 - PortAddresses rem3 = new PortAddresses(CP1, 276 + PortAddresses rem3 =
268 - Sets.newHashSet(PREFIX2), MAC1); 277 + new PortAddresses(CP1, Sets.newHashSet(IA2), MAC1);
269 278
270 mgr.unbindAddressesFromPort(rem3); 279 mgr.unbindAddressesFromPort(rem3);
271 storedAddresses = mgr.getAddressBindingsForPort(CP1); 280 storedAddresses = mgr.getAddressBindingsForPort(CP1);
272 281
273 - assertTrue(storedAddresses.ips().isEmpty()); 282 + assertTrue(storedAddresses.ipAddresses().isEmpty());
274 assertNull(storedAddresses.mac()); 283 assertNull(storedAddresses.mac());
275 } 284 }
276 285
277 @Test 286 @Test
278 public void clearAddresses() { 287 public void clearAddresses() {
279 - PortAddresses add1 = new PortAddresses(CP1, 288 + PortAddresses add1 =
280 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 289 + new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1);
281 290
282 mgr.bindAddressesToPort(add1); 291 mgr.bindAddressesToPort(add1);
283 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 292 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
284 293
285 - assertTrue(storedAddresses.ips().size() == 2); 294 + assertTrue(storedAddresses.ipAddresses().size() == 2);
286 assertNotNull(storedAddresses.mac()); 295 assertNotNull(storedAddresses.mac());
287 296
288 mgr.clearAddresses(CP1); 297 mgr.clearAddresses(CP1);
289 storedAddresses = mgr.getAddressBindingsForPort(CP1); 298 storedAddresses = mgr.getAddressBindingsForPort(CP1);
290 299
291 - assertTrue(storedAddresses.ips().isEmpty()); 300 + assertTrue(storedAddresses.ipAddresses().isEmpty());
292 assertNull(storedAddresses.mac()); 301 assertNull(storedAddresses.mac());
293 } 302 }
294 303
295 @Test 304 @Test
296 public void getAddressBindingsForPort() { 305 public void getAddressBindingsForPort() {
297 - PortAddresses add1 = new PortAddresses(CP1, 306 + PortAddresses add1 =
298 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 307 + new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1);
299 308
300 mgr.bindAddressesToPort(add1); 309 mgr.bindAddressesToPort(add1);
301 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 310 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
302 311
303 assertTrue(storedAddresses.connectPoint().equals(CP1)); 312 assertTrue(storedAddresses.connectPoint().equals(CP1));
304 - assertTrue(storedAddresses.ips().equals(Sets.newHashSet(PREFIX1, PREFIX2))); 313 + assertTrue(storedAddresses.ipAddresses().equals(
314 + Sets.newHashSet(IA1, IA2)));
305 assertTrue(storedAddresses.mac().equals(MAC1)); 315 assertTrue(storedAddresses.mac().equals(MAC1));
306 } 316 }
307 317
...@@ -311,8 +321,8 @@ public class HostManagerTest { ...@@ -311,8 +321,8 @@ public class HostManagerTest {
311 321
312 assertTrue(storedAddresses.isEmpty()); 322 assertTrue(storedAddresses.isEmpty());
313 323
314 - PortAddresses add1 = new PortAddresses(CP1, 324 + PortAddresses add1 =
315 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 325 + new PortAddresses(CP1, Sets.newHashSet(IA1, IA2), MAC1);
316 326
317 mgr.bindAddressesToPort(add1); 327 mgr.bindAddressesToPort(add1);
318 328
...@@ -320,8 +330,8 @@ public class HostManagerTest { ...@@ -320,8 +330,8 @@ public class HostManagerTest {
320 330
321 assertTrue(storedAddresses.size() == 1); 331 assertTrue(storedAddresses.size() == 1);
322 332
323 - PortAddresses add2 = new PortAddresses(CP2, 333 + PortAddresses add2 =
324 - Sets.newHashSet(PREFIX3), MAC2); 334 + new PortAddresses(CP2, Sets.newHashSet(IA3), MAC2);
325 335
326 mgr.bindAddressesToPort(add2); 336 mgr.bindAddressesToPort(add2);
327 337
......
...@@ -28,6 +28,7 @@ import org.onlab.onos.net.device.DeviceService; ...@@ -28,6 +28,7 @@ import org.onlab.onos.net.device.DeviceService;
28 import org.onlab.onos.net.flow.instructions.Instruction; 28 import org.onlab.onos.net.flow.instructions.Instruction;
29 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; 29 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
30 import org.onlab.onos.net.host.HostProvider; 30 import org.onlab.onos.net.host.HostProvider;
31 +import org.onlab.onos.net.host.InterfaceIpAddress;
31 import org.onlab.onos.net.host.PortAddresses; 32 import org.onlab.onos.net.host.PortAddresses;
32 import org.onlab.onos.net.packet.OutboundPacket; 33 import org.onlab.onos.net.packet.OutboundPacket;
33 import org.onlab.onos.net.packet.PacketProcessor; 34 import org.onlab.onos.net.packet.PacketProcessor;
...@@ -48,7 +49,10 @@ public class HostMonitorTest { ...@@ -48,7 +49,10 @@ public class HostMonitorTest {
48 private IpAddress targetIpAddress = IpAddress.valueOf("10.0.0.1"); 49 private IpAddress targetIpAddress = IpAddress.valueOf("10.0.0.1");
49 private IpPrefix targetIpPrefix = IpPrefix.valueOf(targetIpAddress.toOctets()); 50 private IpPrefix targetIpPrefix = IpPrefix.valueOf(targetIpAddress.toOctets());
50 51
51 - private IpPrefix sourcePrefix = IpPrefix.valueOf("10.0.0.99/24"); 52 + private static final IpAddress SOURCE_ADDR =
53 + IpAddress.valueOf("10.0.0.99");
54 + private static final InterfaceIpAddress IA1 =
55 + new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24"));
52 private MacAddress sourceMac = MacAddress.valueOf(1L); 56 private MacAddress sourceMac = MacAddress.valueOf(1L);
53 57
54 private HostMonitor hostMonitor; 58 private HostMonitor hostMonitor;
...@@ -108,8 +112,8 @@ public class HostMonitorTest { ...@@ -108,8 +112,8 @@ public class HostMonitorTest {
108 deviceService.addDevice(device, Collections.singleton(port)); 112 deviceService.addDevice(device, Collections.singleton(port));
109 113
110 ConnectPoint cp = new ConnectPoint(devId, portNum); 114 ConnectPoint cp = new ConnectPoint(devId, portNum);
111 - PortAddresses pa = new PortAddresses(cp, Collections.singleton(sourcePrefix), 115 + PortAddresses pa =
112 - sourceMac); 116 + new PortAddresses(cp, Collections.singleton(IA1), sourceMac);
113 117
114 expect(hostManager.getHostsByIp(targetIpPrefix)) 118 expect(hostManager.getHostsByIp(targetIpPrefix))
115 .andReturn(Collections.<Host>emptySet()).anyTimes(); 119 .andReturn(Collections.<Host>emptySet()).anyTimes();
...@@ -143,7 +147,8 @@ public class HostMonitorTest { ...@@ -143,7 +147,8 @@ public class HostMonitorTest {
143 Ethernet eth = new Ethernet(); 147 Ethernet eth = new Ethernet();
144 eth.deserialize(packet.data().array(), 0, packet.data().array().length); 148 eth.deserialize(packet.data().array(), 0, packet.data().array().length);
145 ARP arp = (ARP) eth.getPayload(); 149 ARP arp = (ARP) eth.getPayload();
146 - assertTrue(Arrays.equals(arp.getSenderProtocolAddress(), sourcePrefix.toOctets())); 150 + assertTrue(Arrays.equals(arp.getSenderProtocolAddress(),
151 + SOURCE_ADDR.toOctets()));
147 assertTrue(Arrays.equals(arp.getSenderHardwareAddress(), sourceMac.toBytes())); 152 assertTrue(Arrays.equals(arp.getSenderHardwareAddress(), sourceMac.toBytes()));
148 assertTrue(Arrays.equals(arp.getTargetProtocolAddress(), targetIpPrefix.toOctets())); 153 assertTrue(Arrays.equals(arp.getTargetProtocolAddress(), targetIpPrefix.toOctets()));
149 } 154 }
......
...@@ -32,6 +32,7 @@ import org.onlab.onos.net.device.DeviceService; ...@@ -32,6 +32,7 @@ import org.onlab.onos.net.device.DeviceService;
32 import org.onlab.onos.net.flow.instructions.Instruction; 32 import org.onlab.onos.net.flow.instructions.Instruction;
33 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; 33 import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
34 import org.onlab.onos.net.host.HostService; 34 import org.onlab.onos.net.host.HostService;
35 +import org.onlab.onos.net.host.InterfaceIpAddress;
35 import org.onlab.onos.net.host.PortAddresses; 36 import org.onlab.onos.net.host.PortAddresses;
36 import org.onlab.onos.net.link.LinkListener; 37 import org.onlab.onos.net.link.LinkListener;
37 import org.onlab.onos.net.link.LinkService; 38 import org.onlab.onos.net.link.LinkService;
...@@ -41,6 +42,7 @@ import org.onlab.onos.net.packet.PacketService; ...@@ -41,6 +42,7 @@ import org.onlab.onos.net.packet.PacketService;
41 import org.onlab.onos.net.provider.ProviderId; 42 import org.onlab.onos.net.provider.ProviderId;
42 import org.onlab.packet.ARP; 43 import org.onlab.packet.ARP;
43 import org.onlab.packet.Ethernet; 44 import org.onlab.packet.Ethernet;
45 +import org.onlab.packet.IpAddress;
44 import org.onlab.packet.IpPrefix; 46 import org.onlab.packet.IpPrefix;
45 import org.onlab.packet.MacAddress; 47 import org.onlab.packet.MacAddress;
46 import org.onlab.packet.VlanId; 48 import org.onlab.packet.VlanId;
...@@ -186,10 +188,15 @@ public class ProxyArpManagerTest { ...@@ -186,10 +188,15 @@ public class ProxyArpManagerTest {
186 188
187 for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { 189 for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) {
188 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); 190 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
189 - IpPrefix prefix1 = IpPrefix.valueOf("10.0." + (2 * i - 1) + ".1/24"); 191 + IpPrefix prefix1 = IpPrefix.valueOf("10.0." + (2 * i - 1) + ".0/24");
190 - IpPrefix prefix2 = IpPrefix.valueOf("10.0." + (2 * i) + ".1/24"); 192 + IpAddress addr1 = IpAddress.valueOf("10.0." + (2 * i - 1) + ".1");
191 - PortAddresses pa = new PortAddresses(cp, 193 + IpPrefix prefix2 = IpPrefix.valueOf("10.0." + (2 * i) + ".0/24");
192 - Sets.newHashSet(prefix1, prefix2), MacAddress.valueOf(i)); 194 + IpAddress addr2 = IpAddress.valueOf("10.0." + (2 * i) + ".1");
195 + InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1);
196 + InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2);
197 + PortAddresses pa =
198 + new PortAddresses(cp, Sets.newHashSet(ia1, ia2),
199 + MacAddress.valueOf(i));
193 addresses.add(pa); 200 addresses.add(pa);
194 201
195 expect(hostService.getAddressBindingsForPort(cp)) 202 expect(hostService.getAddressBindingsForPort(cp))
......
...@@ -30,6 +30,7 @@ import org.onlab.onos.net.host.HostDescription; ...@@ -30,6 +30,7 @@ import org.onlab.onos.net.host.HostDescription;
30 import org.onlab.onos.net.host.HostEvent; 30 import org.onlab.onos.net.host.HostEvent;
31 import org.onlab.onos.net.host.HostStore; 31 import org.onlab.onos.net.host.HostStore;
32 import org.onlab.onos.net.host.HostStoreDelegate; 32 import org.onlab.onos.net.host.HostStoreDelegate;
33 +import org.onlab.onos.net.host.InterfaceIpAddress;
33 import org.onlab.onos.net.host.PortAddresses; 34 import org.onlab.onos.net.host.PortAddresses;
34 import org.onlab.onos.net.provider.ProviderId; 35 import org.onlab.onos.net.provider.ProviderId;
35 import org.onlab.onos.store.AbstractStore; 36 import org.onlab.onos.store.AbstractStore;
...@@ -332,8 +333,9 @@ public class GossipHostStore ...@@ -332,8 +333,9 @@ public class GossipHostStore
332 if (existing == null) { 333 if (existing == null) {
333 portAddresses.put(addresses.connectPoint(), addresses); 334 portAddresses.put(addresses.connectPoint(), addresses);
334 } else { 335 } else {
335 - Set<IpPrefix> union = Sets.union(existing.ips(), addresses.ips()) 336 + Set<InterfaceIpAddress> union =
336 - .immutableCopy(); 337 + Sets.union(existing.ipAddresses(),
338 + addresses.ipAddresses()).immutableCopy();
337 339
338 MacAddress newMac = (addresses.mac() == null) ? existing.mac() 340 MacAddress newMac = (addresses.mac() == null) ? existing.mac()
339 : addresses.mac(); 341 : addresses.mac();
...@@ -351,8 +353,9 @@ public class GossipHostStore ...@@ -351,8 +353,9 @@ public class GossipHostStore
351 synchronized (portAddresses) { 353 synchronized (portAddresses) {
352 PortAddresses existing = portAddresses.get(addresses.connectPoint()); 354 PortAddresses existing = portAddresses.get(addresses.connectPoint());
353 if (existing != null) { 355 if (existing != null) {
354 - Set<IpPrefix> difference = 356 + Set<InterfaceIpAddress> difference =
355 - Sets.difference(existing.ips(), addresses.ips()).immutableCopy(); 357 + Sets.difference(existing.ipAddresses(),
358 + addresses.ipAddresses()).immutableCopy();
356 359
357 // If they removed the existing mac, set the new mac to null. 360 // If they removed the existing mac, set the new mac to null.
358 // Otherwise, keep the existing mac. 361 // Otherwise, keep the existing mac.
......
...@@ -19,6 +19,7 @@ import org.onlab.onos.net.host.HostDescription; ...@@ -19,6 +19,7 @@ import org.onlab.onos.net.host.HostDescription;
19 import org.onlab.onos.net.host.HostEvent; 19 import org.onlab.onos.net.host.HostEvent;
20 import org.onlab.onos.net.host.HostStore; 20 import org.onlab.onos.net.host.HostStore;
21 import org.onlab.onos.net.host.HostStoreDelegate; 21 import org.onlab.onos.net.host.HostStoreDelegate;
22 +import org.onlab.onos.net.host.InterfaceIpAddress;
22 import org.onlab.onos.net.host.PortAddresses; 23 import org.onlab.onos.net.host.PortAddresses;
23 import org.onlab.onos.net.provider.ProviderId; 24 import org.onlab.onos.net.provider.ProviderId;
24 import org.onlab.onos.store.AbstractStore; 25 import org.onlab.onos.store.AbstractStore;
...@@ -202,8 +203,9 @@ public class SimpleHostStore ...@@ -202,8 +203,9 @@ public class SimpleHostStore
202 if (existing == null) { 203 if (existing == null) {
203 portAddresses.put(addresses.connectPoint(), addresses); 204 portAddresses.put(addresses.connectPoint(), addresses);
204 } else { 205 } else {
205 - Set<IpPrefix> union = Sets.union(existing.ips(), addresses.ips()) 206 + Set<InterfaceIpAddress> union =
206 - .immutableCopy(); 207 + Sets.union(existing.ipAddresses(),
208 + addresses.ipAddresses()).immutableCopy();
207 209
208 MacAddress newMac = (addresses.mac() == null) ? existing.mac() 210 MacAddress newMac = (addresses.mac() == null) ? existing.mac()
209 : addresses.mac(); 211 : addresses.mac();
...@@ -221,8 +223,9 @@ public class SimpleHostStore ...@@ -221,8 +223,9 @@ public class SimpleHostStore
221 synchronized (portAddresses) { 223 synchronized (portAddresses) {
222 PortAddresses existing = portAddresses.get(addresses.connectPoint()); 224 PortAddresses existing = portAddresses.get(addresses.connectPoint());
223 if (existing != null) { 225 if (existing != null) {
224 - Set<IpPrefix> difference = 226 + Set<InterfaceIpAddress> difference =
225 - Sets.difference(existing.ips(), addresses.ips()).immutableCopy(); 227 + Sets.difference(existing.ipAddresses(),
228 + addresses.ipAddresses()).immutableCopy();
226 229
227 // If they removed the existing mac, set the new mac to null. 230 // If they removed the existing mac, set the new mac to null.
228 // Otherwise, keep the existing mac. 231 // Otherwise, keep the existing mac.
......