Committed by
Gerrit Code Review
Fix for ONOS-5033 hosts - dynamic or static
Change-Id: I3791370db0037968003abc23c918c63119d2dba2
Showing
11 changed files
with
100 additions
and
10 deletions
| ... | @@ -38,7 +38,7 @@ import static com.google.common.collect.Lists.newArrayList; | ... | @@ -38,7 +38,7 @@ import static com.google.common.collect.Lists.newArrayList; |
| 38 | public class HostsListCommand extends AbstractShellCommand { | 38 | public class HostsListCommand extends AbstractShellCommand { |
| 39 | 39 | ||
| 40 | private static final String FMT = | 40 | private static final String FMT = |
| 41 | - "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s%s"; | 41 | + "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s%s, configured=%s"; |
| 42 | 42 | ||
| 43 | private static final String FMT_SHORT = | 43 | private static final String FMT_SHORT = |
| 44 | "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s"; | 44 | "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s"; |
| ... | @@ -93,7 +93,9 @@ public class HostsListCommand extends AbstractShellCommand { | ... | @@ -93,7 +93,9 @@ public class HostsListCommand extends AbstractShellCommand { |
| 93 | } else { | 93 | } else { |
| 94 | print(FMT, host.id(), host.mac(), | 94 | print(FMT, host.id(), host.mac(), |
| 95 | host.location().deviceId(), host.location().port(), | 95 | host.location().deviceId(), host.location().port(), |
| 96 | - host.vlan(), host.ipAddresses(), annotations(host.annotations())); | 96 | + host.vlan(), host.ipAddresses(), annotations(host.annotations()), |
| 97 | + host.configured()); | ||
| 97 | } | 98 | } |
| 98 | } | 99 | } |
| 99 | } | 100 | } |
| 101 | + | ... | ... |
| ... | @@ -36,6 +36,7 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -36,6 +36,7 @@ public class DefaultHost extends AbstractElement implements Host { |
| 36 | private final VlanId vlan; | 36 | private final VlanId vlan; |
| 37 | private final HostLocation location; | 37 | private final HostLocation location; |
| 38 | private final Set<IpAddress> ips; | 38 | private final Set<IpAddress> ips; |
| 39 | + private final boolean configured; | ||
| 39 | 40 | ||
| 40 | /** | 41 | /** |
| 41 | * Creates an end-station host using the supplied information. | 42 | * Creates an end-station host using the supplied information. |
| ... | @@ -51,11 +52,30 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -51,11 +52,30 @@ public class DefaultHost extends AbstractElement implements Host { |
| 51 | public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, | 52 | public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, |
| 52 | VlanId vlan, HostLocation location, Set<IpAddress> ips, | 53 | VlanId vlan, HostLocation location, Set<IpAddress> ips, |
| 53 | Annotations... annotations) { | 54 | Annotations... annotations) { |
| 55 | + this(providerId, id, mac, vlan, location, ips, false, annotations); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Creates an end-station host using the supplied information. | ||
| 60 | + * | ||
| 61 | + * @param providerId provider identity | ||
| 62 | + * @param id host identifier | ||
| 63 | + * @param mac host MAC address | ||
| 64 | + * @param vlan host VLAN identifier | ||
| 65 | + * @param location host location | ||
| 66 | + * @param ips host IP addresses | ||
| 67 | + * @param configured true if configured via NetworkConfiguration | ||
| 68 | + * @param annotations optional key/value annotations | ||
| 69 | + */ | ||
| 70 | + public DefaultHost(ProviderId providerId, HostId id, MacAddress mac, | ||
| 71 | + VlanId vlan, HostLocation location, Set<IpAddress> ips, | ||
| 72 | + boolean configured, Annotations... annotations) { | ||
| 54 | super(providerId, id, annotations); | 73 | super(providerId, id, annotations); |
| 55 | this.mac = mac; | 74 | this.mac = mac; |
| 56 | this.vlan = vlan; | 75 | this.vlan = vlan; |
| 57 | this.location = location; | 76 | this.location = location; |
| 58 | this.ips = new HashSet<>(ips); | 77 | this.ips = new HashSet<>(ips); |
| 78 | + this.configured = configured; | ||
| 59 | } | 79 | } |
| 60 | 80 | ||
| 61 | @Override | 81 | @Override |
| ... | @@ -84,6 +104,11 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -84,6 +104,11 @@ public class DefaultHost extends AbstractElement implements Host { |
| 84 | } | 104 | } |
| 85 | 105 | ||
| 86 | @Override | 106 | @Override |
| 107 | + public boolean configured() { | ||
| 108 | + return configured; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + @Override | ||
| 87 | public int hashCode() { | 112 | public int hashCode() { |
| 88 | return Objects.hash(id, mac, vlan, location); | 113 | return Objects.hash(id, mac, vlan, location); |
| 89 | } | 114 | } |
| ... | @@ -114,6 +139,7 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -114,6 +139,7 @@ public class DefaultHost extends AbstractElement implements Host { |
| 114 | .add("location", location()) | 139 | .add("location", location()) |
| 115 | .add("ipAddresses", ipAddresses()) | 140 | .add("ipAddresses", ipAddresses()) |
| 116 | .add("annotations", annotations()) | 141 | .add("annotations", annotations()) |
| 142 | + .add("configured", configured()) | ||
| 117 | .toString(); | 143 | .toString(); |
| 118 | } | 144 | } |
| 119 | 145 | ... | ... |
| ... | @@ -63,6 +63,14 @@ public interface Host extends Element { | ... | @@ -63,6 +63,14 @@ public interface Host extends Element { |
| 63 | */ | 63 | */ |
| 64 | HostLocation location(); | 64 | HostLocation location(); |
| 65 | 65 | ||
| 66 | + /** | ||
| 67 | + * Returns true if configured by NetworkConfiguration. | ||
| 68 | + * @return configured/learnt dynamically | ||
| 69 | + */ | ||
| 70 | + default boolean configured() { | ||
| 71 | + return false; | ||
| 72 | + } | ||
| 66 | // TODO: explore capturing list of recent locations to aid in mobility | 73 | // TODO: explore capturing list of recent locations to aid in mobility |
| 67 | 74 | ||
| 68 | } | 75 | } |
| 76 | + | ... | ... |
| ... | @@ -40,6 +40,7 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -40,6 +40,7 @@ public class DefaultHostDescription extends AbstractDescription |
| 40 | private final VlanId vlan; | 40 | private final VlanId vlan; |
| 41 | private final HostLocation location; | 41 | private final HostLocation location; |
| 42 | private final Set<IpAddress> ip; | 42 | private final Set<IpAddress> ip; |
| 43 | + private final boolean configured; | ||
| 43 | 44 | ||
| 44 | /** | 45 | /** |
| 45 | * Creates a host description using the supplied information. | 46 | * Creates a host description using the supplied information. |
| ... | @@ -83,11 +84,46 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -83,11 +84,46 @@ public class DefaultHostDescription extends AbstractDescription |
| 83 | public DefaultHostDescription(MacAddress mac, VlanId vlan, | 84 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
| 84 | HostLocation location, Set<IpAddress> ip, | 85 | HostLocation location, Set<IpAddress> ip, |
| 85 | SparseAnnotations... annotations) { | 86 | SparseAnnotations... annotations) { |
| 87 | + this(mac, vlan, location, ip, false, annotations); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Creates a host description using the supplied information. | ||
| 92 | + * | ||
| 93 | + * @param mac host MAC address | ||
| 94 | + * @param vlan host VLAN identifier | ||
| 95 | + * @param location host location | ||
| 96 | + * @param configured true if configured via NetworkConfiguration | ||
| 97 | + * @param annotations optional key/value annotations map | ||
| 98 | + */ | ||
| 99 | + public DefaultHostDescription(MacAddress mac, VlanId vlan, | ||
| 100 | + HostLocation location, | ||
| 101 | + boolean configured, | ||
| 102 | + SparseAnnotations... annotations) { | ||
| 103 | + this(mac, vlan, location, Collections.<IpAddress>emptySet(), | ||
| 104 | + configured, annotations); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Creates a host description using the supplied information. | ||
| 109 | + * | ||
| 110 | + * @param mac host MAC address | ||
| 111 | + * @param vlan host VLAN identifier | ||
| 112 | + * @param location host location | ||
| 113 | + * @param ip host IP address | ||
| 114 | + * @param configured true if configured via NetworkConfiguration | ||
| 115 | + * @param annotations optional key/value annotations map | ||
| 116 | + */ | ||
| 117 | + public DefaultHostDescription(MacAddress mac, VlanId vlan, | ||
| 118 | + HostLocation location, Set<IpAddress> ip, | ||
| 119 | + boolean configured, | ||
| 120 | + SparseAnnotations... annotations) { | ||
| 86 | super(annotations); | 121 | super(annotations); |
| 87 | this.mac = mac; | 122 | this.mac = mac; |
| 88 | this.vlan = vlan; | 123 | this.vlan = vlan; |
| 89 | this.location = location; | 124 | this.location = location; |
| 90 | this.ip = ImmutableSet.copyOf(ip); | 125 | this.ip = ImmutableSet.copyOf(ip); |
| 126 | + this.configured = configured; | ||
| 91 | } | 127 | } |
| 92 | 128 | ||
| 93 | @Override | 129 | @Override |
| ... | @@ -111,12 +147,18 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -111,12 +147,18 @@ public class DefaultHostDescription extends AbstractDescription |
| 111 | } | 147 | } |
| 112 | 148 | ||
| 113 | @Override | 149 | @Override |
| 150 | + public boolean configured() { | ||
| 151 | + return configured; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + @Override | ||
| 114 | public String toString() { | 155 | public String toString() { |
| 115 | return toStringHelper(this) | 156 | return toStringHelper(this) |
| 116 | .add("mac", mac) | 157 | .add("mac", mac) |
| 117 | .add("vlan", vlan) | 158 | .add("vlan", vlan) |
| 118 | .add("location", location) | 159 | .add("location", location) |
| 119 | .add("ipAddress", ip) | 160 | .add("ipAddress", ip) |
| 161 | + .add("configured", configured) | ||
| 120 | .toString(); | 162 | .toString(); |
| 121 | } | 163 | } |
| 122 | 164 | ||
| ... | @@ -139,5 +181,4 @@ public class DefaultHostDescription extends AbstractDescription | ... | @@ -139,5 +181,4 @@ public class DefaultHostDescription extends AbstractDescription |
| 139 | } | 181 | } |
| 140 | return false; | 182 | return false; |
| 141 | } | 183 | } |
| 142 | - | ||
| 143 | } | 184 | } | ... | ... |
| ... | @@ -55,4 +55,12 @@ public interface HostDescription extends Description { | ... | @@ -55,4 +55,12 @@ public interface HostDescription extends Description { |
| 55 | * @return host IP address | 55 | * @return host IP address |
| 56 | */ | 56 | */ |
| 57 | Set<IpAddress> ipAddress(); | 57 | Set<IpAddress> ipAddress(); |
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Returns true if configured by NetworkConfiguration. | ||
| 61 | + * @return configured/learnt dynamically | ||
| 62 | + */ | ||
| 63 | + default boolean configured() { | ||
| 64 | + return false; | ||
| 65 | + } | ||
| 58 | } | 66 | } | ... | ... |
| ... | @@ -39,7 +39,8 @@ public final class HostCodec extends AnnotatedCodec<Host> { | ... | @@ -39,7 +39,8 @@ public final class HostCodec extends AnnotatedCodec<Host> { |
| 39 | final ObjectNode result = context.mapper().createObjectNode() | 39 | final ObjectNode result = context.mapper().createObjectNode() |
| 40 | .put("id", host.id().toString()) | 40 | .put("id", host.id().toString()) |
| 41 | .put("mac", host.mac().toString()) | 41 | .put("mac", host.mac().toString()) |
| 42 | - .put("vlan", host.vlan().toString()); | 42 | + .put("vlan", host.vlan().toString()) |
| 43 | + .put("configured", host.configured()); | ||
| 43 | 44 | ||
| 44 | final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); | 45 | final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); |
| 45 | for (final IpAddress ipAddress : host.ipAddresses()) { | 46 | for (final IpAddress ipAddress : host.ipAddresses()) { | ... | ... |
| ... | @@ -64,7 +64,7 @@ public final class BasicHostOperator implements ConfigOperator { | ... | @@ -64,7 +64,7 @@ public final class BasicHostOperator implements ConfigOperator { |
| 64 | 64 | ||
| 65 | SparseAnnotations sa = combine(cfg, descr.annotations()); | 65 | SparseAnnotations sa = combine(cfg, descr.annotations()); |
| 66 | return new DefaultHostDescription(descr.hwAddress(), descr.vlan(), | 66 | return new DefaultHostDescription(descr.hwAddress(), descr.vlan(), |
| 67 | - location, ipAddresses, sa); | 67 | + location, ipAddresses, descr.configured(), sa); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | /** | 70 | /** | ... | ... |
| ... | @@ -167,11 +167,14 @@ public class DistributedHostStore | ... | @@ -167,11 +167,14 @@ public class DistributedHostStore |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | final Annotations annotations; | 169 | final Annotations annotations; |
| 170 | + final boolean configured; | ||
| 170 | if (existingHost != null) { | 171 | if (existingHost != null) { |
| 171 | annotations = merge((DefaultAnnotations) existingHost.annotations(), | 172 | annotations = merge((DefaultAnnotations) existingHost.annotations(), |
| 172 | hostDescription.annotations()); | 173 | hostDescription.annotations()); |
| 174 | + configured = existingHost.configured(); | ||
| 173 | } else { | 175 | } else { |
| 174 | annotations = hostDescription.annotations(); | 176 | annotations = hostDescription.annotations(); |
| 177 | + configured = hostDescription.configured(); | ||
| 175 | } | 178 | } |
| 176 | 179 | ||
| 177 | return new DefaultHost(providerId, | 180 | return new DefaultHost(providerId, |
| ... | @@ -180,6 +183,7 @@ public class DistributedHostStore | ... | @@ -180,6 +183,7 @@ public class DistributedHostStore |
| 180 | hostDescription.vlan(), | 183 | hostDescription.vlan(), |
| 181 | location, | 184 | location, |
| 182 | addresses, | 185 | addresses, |
| 186 | + configured, | ||
| 183 | annotations); | 187 | annotations); |
| 184 | }); | 188 | }); |
| 185 | return null; | 189 | return null; | ... | ... |
| ... | @@ -112,8 +112,8 @@ public class NetworkConfigHostProvider extends AbstractProvider implements HostP | ... | @@ -112,8 +112,8 @@ public class NetworkConfigHostProvider extends AbstractProvider implements HostP |
| 112 | protected void addHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set<IpAddress> ips) { | 112 | protected void addHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set<IpAddress> ips) { |
| 113 | HostId hid = HostId.hostId(mac, vlan); | 113 | HostId hid = HostId.hostId(mac, vlan); |
| 114 | HostDescription desc = (ips != null) ? | 114 | HostDescription desc = (ips != null) ? |
| 115 | - new DefaultHostDescription(mac, vlan, hloc, ips) : | 115 | + new DefaultHostDescription(mac, vlan, hloc, ips, true) : |
| 116 | - new DefaultHostDescription(mac, vlan, hloc); | 116 | + new DefaultHostDescription(mac, vlan, hloc, true); |
| 117 | providerService.hostDetected(hid, desc, false); | 117 | providerService.hostDetected(hid, desc, false); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| ... | @@ -128,7 +128,7 @@ public class NetworkConfigHostProvider extends AbstractProvider implements HostP | ... | @@ -128,7 +128,7 @@ public class NetworkConfigHostProvider extends AbstractProvider implements HostP |
| 128 | */ | 128 | */ |
| 129 | protected void updateHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set<IpAddress> ips) { | 129 | protected void updateHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set<IpAddress> ips) { |
| 130 | HostId hid = HostId.hostId(mac, vlan); | 130 | HostId hid = HostId.hostId(mac, vlan); |
| 131 | - HostDescription desc = new DefaultHostDescription(mac, vlan, hloc, ips); | 131 | + HostDescription desc = new DefaultHostDescription(mac, vlan, hloc, ips, true); |
| 132 | providerService.hostDetected(hid, desc, true); | 132 | providerService.hostDetected(hid, desc, true); |
| 133 | } | 133 | } |
| 134 | 134 | ... | ... |
| ... | @@ -214,7 +214,7 @@ public class HostsWebResource extends AbstractWebResource { | ... | @@ -214,7 +214,7 @@ public class HostsWebResource extends AbstractWebResource { |
| 214 | // Update host inventory | 214 | // Update host inventory |
| 215 | 215 | ||
| 216 | HostId hostId = HostId.hostId(mac, vlanId); | 216 | HostId hostId = HostId.hostId(mac, vlanId); |
| 217 | - DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips, annotations); | 217 | + DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips, true, annotations); |
| 218 | hostProviderService.hostDetected(hostId, desc, false); | 218 | hostProviderService.hostDetected(hostId, desc, false); |
| 219 | return hostId; | 219 | return hostId; |
| 220 | } | 220 | } | ... | ... |
| ... | @@ -198,7 +198,7 @@ public class HostResourceTest extends ResourceTest { | ... | @@ -198,7 +198,7 @@ public class HostResourceTest extends ResourceTest { |
| 198 | @Override | 198 | @Override |
| 199 | public boolean matchesSafely(JsonArray json) { | 199 | public boolean matchesSafely(JsonArray json) { |
| 200 | boolean hostFound = false; | 200 | boolean hostFound = false; |
| 201 | - final int expectedAttributes = 5; | 201 | + final int expectedAttributes = 6; |
| 202 | for (int jsonHostIndex = 0; jsonHostIndex < json.size(); | 202 | for (int jsonHostIndex = 0; jsonHostIndex < json.size(); |
| 203 | jsonHostIndex++) { | 203 | jsonHostIndex++) { |
| 204 | 204 | ... | ... |
-
Please register or login to post a comment