Jonathan Hart

Changed PortAddress API to allow multiple IP addresses per port

...@@ -4,8 +4,6 @@ import java.util.Set; ...@@ -4,8 +4,6 @@ import java.util.Set;
4 4
5 import org.onlab.onos.net.ConnectPoint; 5 import org.onlab.onos.net.ConnectPoint;
6 import org.onlab.onos.net.HostId; 6 import org.onlab.onos.net.HostId;
7 -import org.onlab.packet.IpAddress;
8 -import org.onlab.packet.MacAddress;
9 7
10 /** 8 /**
11 * Service for administering the inventory of end-station hosts. 9 * Service for administering the inventory of end-station hosts.
...@@ -20,26 +18,34 @@ public interface HostAdminService { ...@@ -20,26 +18,34 @@ public interface HostAdminService {
20 void removeHost(HostId hostId); 18 void removeHost(HostId hostId);
21 19
22 /** 20 /**
23 - * Binds an IP address and optional MAC address to the given connection 21 + * Binds IP and MAC addresses to the given connection point.
24 - * point.
25 * <p/> 22 * <p/>
26 - * This method will overwrite any previously held address information for 23 + * The addresses are added to the set of addresses already bound to the
27 - * the connection point. 24 + * connection point. If any of the fields in addresses is null, no change
25 + * is made to the corresponding addresses in the store.
26 + * {@link #unbindAddressesFromPort(PortAddresses)} must be use to unbind
27 + * addresses that have previously been bound.
28 + *
29 + * @param addresses address object containing addresses to add and the port
30 + * to add them to
31 + */
32 + void bindAddressesToPort(PortAddresses addresses);
33 +
34 + /**
35 + * Removes the addresses contained in the given PortAddresses object from
36 + * the set of addresses bound to the port.
28 * 37 *
29 - * @param ip the IP address to bind to the connection point. This parameter 38 + * @param portAddresses set of addresses to remove and port to remove them
30 - * is mandatory and cannot be null. 39 + * from
31 - * @param mac the optional MAC address to bind to the connection point. Can
32 - * be set to null if no MAC address needs to be bound.
33 - * @param connectPoint the connection point to bind the addresses to
34 */ 40 */
35 - void bindAddressesToPort(IpAddress ip, MacAddress mac, ConnectPoint connectPoint); 41 + void unbindAddressesFromPort(PortAddresses portAddresses);
36 42
37 /** 43 /**
38 * Removes all address information for the given connection point. 44 * Removes all address information for the given connection point.
39 * 45 *
40 * @param connectPoint the connection point to remove address information 46 * @param connectPoint the connection point to remove address information
41 */ 47 */
42 - void unbindAddressesFromPort(ConnectPoint connectPoint); 48 + void clearAddresses(ConnectPoint connectPoint);
43 49
44 /** 50 /**
45 * Returns the addresses information for all connection points. 51 * Returns the addresses information for all connection points.
......
...@@ -99,19 +99,28 @@ public interface HostStore { ...@@ -99,19 +99,28 @@ public interface HostStore {
99 Set<Host> getConnectedHosts(DeviceId deviceId); 99 Set<Host> getConnectedHosts(DeviceId deviceId);
100 100
101 /** 101 /**
102 - * Updates the address information for a given port. 102 + * Updates the address information for a given port. The given address
103 + * information is added to any previously held information for the port.
103 * 104 *
104 * @param addresses the port and address information 105 * @param addresses the port and address information
105 */ 106 */
106 void updateAddressBindings(PortAddresses addresses); 107 void updateAddressBindings(PortAddresses addresses);
107 108
108 /** 109 /**
110 + * Removes the given addresses from the set of address information held for
111 + * a port.
112 + *
113 + * @param addresses the port and address information
114 + */
115 + void removeAddressBindings(PortAddresses addresses);
116 +
117 + /**
109 * Removes any previously stored address information for a given connection 118 * Removes any previously stored address information for a given connection
110 * point. 119 * point.
111 * 120 *
112 * @param connectPoint the connection point 121 * @param connectPoint the connection point
113 */ 122 */
114 - void removeAddressBindings(ConnectPoint connectPoint); 123 + void clearAddressBindings(ConnectPoint connectPoint);
115 124
116 /** 125 /**
117 * Returns the address bindings stored for all connection points. 126 * Returns the address bindings stored for all connection points.
......
1 package org.onlab.onos.net.host; 1 package org.onlab.onos.net.host;
2 2
3 +import java.util.HashSet;
4 +import java.util.Set;
5 +
3 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
4 -import org.onlab.packet.IpAddress; 7 +import org.onlab.packet.IpPrefix;
5 import org.onlab.packet.MacAddress; 8 import org.onlab.packet.MacAddress;
6 9
7 /** 10 /**
8 * Represents address information bound to a port. 11 * Represents address information bound to a port.
9 */ 12 */
10 -public interface PortAddresses { 13 +public class PortAddresses {
14 +
15 + private final ConnectPoint connectPoint;
16 + private final Set<IpPrefix> ipAddresses;
17 + private final MacAddress macAddress;
18 +
19 + /**
20 + * Constructs a PortAddress object for the given connection point, with a
21 + * set of IP addresses and a MAC address.
22 + * <p/>
23 + * Both address parameters are optional and can be set to null.
24 + *
25 + * @param connectPoint the connection point these addresses are for
26 + * @param ips a set of IP addresses
27 + * @param mac a MAC address
28 + */
29 + public PortAddresses(ConnectPoint connectPoint,
30 + Set<IpPrefix> ips, MacAddress mac) {
31 + this.connectPoint = connectPoint;
32 + this.ipAddresses = (ips == null) ? null : new HashSet<>(ips);
33 + this.macAddress = mac;
34 + }
11 35
12 /** 36 /**
13 * Returns the connection point this address information is bound to. 37 * Returns the connection point this address information is bound to.
14 * 38 *
15 * @return the connection point 39 * @return the connection point
16 */ 40 */
17 - ConnectPoint connectPoint(); 41 + public ConnectPoint connectPoint() {
42 + return connectPoint;
43 + }
18 44
19 /** 45 /**
20 - * Returns the IP address bound to the port. 46 + * Returns the set of IP addresses.
21 * 47 *
22 - * @return the IP address 48 + * @return the IP addresses
23 */ 49 */
24 - IpAddress ip(); 50 + public Set<IpPrefix> ips() {
51 + return ipAddresses;
52 + }
25 53
26 /** 54 /**
27 - * Returns the MAC address bound to the port. 55 + * Returns the MAC address.
28 * 56 *
29 - * @return the MAC address if one is bound, otherwise null 57 + * @return the MAC address
30 */ 58 */
31 - MacAddress mac(); 59 + public MacAddress mac() {
60 + return macAddress;
61 + }
62 +
32 } 63 }
......
1 -package org.onlab.onos.net.host.impl;
2 -
3 -import org.onlab.onos.net.ConnectPoint;
4 -import org.onlab.onos.net.host.PortAddresses;
5 -import org.onlab.packet.IpAddress;
6 -import org.onlab.packet.MacAddress;
7 -
8 -public class DefaultPortAddresses implements PortAddresses {
9 -
10 - private final ConnectPoint connectPoint;
11 - private final IpAddress ipAddress;
12 - private final MacAddress macAddress;
13 -
14 - public DefaultPortAddresses(ConnectPoint connectPoint,
15 - IpAddress ip, MacAddress mac) {
16 - this.connectPoint = connectPoint;
17 - this.ipAddress = ip;
18 - this.macAddress = mac;
19 - }
20 -
21 - @Override
22 - public ConnectPoint connectPoint() {
23 - return connectPoint;
24 - }
25 -
26 - @Override
27 - public IpAddress ip() {
28 - return ipAddress;
29 - }
30 -
31 - @Override
32 - public MacAddress mac() {
33 - return macAddress;
34 - }
35 -
36 -}
...@@ -155,14 +155,18 @@ public class HostManager ...@@ -155,14 +155,18 @@ public class HostManager
155 } 155 }
156 156
157 @Override 157 @Override
158 - public void bindAddressesToPort(IpAddress ip, MacAddress mac, 158 + public void bindAddressesToPort(PortAddresses addresses) {
159 - ConnectPoint connectPoint) { 159 + store.updateAddressBindings(addresses);
160 - store.updateAddressBindings(new DefaultPortAddresses(connectPoint, ip, mac));
161 } 160 }
162 161
163 @Override 162 @Override
164 - public void unbindAddressesFromPort(ConnectPoint connectPoint) { 163 + public void unbindAddressesFromPort(PortAddresses portAddresses) {
165 - store.removeAddressBindings(connectPoint); 164 + store.removeAddressBindings(portAddresses);
165 + }
166 +
167 + @Override
168 + public void clearAddresses(ConnectPoint connectPoint) {
169 + store.clearAddressBindings(connectPoint);
166 } 170 }
167 171
168 @Override 172 @Override
......
...@@ -128,9 +128,11 @@ public class HostMonitor implements TimerTask { ...@@ -128,9 +128,11 @@ public class HostMonitor implements TimerTask {
128 ConnectPoint cp = new ConnectPoint(device.id(), port.number()); 128 ConnectPoint cp = new ConnectPoint(device.id(), port.number());
129 PortAddresses addresses = hostStore.getAddressBindingsForPort(cp); 129 PortAddresses addresses = hostStore.getAddressBindingsForPort(cp);
130 130
131 - if (addresses.ip().contains(targetIp)) { 131 + /*for (IpPrefix prefix : addresses.ips()) {
132 + if (prefix.contains(targetIp)) {
132 sendProbe(device.id(), port, addresses, targetIp); 133 sendProbe(device.id(), port, addresses, targetIp);
133 } 134 }
135 + }*/
134 } 136 }
135 } 137 }
136 138
...@@ -173,7 +175,7 @@ public class HostMonitor implements TimerTask { ...@@ -173,7 +175,7 @@ public class HostMonitor implements TimerTask {
173 } 175 }
174 176
175 arp.setSenderHardwareAddress(sourceMacAddress) 177 arp.setSenderHardwareAddress(sourceMacAddress)
176 - .setSenderProtocolAddress(portAddresses.ip().toOctets()) 178 + //TODO .setSenderProtocolAddress(portAddresses.ips().toOctets())
177 .setTargetHardwareAddress(ZERO_MAC_ADDRESS) 179 .setTargetHardwareAddress(ZERO_MAC_ADDRESS)
178 .setTargetProtocolAddress(targetIp.toOctets()); 180 .setTargetProtocolAddress(targetIp.toOctets());
179 181
......
...@@ -198,12 +198,19 @@ public class SimpleHostStore implements HostStore { ...@@ -198,12 +198,19 @@ public class SimpleHostStore implements HostStore {
198 198
199 @Override 199 @Override
200 public void updateAddressBindings(PortAddresses addresses) { 200 public void updateAddressBindings(PortAddresses addresses) {
201 - portAddresses.put(addresses.connectPoint(), addresses); 201 + // TODO portAddresses.put(addresses.connectPoint(), addresses);
202 } 202 }
203 203
204 @Override 204 @Override
205 - public void removeAddressBindings(ConnectPoint connectPoint) { 205 + public void removeAddressBindings(PortAddresses addresses) {
206 - portAddresses.remove(connectPoint); 206 + // TODO Auto-generated method stub
207 +
208 + }
209 +
210 + @Override
211 + public void clearAddressBindings(ConnectPoint connectPoint) {
212 + // TODO Auto-generated method stub
213 +
207 } 214 }
208 215
209 @Override 216 @Override
......