Jonathan Hart

Added IP addresses to Port

1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import static com.google.common.base.MoreObjects.toStringHelper;
4 +
5 +import java.util.Collections;
3 import java.util.Objects; 6 import java.util.Objects;
7 +import java.util.Set;
4 8
5 -import static com.google.common.base.MoreObjects.toStringHelper; 9 +import org.onlab.packet.IpAddress;
6 10
7 /** 11 /**
8 * Default port implementation. 12 * Default port implementation.
...@@ -13,6 +17,9 @@ public class DefaultPort implements Port { ...@@ -13,6 +17,9 @@ public class DefaultPort implements Port {
13 private final PortNumber number; 17 private final PortNumber number;
14 private final boolean isEnabled; 18 private final boolean isEnabled;
15 19
20 + // Attributes
21 + private final Set<IpAddress> ipAddresses;
22 +
16 /** 23 /**
17 * Creates a network element attributed to the specified provider. 24 * Creates a network element attributed to the specified provider.
18 * 25 *
...@@ -22,9 +29,24 @@ public class DefaultPort implements Port { ...@@ -22,9 +29,24 @@ public class DefaultPort implements Port {
22 */ 29 */
23 public DefaultPort(Element element, PortNumber number, 30 public DefaultPort(Element element, PortNumber number,
24 boolean isEnabled) { 31 boolean isEnabled) {
32 + this(element, number, isEnabled, null);
33 + }
34 +
35 + /**
36 + * Creates a network element attributed to the specified provider.
37 + *
38 + * @param element parent network element
39 + * @param number port number
40 + * @param isEnabled indicator whether the port is up and active
41 + * @param ipAddresses set of IP addresses assigned to the port
42 + */
43 + public DefaultPort(Element element, PortNumber number,
44 + boolean isEnabled, Set<IpAddress> ipAddresses) {
25 this.element = element; 45 this.element = element;
26 this.number = number; 46 this.number = number;
27 this.isEnabled = isEnabled; 47 this.isEnabled = isEnabled;
48 + this.ipAddresses = (ipAddresses == null) ? null :
49 + Collections.unmodifiableSet(ipAddresses);
28 } 50 }
29 51
30 @Override 52 @Override
...@@ -67,4 +89,9 @@ public class DefaultPort implements Port { ...@@ -67,4 +89,9 @@ public class DefaultPort implements Port {
67 return element; 89 return element;
68 } 90 }
69 91
92 + @Override
93 + public Set<IpAddress> ipAddresses() {
94 + return ipAddresses;
95 + }
96 +
70 } 97 }
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import java.util.Set;
4 +
5 +import org.onlab.packet.IpAddress;
6 +
3 /** 7 /**
4 * Abstraction of a network port. 8 * Abstraction of a network port.
5 */ 9 */
...@@ -28,4 +32,12 @@ public interface Port { ...@@ -28,4 +32,12 @@ public interface Port {
28 32
29 // set of port attributes 33 // set of port attributes
30 34
35 + /**
36 + * Returns the set of IP addresses that are logically configured on this
37 + * port.
38 + *
39 + * @return the set of IP addresses configured on the port. The set is empty
40 + * if no addresses are configured.
41 + */
42 + Set<IpAddress> ipAddresses();
31 } 43 }
......