Added CLI and REST support for auxLocations
Change-Id: I04e78f766dcbb18bce4a2f9160d3740ec2fbd846
diff --git a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
index b820573..310c8fd 100644
--- a/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
+++ b/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java
@@ -126,18 +126,19 @@
*
* @param mac MAC address of the host
* @param vlan VLAN ID of the host
- * @param locations Location of the host
+ * @param locations Locations of the host
+ * @param auxLocations auxiliary locations of the host
* @param ips Set of IP addresses of the host
* @param innerVlan host inner VLAN identifier
* @param outerTpid outer TPID of a host
*/
- protected void addHost(MacAddress mac, VlanId vlan, Set<HostLocation> locations, Set<IpAddress> ips,
- VlanId innerVlan, EthType outerTpid) {
+ protected void addHost(MacAddress mac, VlanId vlan, Set<HostLocation> locations, Set<HostLocation> auxLocations,
+ Set<IpAddress> ips, VlanId innerVlan, EthType outerTpid) {
HostId hid = HostId.hostId(mac, vlan);
HostDescription desc = (ips != null) ?
- new DefaultHostDescription(mac, vlan, locations, ips,
+ new DefaultHostDescription(mac, vlan, locations, auxLocations, ips,
innerVlan, outerTpid, true) :
- new DefaultHostDescription(mac, vlan, locations, Collections.emptySet(),
+ new DefaultHostDescription(mac, vlan, locations, auxLocations, Collections.emptySet(),
innerVlan, outerTpid, true);
providerService.hostDetected(hid, desc, true);
}
@@ -163,15 +164,16 @@
*
* @param mac MAC address of the host
* @param vlan VLAN ID of the host
- * @param locations Location of the host
+ * @param locations Locations of the host
+ * @param auxLocations auxiliary locations of the host
* @param ips Set of IP addresses of the host
* @param innerVlan host inner VLAN identifier
* @param outerTpid outer TPID of a host
*/
- protected void updateHost(MacAddress mac, VlanId vlan, Set<HostLocation> locations, Set<IpAddress> ips,
- VlanId innerVlan, EthType outerTpid) {
+ protected void updateHost(MacAddress mac, VlanId vlan, Set<HostLocation> locations, Set<HostLocation> auxLocations,
+ Set<IpAddress> ips, VlanId innerVlan, EthType outerTpid) {
HostId hid = HostId.hostId(mac, vlan);
- HostDescription desc = new DefaultHostDescription(mac, vlan, locations, ips,
+ HostDescription desc = new DefaultHostDescription(mac, vlan, locations, auxLocations, ips,
innerVlan, outerTpid, true);
providerService.hostDetected(hid, desc, true);
}
@@ -199,9 +201,18 @@
Set<HostLocation> locations = locs.stream()
.map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis()))
.collect(Collectors.toSet());
+
+ // auxLocations allows to be null
+ Set<HostLocation> auxLocations = hostConfig.auxLocations();
+ if (auxLocations != null) {
+ auxLocations = auxLocations.stream()
+ .map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis()))
+ .collect(Collectors.toSet());
+ }
+
VlanId innerVlan = hostConfig.innerVlan();
EthType outerTpid = hostConfig.outerTpid();
- addHost(mac, vlan, locations, ipAddresses, innerVlan, outerTpid);
+ addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
} else {
log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
}
@@ -224,6 +235,7 @@
BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = null;
Set<HostLocation> locations = null;
+ Set<HostLocation> auxLocations = null;
VlanId innerVlan = VlanId.NONE;
EthType outerTpid = EthType.EtherType.UNKNOWN.ethType();
@@ -238,16 +250,25 @@
locations = locations.stream()
.map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis()))
.collect(Collectors.toSet());
+
+ // auxLocations allows to be null
+ auxLocations = hostConfig.auxLocations();
+ if (auxLocations != null) {
+ auxLocations = auxLocations.stream()
+ .map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis()))
+ .collect(Collectors.toSet());
+ }
+
innerVlan = hostConfig.innerVlan();
outerTpid = hostConfig.outerTpid();
}
switch (event.type()) {
case CONFIG_ADDED:
- addHost(mac, vlan, locations, ipAddresses, innerVlan, outerTpid);
+ addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
break;
case CONFIG_UPDATED:
- updateHost(mac, vlan, locations, ipAddresses, innerVlan, outerTpid);
+ updateHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
break;
case CONFIG_REMOVED:
removeHost(mac, vlan);
diff --git a/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java b/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java
index 36de211..4bba524 100644
--- a/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java
+++ b/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java
@@ -52,6 +52,9 @@
private DeviceId deviceId = DeviceId.deviceId("of:0000000000000001");
private PortNumber port = PortNumber.portNumber(5);
private Set<HostLocation> locations = Sets.newHashSet(new HostLocation(deviceId, port, 100));
+ private DeviceId auxDeviceId = DeviceId.deviceId("of:0000000000000002");
+ private PortNumber auxPort = PortNumber.portNumber(7);
+ private Set<HostLocation> auxLocations = Sets.newHashSet(new HostLocation(auxDeviceId, auxPort, 100));
private Set<IpAddress> ips = new HashSet<>();
private HostId hostId = HostId.hostId(mac, vlan);
private HostDescription hostDescription;
@@ -65,13 +68,13 @@
// Initialize test variables
ips.add(IpAddress.valueOf("10.0.0.1"));
ips.add(IpAddress.valueOf("192.168.0.1"));
- hostDescription = new DefaultHostDescription(mac, vlan, locations, ips,
+ hostDescription = new DefaultHostDescription(mac, vlan, locations, auxLocations, ips,
innerVlan, outerTpid, true);
}
@Test
public void testAddHost() throws Exception {
- provider.addHost(mac, vlan, locations, ips, innerVlan, outerTpid);
+ provider.addHost(mac, vlan, locations, auxLocations, ips, innerVlan, outerTpid);
assertThat(providerService.hostId, is(hostId));
assertThat(providerService.hostDescription, is(hostDescription));
assertThat(providerService.event, is("hostDetected"));
@@ -80,7 +83,7 @@
@Test
public void testUpdateHost() throws Exception {
- provider.updateHost(mac, vlan, locations, ips, innerVlan, outerTpid);
+ provider.updateHost(mac, vlan, locations, auxLocations, ips, innerVlan, outerTpid);
assertThat(providerService.hostId, is(hostId));
assertThat(providerService.hostDescription, is(hostDescription));
assertThat(providerService.event, is("hostDetected"));