Jonathan Hart
Committed by Thomas Vachuska

Remove all address bindings code from Host subsystem.

This has been superseded by the InterfaceService.

Change-Id: I8aae4cfe00752a84e545a1030c199aea8b59da38
......@@ -21,7 +21,6 @@ import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import java.util.Objects;
import java.util.Set;
......@@ -55,18 +54,6 @@ public class Interface {
}
/**
* Creates an Interface based on a PortAddresses object.
*
* @param portAddresses the PortAddresses object to turn into an Interface
*/
public Interface(PortAddresses portAddresses) {
connectPoint = portAddresses.connectPoint();
ipAddresses = Sets.newHashSet(portAddresses.ipAddresses());
macAddress = portAddresses.mac();
vlan = portAddresses.vlan();
}
/**
* Retrieves the connection point that this interface maps to.
*
* @return the connection point
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.routing.config.impl;
import com.google.common.collect.Sets;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.routing.config.Interface;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Adapts PortAddresses data from the HostService into Interface data used by
* the routing module.
*/
public class HostToInterfaceAdaptor {
private final HostService hostService;
public HostToInterfaceAdaptor(HostService hostService) {
this.hostService = checkNotNull(hostService);
}
public Set<Interface> getInterfaces() {
Set<PortAddresses> addresses = hostService.getAddressBindings();
Set<Interface> interfaces = Sets.newHashSetWithExpectedSize(addresses.size());
for (PortAddresses a : addresses) {
interfaces.add(new Interface(a));
}
return interfaces;
}
public Interface getInterface(ConnectPoint connectPoint) {
checkNotNull(connectPoint);
Set<PortAddresses> portAddresses =
hostService.getAddressBindingsForPort(connectPoint);
for (PortAddresses addresses : portAddresses) {
if (addresses.connectPoint().equals(connectPoint)) {
return new Interface(addresses);
}
}
return null;
}
public Interface getInterface(IpAddress ip) {
Set<PortAddresses> portAddresses = hostService.getAddressBindings();
for (PortAddresses portAddress : portAddresses) {
for (InterfaceIpAddress portIp : portAddress.ipAddresses()) {
if (portIp.ipAddress().equals(ip)) {
return new Interface(portAddress);
}
}
}
return null;
}
public Interface getMatchingInterface(IpAddress ipAddress) {
checkNotNull(ipAddress);
for (PortAddresses portAddresses : hostService.getAddressBindings()) {
for (InterfaceIpAddress ia : portAddresses.ipAddresses()) {
if (ia.subnetAddress().contains(ipAddress)) {
return new Interface(portAddresses);
}
}
}
return null;
}
}
......@@ -38,7 +38,6 @@ import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.config.basics.SubjectFactories;
import org.onosproject.net.host.HostService;
import org.onosproject.routing.config.BgpConfig;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
......@@ -76,9 +75,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
private String configFileName = DEFAULT_CONFIG_FILE;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigRegistry registry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -103,7 +99,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
new DefaultByteArrayNodeFactory());
private MacAddress virtualGatewayMacAddress;
private HostToInterfaceAdaptor hostAdaptor;
private ConfigFactory configFactory =
new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") {
......@@ -117,7 +112,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
public void activate() {
registry.registerConfigFactory(configFactory);
readConfiguration();
hostAdaptor = new HostToInterfaceAdaptor(hostService);
log.info("Routing configuration service started");
}
......@@ -189,7 +183,7 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
@Override
public Set<Interface> getInterfaces() {
return hostAdaptor.getInterfaces();
return Collections.emptySet();
}
@Override
......@@ -212,17 +206,17 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
@Override
public Interface getInterface(ConnectPoint connectPoint) {
return hostAdaptor.getInterface(connectPoint);
return null;
}
@Override
public Interface getInterface(IpAddress ip) {
return hostAdaptor.getInterface(ip);
return null;
}
@Override
public Interface getMatchingInterface(IpAddress ipAddress) {
return hostAdaptor.getMatchingInterface(ipAddress);
return null;
}
@Override
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.routing.config.impl;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.routing.config.Interface;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for the HostToInterfaceAdaptor class.
*/
public class HostToInterfaceAdaptorTest {
private HostService hostService;
private HostToInterfaceAdaptor adaptor;
private Set<PortAddresses> portAddresses;
private Map<ConnectPoint, Interface> interfaces;
private static final ConnectPoint CP1 = new ConnectPoint(
DeviceId.deviceId("of:1"), PortNumber.portNumber(1));
private static final ConnectPoint CP2 = new ConnectPoint(
DeviceId.deviceId("of:1"), PortNumber.portNumber(2));
private static final ConnectPoint CP3 = new ConnectPoint(
DeviceId.deviceId("of:2"), PortNumber.portNumber(1));
private static final ConnectPoint NON_EXISTENT_CP = new ConnectPoint(
DeviceId.deviceId("doesnotexist"), PortNumber.portNumber(1));
@Before
public void setUp() throws Exception {
hostService = createMock(HostService.class);
portAddresses = Sets.newHashSet();
interfaces = Maps.newHashMap();
InterfaceIpAddress ia11 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.1.1"),
IpPrefix.valueOf("192.168.1.0/24"));
createPortAddressesAndInterface(CP1,
Sets.newHashSet(ia11),
MacAddress.valueOf("00:00:00:00:00:01"),
VlanId.NONE);
// Two addresses in the same subnet
InterfaceIpAddress ia21 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.2.1"),
IpPrefix.valueOf("192.168.2.0/24"));
InterfaceIpAddress ia22 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.2.2"),
IpPrefix.valueOf("192.168.2.0/24"));
createPortAddressesAndInterface(CP2,
Sets.newHashSet(ia21, ia22),
MacAddress.valueOf("00:00:00:00:00:02"),
VlanId.vlanId((short) 4));
// Two addresses in different subnets
InterfaceIpAddress ia31 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.3.1"),
IpPrefix.valueOf("192.168.3.0/24"));
InterfaceIpAddress ia41 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.4.1"),
IpPrefix.valueOf("192.168.4.0/24"));
createPortAddressesAndInterface(CP3,
Sets.newHashSet(ia31, ia41),
MacAddress.valueOf("00:00:00:00:00:03"),
VlanId.NONE);
expect(hostService.getAddressBindings()).andReturn(portAddresses).anyTimes();
replay(hostService);
adaptor = new HostToInterfaceAdaptor(hostService);
}
/**
* Creates both a PortAddresses and an Interface for the given inputs and
* places them in the correct global data stores.
*
* @param cp the connect point
* @param ipAddresses the set of interface IP addresses
* @param mac the MAC address
* @param vlan the VLAN ID
*/
private void createPortAddressesAndInterface(
ConnectPoint cp, Set<InterfaceIpAddress> ipAddresses,
MacAddress mac, VlanId vlan) {
PortAddresses pa = new PortAddresses(cp, ipAddresses, mac, vlan);
portAddresses.add(pa);
expect(hostService.getAddressBindingsForPort(cp)).andReturn(
Collections.singleton(pa)).anyTimes();
Interface intf = new Interface(cp, ipAddresses, mac, vlan);
interfaces.put(cp, intf);
}
/**
* Tests {@link HostToInterfaceAdaptor#getInterfaces()}.
* Verifies that the set of interfaces returned matches what is expected
* based on the input PortAddresses data.
*/
@Test
public void testGetInterfaces() {
Set<Interface> adaptorIntfs = adaptor.getInterfaces();
assertEquals(3, adaptorIntfs.size());
assertTrue(adaptorIntfs.contains(this.interfaces.get(CP1)));
assertTrue(adaptorIntfs.contains(this.interfaces.get(CP2)));
assertTrue(adaptorIntfs.contains(this.interfaces.get(CP3)));
}
/**
* Tests {@link HostToInterfaceAdaptor#getInterface(ConnectPoint)}.
* Verifies that the correct interface is returned for a given connect
* point.
*/
@Test
public void testGetInterface() {
assertEquals(this.interfaces.get(CP1), adaptor.getInterface(CP1));
assertEquals(this.interfaces.get(CP2), adaptor.getInterface(CP2));
assertEquals(this.interfaces.get(CP3), adaptor.getInterface(CP3));
// Try and get an interface for a connect point with no addresses
reset(hostService);
expect(hostService.getAddressBindingsForPort(NON_EXISTENT_CP))
.andReturn(Collections.<PortAddresses>emptySet()).anyTimes();
replay(hostService);
assertNull(adaptor.getInterface(NON_EXISTENT_CP));
}
/**
* Tests {@link HostToInterfaceAdaptor#getInterface(ConnectPoint)} in the
* case that the input connect point is null.
* Verifies that a NullPointerException is thrown.
*/
@Test(expected = NullPointerException.class)
public void testGetInterfaceNull() {
ConnectPoint c = null;
adaptor.getInterface(c);
}
/**
* Tests {@link HostToInterfaceAdaptor#getMatchingInterface(IpAddress)}.
* Verifies that the correct interface is returned based on the given IP
* address.
*/
@Test
public void testGetMatchingInterface() {
assertEquals(this.interfaces.get(CP1),
adaptor.getMatchingInterface(IpAddress.valueOf("192.168.1.100")));
assertEquals(this.interfaces.get(CP2),
adaptor.getMatchingInterface(IpAddress.valueOf("192.168.2.100")));
assertEquals(this.interfaces.get(CP3),
adaptor.getMatchingInterface(IpAddress.valueOf("192.168.3.100")));
assertEquals(this.interfaces.get(CP3),
adaptor.getMatchingInterface(IpAddress.valueOf("192.168.4.100")));
// Try and match an address we don't have subnet configured for
assertNull(adaptor.getMatchingInterface(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests {@link HostToInterfaceAdaptor#getMatchingInterface(IpAddress)} in the
* case that the input IP address is null.
* Verifies that a NullPointerException is thrown.
*/
@Test(expected = NullPointerException.class)
public void testGetMatchingInterfaceNull() {
adaptor.getMatchingInterface(null);
}
}
......@@ -25,7 +25,6 @@ import org.onosproject.net.ElementId;
import org.onosproject.net.Port;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.group.Group;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.topology.TopologyCluster;
import java.util.Comparator;
......@@ -113,13 +112,6 @@ public final class Comparators {
}
};
public static final Comparator<PortAddresses> ADDRESSES_COMPARATOR = new Comparator<PortAddresses>() {
@Override
public int compare(PortAddresses arg0, PortAddresses arg1) {
return CONNECT_POINT_COMPARATOR.compare(arg0.connectPoint(), arg1.connectPoint());
}
};
public static final Comparator<Interface> INTERFACES_COMPARATOR = (intf1, intf2) ->
CONNECT_POINT_COMPARATOR.compare(intf1.connectPoint(), intf2.connectPoint());
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.cli.net;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cli.Comparators;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* Lists all configured address port bindings.
*/
@Command(scope = "onos", name = "address-bindings",
description = "Lists all configured address port bindings.")
public class AddressBindingsListCommand extends AbstractShellCommand {
private static final String FORMAT =
"port=%s/%s, ip(s)=%s, mac=%s, vlan=%s";
@Override
protected void execute() {
HostService hostService = get(HostService.class);
List<PortAddresses> addresses =
Lists.newArrayList(hostService.getAddressBindings());
Collections.sort(addresses, Comparators.ADDRESSES_COMPARATOR);
for (PortAddresses pa : addresses) {
print(FORMAT, pa.connectPoint().deviceId(), pa.connectPoint().port(),
printIpAddresses(pa.ipAddresses()), pa.mac(), pa.vlan());
}
}
private String printIpAddresses(Set<InterfaceIpAddress> addresses) {
StringBuilder output = new StringBuilder("[");
for (InterfaceIpAddress address : addresses) {
output.append(address.ipAddress().toString());
output.append("/");
output.append(address.subnetAddress().prefixLength());
output.append(", ");
}
// Remove the last comma
output.delete(output.length() - 2 , output.length());
output.append("]");
return output.toString();
}
}
......@@ -331,9 +331,6 @@
</completers>
</command>
<command>
<action class="org.onosproject.cli.net.AddressBindingsListCommand"/>
</command>
<command>
<action class="org.onosproject.cli.net.InterfacesListCommand"/>
</command>
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.host;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.HostId;
/**
......@@ -30,37 +29,4 @@ public interface HostAdminService extends HostService {
*/
void removeHost(HostId hostId);
/**
* Binds IP and MAC addresses to the given connection point.
* <p>
* The addresses are added to the set of addresses already bound to the
* connection point.
*
* @param addresses address object containing addresses to add and the port
* to add them to
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void bindAddressesToPort(PortAddresses addresses);
/**
* Removes the addresses contained in the given PortAddresses object from
* the set of addresses bound to the port.
*
* @param portAddresses set of addresses to remove and port to remove them
* from
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void unbindAddressesFromPort(PortAddresses portAddresses);
/**
* Removes all address information for the given connection point.
*
* @param connectPoint the connection point to remove address information
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void clearAddresses(ConnectPoint connectPoint);
}
......
......@@ -123,24 +123,4 @@ public interface HostService
*/
void requestMac(IpAddress ip);
/**
* Returns the addresses information for all connection points.
*
* @return the set of address bindings for all connection points
* @deprecated in Drake release: use InterfaceService instead
*/
@Deprecated
Set<PortAddresses> getAddressBindings();
/**
* Retrieves the addresses that have been bound to the given connection
* point.
*
* @param connectPoint the connection point to retrieve address bindings for
* @return addresses bound to the port
* @deprecated in Drake release: use InterfaceService instead
*/
@Deprecated
Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint);
}
......
......@@ -115,53 +115,4 @@ public interface HostStore extends Store<HostEvent, HostStoreDelegate> {
*/
Set<Host> getConnectedHosts(DeviceId deviceId);
/**
* Updates the address information for a given port. The given address
* information is added to any previously held information for the port.
*
* @param addresses the port and address information
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void updateAddressBindings(PortAddresses addresses);
/**
* Removes the given addresses from the set of address information held for
* a port.
*
* @param addresses the port and address information
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void removeAddressBindings(PortAddresses addresses);
/**
* Removes any previously stored address information for a given connection
* point.
*
* @param connectPoint the connection point
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
void clearAddressBindings(ConnectPoint connectPoint);
/**
* Returns the address bindings stored for all connection points.
*
* @return the set of address bindings
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
Set<PortAddresses> getAddressBindings();
/**
* Returns the address bindings for a particular connection point.
*
* @param connectPoint the connection point to return address information
* for
* @return address information for the connection point
* @deprecated in Drake release: address info now stored in InterfaceService
*/
@Deprecated
Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint);
}
......
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.host;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import com.google.common.base.MoreObjects;
/**
* Represents address information bound to a port.
*/
public final class PortAddresses {
private final ConnectPoint connectPoint;
private final Set<InterfaceIpAddress> ipAddresses;
private final MacAddress macAddress;
private final VlanId vlan;
/**
* Constructs a PortAddresses object for the given connection point, with a
* set of IP addresses and a MAC address. Both address parameters are
* optional and can be set to null.
*
* @param connectPoint the connection point these addresses are for
* @param ipAddresses a set of interface IP addresses
* @param mac a MAC address
* @param vlan a VLAN ID
*/
public PortAddresses(ConnectPoint connectPoint,
Set<InterfaceIpAddress> ipAddresses, MacAddress mac, VlanId vlan) {
this.connectPoint = connectPoint;
this.ipAddresses = (ipAddresses == null) ?
Collections.<InterfaceIpAddress>emptySet()
: new HashSet<>(ipAddresses);
this.macAddress = mac;
this.vlan = vlan;
}
/**
* Returns the connection point this address information is bound to.
*
* @return the connection point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Returns the set of interface IP addresses.
*
* @return the interface IP addresses
*/
public Set<InterfaceIpAddress> ipAddresses() {
return ipAddresses;
}
/**
* Returns the MAC address.
*
* @return the MAC address
*/
public MacAddress mac() {
return macAddress;
}
/**
* Returns the VLAN ID.
*
* @return the VLAN ID
*/
public VlanId vlan() {
return vlan;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof PortAddresses)) {
return false;
}
PortAddresses otherPa = (PortAddresses) other;
return Objects.equals(this.connectPoint, otherPa.connectPoint)
&& Objects.equals(this.ipAddresses, otherPa.ipAddresses)
&& Objects.equals(this.macAddress, otherPa.macAddress)
&& Objects.equals(this.vlan, otherPa.vlan);
}
@Override
public int hashCode() {
return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("connect-point", connectPoint)
.add("ip-addresses", ipAddresses)
.add("mac-address", macAddress)
.add("vlan", vlan)
.toString();
}
}
......@@ -15,15 +15,15 @@
*/
package org.onosproject.net.host;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import java.util.Set;
/**
* Test adapter for host service.
......@@ -89,14 +89,4 @@ public class HostServiceAdapter implements HostService {
public void removeListener(HostListener listener) {
}
@Override
public Set<PortAddresses> getAddressBindings() {
return null;
}
@Override
public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
return null;
}
}
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.host;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.NetTestTools;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit tests for port addresses class.
*/
public class PortAddressesTest {
PortAddresses addresses1;
PortAddresses sameAsAddresses1;
PortAddresses addresses2;
PortAddresses addresses3;
private static final ConnectPoint CONNECT_POINT1 =
NetTestTools.connectPoint("cp1", 1);
private static final IpAddress IP_ADDRESS1 = IpAddress.valueOf("1.2.3.4");
private static final IpPrefix SUBNET_ADDRESS1 =
IpPrefix.valueOf("1.2.0.0/16");
private static final InterfaceIpAddress INTERFACE_ADDRESS_1 =
new InterfaceIpAddress(IP_ADDRESS1, SUBNET_ADDRESS1);
private static final ConnectPoint CONNECT_POINT2 =
NetTestTools.connectPoint("cp2", 1);
private static final IpAddress IP_ADDRESS2 = IpAddress.valueOf("1.2.3.5");
private static final IpPrefix SUBNET_ADDRESS2 =
IpPrefix.valueOf("1.3.0.0/16");
private static final InterfaceIpAddress INTERFACE_ADDRESS_2 =
new InterfaceIpAddress(IP_ADDRESS2, SUBNET_ADDRESS2);
Set<InterfaceIpAddress> ipAddresses;
/**
* Initializes local data used by all test cases.
*/
@Before
public void setUpAddresses() {
ipAddresses = ImmutableSet.of(INTERFACE_ADDRESS_1,
INTERFACE_ADDRESS_2);
addresses1 = new PortAddresses(CONNECT_POINT1, ipAddresses,
MacAddress.BROADCAST, VlanId.NONE);
sameAsAddresses1 = new PortAddresses(CONNECT_POINT1, ipAddresses,
MacAddress.BROADCAST, VlanId.NONE);
addresses2 = new PortAddresses(CONNECT_POINT2, ipAddresses,
MacAddress.BROADCAST, VlanId.NONE);
addresses3 = new PortAddresses(CONNECT_POINT2, ipAddresses,
MacAddress.ZERO, VlanId.NONE);
}
/**
* Checks that the PortAddresses class is immutable.
*/
@Test
public void testImmutability() {
assertThatClassIsImmutable(PortAddresses.class);
}
/**
* Checks the operation of the equals(), hash() and toString()
* methods.
*/
@Test
public void testEquals() {
new EqualsTester()
.addEqualityGroup(addresses1, sameAsAddresses1)
.addEqualityGroup(addresses2)
.addEqualityGroup(addresses3)
.testEquals();
}
/**
* Tests that object are created correctly.
*/
@Test
public void testConstruction() {
assertThat(addresses1.mac(), is(MacAddress.BROADCAST));
assertThat(addresses1.connectPoint(), is(CONNECT_POINT1));
assertThat(addresses1.ipAddresses(), is(ipAddresses));
assertThat(addresses1.vlan(), is(VlanId.NONE));
}
}
......@@ -15,23 +15,16 @@
*/
package org.onosproject.store.trivial;
import static org.onosproject.net.DefaultAnnotations.merge;
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
......@@ -44,19 +37,21 @@ import org.onosproject.net.host.HostDescription;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.AbstractStore;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static org.onosproject.net.DefaultAnnotations.merge;
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED;
import static org.slf4j.LoggerFactory.getLogger;
// TODO: multi-provider, annotation not supported.
/**
......@@ -77,10 +72,6 @@ public class SimpleHostStore
// Hosts tracked by their location
private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
private final SetMultimap<ConnectPoint, PortAddresses> portAddresses =
Multimaps.synchronizedSetMultimap(
HashMultimap.<ConnectPoint, PortAddresses>create());
@Activate
public void activate() {
log.info("Started");
......@@ -224,41 +215,6 @@ public class SimpleHostStore
return hostset;
}
@Override
public void updateAddressBindings(PortAddresses addresses) {
portAddresses.put(addresses.connectPoint(), addresses);
}
@Override
public void removeAddressBindings(PortAddresses addresses) {
portAddresses.remove(addresses.connectPoint(), addresses);
}
@Override
public void clearAddressBindings(ConnectPoint connectPoint) {
portAddresses.removeAll(connectPoint);
}
@Override
public Set<PortAddresses> getAddressBindings() {
synchronized (portAddresses) {
return ImmutableSet.copyOf(portAddresses.values());
}
}
@Override
public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
synchronized (portAddresses) {
Set<PortAddresses> addresses = portAddresses.get(connectPoint);
if (addresses == null) {
return Collections.emptySet();
} else {
return ImmutableSet.copyOf(addresses);
}
}
}
// Auxiliary extension to allow location to mutate.
private static final class StoredHost extends DefaultHost {
private HostLocation location;
......
......@@ -46,7 +46,6 @@ import org.onosproject.net.host.HostProviderService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
......@@ -199,33 +198,6 @@ public class HostManager
}
}
@Override
public void bindAddressesToPort(PortAddresses addresses) {
store.updateAddressBindings(addresses);
}
@Override
public void unbindAddressesFromPort(PortAddresses portAddresses) {
store.removeAddressBindings(portAddresses);
}
@Override
public void clearAddresses(ConnectPoint connectPoint) {
store.clearAddressBindings(connectPoint);
}
@Override
public Set<PortAddresses> getAddressBindings() {
checkPermission(HOST_READ);
return store.getAddressBindings();
}
@Override
public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
checkPermission(HOST_READ);
return store.getAddressBindingsForPort(connectPoint);
}
// Personalized host provider service issued to the supplied provider.
private class InternalHostProviderService
extends AbstractProviderService<HostProvider>
......
......@@ -43,7 +43,6 @@ import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.host.HostProvider;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketServiceAdapter;
import org.onosproject.net.provider.ProviderId;
......@@ -140,8 +139,6 @@ public class HostMonitorTest {
deviceService.addDevice(device, Collections.singleton(port));
ConnectPoint cp = new ConnectPoint(devId, portNum);
PortAddresses pa =
new PortAddresses(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE);
expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
.andReturn(Collections.emptySet()).anyTimes();
......@@ -211,9 +208,6 @@ public class HostMonitorTest {
deviceService.addDevice(device, Collections.singleton(port));
ConnectPoint cp = new ConnectPoint(devId, portNum);
PortAddresses pa =
new PortAddresses(cp, Collections.singleton(IA1), sourceMac,
VlanId.vlanId(vlan));
expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
.andReturn(Collections.emptySet()).anyTimes();
......
......@@ -25,7 +25,6 @@ import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.RE
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
......@@ -52,7 +51,6 @@ import org.onosproject.net.host.HostDescription;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.host.HostEvent.Type;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.AbstractStore;
......@@ -93,10 +91,6 @@ public class ECHostStore
Multimaps.synchronizedSetMultimap(
HashMultimap.<ConnectPoint, Host>create());
private final SetMultimap<ConnectPoint, PortAddresses> portAddresses =
Multimaps.synchronizedSetMultimap(
HashMultimap.<ConnectPoint, PortAddresses>create());
private EventuallyConsistentMap<HostId, DefaultHost> hosts;
private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker =
......@@ -123,7 +117,6 @@ public class ECHostStore
hosts.removeListener(hostLocationTracker);
hosts.destroy();
locations.clear();
portAddresses.clear();
log.info("Stopped");
}
......@@ -199,34 +192,6 @@ public class ECHostStore
.collect(Collectors.toSet());
}
@Override
public void updateAddressBindings(PortAddresses addresses) {
portAddresses.put(addresses.connectPoint(), addresses);
}
@Override
public void removeAddressBindings(PortAddresses addresses) {
portAddresses.remove(addresses.connectPoint(), addresses);
}
@Override
public void clearAddressBindings(ConnectPoint connectPoint) {
portAddresses.removeAll(connectPoint);
}
@Override
public Set<PortAddresses> getAddressBindings() {
return ImmutableSet.copyOf(portAddresses.values());
}
@Override
public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
synchronized (portAddresses) {
Set<PortAddresses> addresses = portAddresses.get(connectPoint);
return addresses == null ? Collections.emptySet() : ImmutableSet.copyOf(addresses);
}
}
private Set<Host> filter(Collection<DefaultHost> collection, Predicate<DefaultHost> predicate) {
return collection.stream().filter(predicate).collect(Collectors.toSet());
}
......