From b731e2f1dd0972409b136aebc7b463dd72c9cfad Mon Sep 17 00:00:00 2001 From: CNlucius Date: Tue, 13 Sep 2016 11:40:12 +0800 Subject: ONOSFW-171 O/S-SFC-ONOS scenario documentation Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365 Signed-off-by: CNlucius --- framework/src/onos/providers/netcfghost/pom.xml | 65 ------- .../netcfghost/NetworkConfigHostProvider.java | 196 --------------------- .../provider/netcfghost/package-info.java | 20 --- .../netcfghost/NetworkConfigHostProviderTest.java | 132 -------------- 4 files changed, 413 deletions(-) delete mode 100644 framework/src/onos/providers/netcfghost/pom.xml delete mode 100644 framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java delete mode 100644 framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/package-info.java delete mode 100644 framework/src/onos/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java (limited to 'framework/src/onos/providers/netcfghost') diff --git a/framework/src/onos/providers/netcfghost/pom.xml b/framework/src/onos/providers/netcfghost/pom.xml deleted file mode 100644 index 9d106921..00000000 --- a/framework/src/onos/providers/netcfghost/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - onos-providers - org.onosproject - 1.4.0-rc1 - - 4.0.0 - - onos-netcfg-host-provider - bundle - - - Host provider that uses network config service to discover hosts. - - http://onosproject.org - - - org.onosproject.netcfghostprovider - ON.Lab - - - - - org.onosproject - onos-api - - - - org.onosproject - onlab-osgi - - - - junit - junit - 4.11 - test - - - - org.easymock - easymock - test - - - - diff --git a/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java b/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java deleted file mode 100644 index 767cfb7f..00000000 --- a/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/NetworkConfigHostProvider.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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.provider.netcfghost; - -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.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.VlanId; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.config.basics.BasicHostConfig; -import org.onosproject.net.host.DefaultHostDescription; -import org.onosproject.net.host.HostDescription; -import org.onosproject.net.host.HostProvider; -import org.onosproject.net.host.HostProviderRegistry; -import org.onosproject.net.host.HostProviderService; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.util.Set; - -/** - * Host provider that uses network config service to discover hosts. - */ -@Component(immediate = true) -public class NetworkConfigHostProvider extends AbstractProvider implements HostProvider { - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostProviderRegistry providerRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry networkConfigRegistry; - - private static final String APP_NAME = "org.onosproject.provider.netcfghost"; - private ApplicationId appId; - protected HostProviderService providerService; - - private final Logger log = LoggerFactory.getLogger(getClass()); - private final InternalNetworkConfigListener networkConfigListener = - new InternalNetworkConfigListener(); - - /** - * Creates an network config host location provider. - */ - public NetworkConfigHostProvider() { - super(new ProviderId("host", APP_NAME)); - } - - @Activate - protected void activate() { - appId = coreService.registerApplication(APP_NAME); - providerService = providerRegistry.register(this); - networkConfigRegistry.addListener(networkConfigListener); - readInitialConfig(); - log.info("Started"); - } - - @Deactivate - protected void deactivate() { - networkConfigRegistry.removeListener(networkConfigListener); - providerRegistry.unregister(this); - providerService = null; - log.info("Stopped"); - } - - @Override - public void triggerProbe(Host host) { - /* - * Note: In CORD deployment, we assume that all hosts are configured. - * Therefore no probe is required. - */ - } - - /** - * Adds host information. - * IP information will be appended if host exists. - * - * @param mac MAC address of the host - * @param vlan VLAN ID of the host - * @param hloc Location of the host - * @param ips Set of IP addresses of the host - */ - protected void addHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set ips) { - HostId hid = HostId.hostId(mac, vlan); - HostDescription desc = new DefaultHostDescription(mac, vlan, hloc, ips); - providerService.hostDetected(hid, desc, false); - } - - /** - * Updates host information. - * IP information will be replaced if host exists. - * - * @param mac MAC address of the host - * @param vlan VLAN ID of the host - * @param hloc Location of the host - * @param ips Set of IP addresses of the host - */ - protected void updateHost(MacAddress mac, VlanId vlan, HostLocation hloc, Set ips) { - HostId hid = HostId.hostId(mac, vlan); - HostDescription desc = new DefaultHostDescription(mac, vlan, hloc, ips); - providerService.hostDetected(hid, desc, true); - } - - /** - * Removes host information. - * - * @param mac MAC address of the host - * @param vlan VLAN ID of the host - */ - protected void removeHost(MacAddress mac, VlanId vlan) { - HostId hid = HostId.hostId(mac, vlan); - providerService.hostVanished(hid); - } - - private void readInitialConfig() { - networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> { - MacAddress mac = hostId.mac(); - VlanId vlan = hostId.vlanId(); - BasicHostConfig hostConfig = - networkConfigRegistry.getConfig(hostId, BasicHostConfig.class); - Set ipAddresses = hostConfig.ipAddresses(); - ConnectPoint location = hostConfig.location(); - HostLocation hloc = new HostLocation(location, System.currentTimeMillis()); - addHost(mac, vlan, hloc, ipAddresses); - }); - } - - private class InternalNetworkConfigListener implements NetworkConfigListener { - @Override - public void event(NetworkConfigEvent event) { - // Do not process non-host, register and unregister events - if (!event.configClass().equals(BasicHostConfig.class) || - event.type() == NetworkConfigEvent.Type.CONFIG_REGISTERED || - event.type() == NetworkConfigEvent.Type.CONFIG_UNREGISTERED) { - return; - } - - HostId hostId = (HostId) event.subject(); - MacAddress mac = hostId.mac(); - VlanId vlan = hostId.vlanId(); - BasicHostConfig hostConfig = - networkConfigRegistry.getConfig(hostId, BasicHostConfig.class); - Set ipAddresses = null; - HostLocation hloc = null; - - // Note: There will be no config presented in the CONFIG_REMOVE case - if (hostConfig != null) { - ipAddresses = hostConfig.ipAddresses(); - ConnectPoint location = hostConfig.location(); - hloc = new HostLocation(location, System.currentTimeMillis()); - } - - switch (event.type()) { - case CONFIG_ADDED: - addHost(mac, vlan, hloc, ipAddresses); - break; - case CONFIG_UPDATED: - updateHost(mac, vlan, hloc, ipAddresses); - break; - case CONFIG_REMOVED: - removeHost(mac, vlan); - break; - default: - break; - } - } - } -} diff --git a/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/package-info.java b/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/package-info.java deleted file mode 100644 index a56b9a80..00000000 --- a/framework/src/onos/providers/netcfghost/src/main/java/org/onosproject/provider/netcfghost/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/** - * Host provider that uses network config service to discover hosts. - */ -package org.onosproject.provider.netcfghost; diff --git a/framework/src/onos/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java b/framework/src/onos/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java deleted file mode 100644 index a4f057cf..00000000 --- a/framework/src/onos/providers/netcfghost/src/test/java/org/onosproject/provider/netcfghost/NetworkConfigHostProviderTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.provider.netcfghost; - -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.VlanId; -import org.onosproject.net.DeviceId; -import org.onosproject.net.HostId; -import org.onosproject.net.HostLocation; -import org.onosproject.net.PortNumber; -import org.onosproject.net.host.DefaultHostDescription; -import org.onosproject.net.host.HostDescription; -import org.onosproject.net.host.HostProvider; -import org.onosproject.net.host.HostProviderService; -import org.onosproject.net.provider.AbstractProviderService; - -import java.util.HashSet; -import java.util.Set; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - -/** - * Set of tests of the host location provider for CORD. - */ -public class NetworkConfigHostProviderTest { - private NetworkConfigHostProvider provider = new NetworkConfigHostProvider(); - private MockHostProviderService providerService = new MockHostProviderService(provider); - - private MacAddress mac = MacAddress.valueOf("c0:ff:ee:c0:ff:ee"); - private VlanId vlan = VlanId.vlanId(VlanId.UNTAGGED); - private DeviceId deviceId = DeviceId.deviceId("of:0000000000000001"); - private PortNumber port = PortNumber.portNumber(5); - private HostLocation hloc = new HostLocation(deviceId, port, 100); - private Set ips = new HashSet<>(); - private HostId hostId = HostId.hostId(mac, vlan); - private HostDescription hostDescription; - - @Before - public void setUp() { - provider.providerService = providerService; - - // Initialize test variables - ips.add(IpAddress.valueOf("10.0.0.1")); - ips.add(IpAddress.valueOf("192.168.0.1")); - hostDescription = new DefaultHostDescription(mac, vlan, hloc, ips); - } - - @Test - public void testAddHost() throws Exception { - provider.addHost(mac, vlan, hloc, ips); - assertThat(providerService.hostId, is(hostId)); - assertThat(providerService.hostDescription, is(hostDescription)); - assertThat(providerService.event, is("hostDetected")); - providerService.clear(); - } - - @Test - public void testUpdateHost() throws Exception { - provider.updateHost(mac, vlan, hloc, ips); - assertThat(providerService.hostId, is(hostId)); - assertThat(providerService.hostDescription, is(hostDescription)); - assertThat(providerService.event, is("hostDetected")); - providerService.clear(); - } - - @Test - public void testRemoveHost() throws Exception { - provider.removeHost(mac, vlan); - assertThat(providerService.hostId, is(hostId)); - assertNull(providerService.hostDescription); - assertThat(providerService.event, is("hostVanished")); - providerService.clear(); - } - - /** - * Mock HostProviderService. - */ - private class MockHostProviderService - extends AbstractProviderService - implements HostProviderService { - private HostId hostId = null; - private HostDescription hostDescription = null; - private String event = null; - - public MockHostProviderService(HostProvider provider) { - super(provider); - } - - @Override - public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { - this.hostId = hostId; - this.hostDescription = hostDescription; - this.event = "hostDetected"; - } - - @Override - public void hostVanished(HostId hostId) { - this.hostId = hostId; - this.event = "hostVanished"; - } - - @Override - public void removeIpFromHost(HostId hostId, IpAddress ipAddress) { - // Note: This method is never used. - } - - public void clear() { - this.hostId = null; - this.hostDescription = null; - this.event = null; - } - } -} -- cgit 1.2.3-korg