diff options
Diffstat (limited to 'framework/src/onos/apps/vtn')
66 files changed, 2146 insertions, 2185 deletions
diff --git a/framework/src/onos/apps/vtn/app/pom.xml b/framework/src/onos/apps/vtn/app/pom.xml index 4ed66172..5a877363 100644 --- a/framework/src/onos/apps/vtn/app/pom.xml +++ b/framework/src/onos/apps/vtn/app/pom.xml @@ -1,44 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Copyright 2014 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. --> +<!-- ~ Copyright 2014 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. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-onosfw</artifactId> - <packaging>pom</packaging> + <artifactId>onos-app-vtn-onosfw</artifactId> + <packaging>pom</packaging> - <description>ONOS framework applications</description> + <description>ONOS framework applications</description> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-rsc</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-web</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-mgr</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-rsc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-web</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-mgr</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/pom.xml b/framework/src/onos/apps/vtn/pom.xml index e91b0c9b..a42f91a0 100644 --- a/framework/src/onos/apps/vtn/pom.xml +++ b/framework/src/onos/apps/vtn/pom.xml @@ -32,6 +32,7 @@ <description>ONOS framework applications</description> <modules> + <module>sfcmgr</module> <module>vtnrsc</module> <module>vtnmgr</module> <module>vtnweb</module> @@ -53,5 +54,25 @@ <artifactId>easymock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onlab-osgi</artifactId> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-servlet</artifactId> + </dependency> + <dependency> + <groupId>com.sun.jersey.jersey-test-framework</groupId> + <artifactId>jersey-test-framework-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey.jersey-test-framework</groupId> + <artifactId>jersey-test-framework-grizzly2</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java deleted file mode 100644 index a2748f5e..00000000 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.sfc; - -import org.onosproject.vtnrsc.PortChain; - -/** - * SFC application that applies flows to the device. - */ -public interface SfcService { - /** - * Applies flow classification to OVS. - * - * @param portChain Port-Chain. - */ - void InstallFlowClassification(PortChain portChain); - - - /** - * Remove flow classification from OVS. - * - * @param portChain Port-Chain. - */ - void UnInstallFlowClassification(PortChain portChain); - - /** - * Applies Service Function chain to OVS. - * - * @param portChain Port-Chain. - */ - void InstallServiceFunctionChain(PortChain portChain); - - /** - * Remove Service Function chain from OVS. - * - * @param portChain Port-Chain. - */ - void UnInstallServiceFunctionChain(PortChain portChain); -} diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java deleted file mode 100644 index 1872295f..00000000 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.sfc.impl; - -import static org.slf4j.LoggerFactory.getLogger; - -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.onosproject.vtnrsc.sfc.PortChain; -import org.slf4j.Logger; - -/** - * Provides implementation of SFC Service. - */ -@Component(immediate = true) -@Service -public class SfcManager implements SfcService { - - private final Logger log = getLogger(SfcManager.class); - - @Activate - public void activate() { - log.info("Started"); - } - - @Deactivate - public void deactivate() { - log.info("Stopped"); - } - - @Override - public void InstallFlowClassification(PortChain portChain) { - log.debug("InstallFlowClassification"); - //TODO: Installation of flow classification into OVS. - } - - @Override - public void UnInstallFlowClassification(PortChain portChain) { - log.debug("UnInstallFlowClassification"); - //TODO: Un-installation flow classification from OVS - } - - @Override - public void InstallServiceFunctionChain(PortChain portChain) { - log.debug("InstallServiceFunctionChain"); - //TODO: Installation of Service Function chain into OVS. - } - - @Override - public void UnInstallServiceFunctionChain(PortChain portChain) { - log.debug("UnInstallServiceFunctionChain"); - //TODO: Un-installation of Service Function chain from OVS. - } -} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java deleted file mode 100644 index a20f852b..00000000 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.vtn; - -import org.onosproject.net.Device; -import org.onosproject.net.Host; - -/** - * VTN application that applies configuration and flows to the device. - */ -public interface VTNService { - - /** - * Creates a vxlan tunnel and creates the ovs when a ovs controller node is detected. - * - * @param device controller-type device - */ - void onServerDetected(Device device); - - /** - * Drops a vxlan tunnel and drops the ovs when a ovs controller node is vanished. - * - * @param device controller-type device - */ - void onServerVanished(Device device); - - /** - * Applies default forwarding flows when a ovs is detected. - * - * @param device switch-type device - */ - void onOvsDetected(Device device); - - /** - * Remove default forwarding flows when a ovs is vanished. - * - * @param device switch-type device - */ - void onOvsVanished(Device device); - - /** - * Applies multicast flows and tunnel flows when a VM is detected. - * - * @param host a VM - */ - void onHostDetected(Host host); - - /** - * Remove multicast flows and tunnel flows when a VM is vanished. - * - * @param host a VM - */ - void onHostVanished(Host host); - -} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java deleted file mode 100644 index 090ef0f1..00000000 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java +++ /dev/null @@ -1,672 +0,0 @@ -/* - * 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.vtn.impl; - -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; -import static org.onlab.util.Tools.groupedThreads; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; -import java.util.stream.Collectors; - -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.apache.felix.scr.annotations.Service; -import org.onlab.osgi.DefaultServiceDirectory; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.util.KryoNamespace; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.BridgeConfig; -import org.onosproject.net.behaviour.BridgeDescription; -import org.onosproject.net.behaviour.BridgeName; -import org.onosproject.net.behaviour.DefaultTunnelDescription; -import org.onosproject.net.behaviour.IpTunnelEndPoint; -import org.onosproject.net.behaviour.Pipeliner; -import org.onosproject.net.behaviour.PipelinerContext; -import org.onosproject.net.behaviour.TunnelConfig; -import org.onosproject.net.behaviour.TunnelDescription; -import org.onosproject.net.behaviour.TunnelEndPoint; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.FlowRuleService; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criteria; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.FlowObjectiveStore; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.onosproject.net.flowobjective.ForwardingObjective.Flag; -import org.onosproject.net.flowobjective.Objective; -import org.onosproject.net.host.HostEvent; -import org.onosproject.net.host.HostListener; -import org.onosproject.net.host.HostService; -import org.onosproject.store.serializers.KryoNamespaces; -import org.onosproject.store.service.EventuallyConsistentMap; -import org.onosproject.store.service.StorageService; -import org.onosproject.store.service.WallClockTimestamp; -import org.onosproject.vtn.VTNService; -import org.onosproject.vtnrsc.SegmentationId; -import org.onosproject.vtnrsc.TenantNetwork; -import org.onosproject.vtnrsc.VirtualPort; -import org.onosproject.vtnrsc.VirtualPortId; -import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; -import org.onosproject.vtnrsc.virtualport.VirtualPortService; -import org.slf4j.Logger; - -import com.google.common.collect.Sets; - -/** - * Provides implementation of VTNService. - */ -@Component(immediate = true) -@Service -public class VTNManager implements VTNService { - private final Logger log = getLogger(getClass()); - - private static final String APP_ID = "org.onosproject.app.vtn"; - private ScheduledExecutorService backgroundService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostService hostService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowRuleService flowRuleService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected StorageService storageService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TenantNetworkService tenantNetworkService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected VirtualPortService virtualPortService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DriverService driverService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveStore flowObjectiveStore; - protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); - private EventuallyConsistentMap<HostId, SegmentationId> binding; - private ApplicationId appId; - private HostListener hostListener = new InnerHostListener(); - private DeviceListener deviceListener = new InnerDeviceListener(); - private static final String IFACEID = "ifaceid"; - private static final String PORT_HEAD = "vxlan"; - private static final String DEFAULT_BRIDGE_NAME = "br-int"; - private static final String CONTROLLER_IP_KEY = "ipaddress"; - private static final int DEFAULT_MAC_PRIORITY = 0x0000; - private static final int MAC_PRIORITY = 0xffff; - private static final int DEFAULT_PORT_PRIORITY = 0x0000; - private static final int PORT_PRIORITY = 0xffff; - private static final String SWITCH_CHANNEL_ID = "channelId"; - private static final String DRIVER_NAME = "onosfw"; - - @Activate - public void activate() { - KryoNamespace.Builder serializer = KryoNamespace.newBuilder() - .register(KryoNamespaces.API); - appId = coreService.registerApplication(APP_ID); - deviceService.addListener(deviceListener); - hostService.addListener(hostListener); - backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn", - "manager-background")); - binding = storageService - .<HostId, SegmentationId>eventuallyConsistentMapBuilder() - .withName("all_tunnel").withSerializer(serializer) - .withTimestampProvider((k, v) -> new WallClockTimestamp()) - .build(); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - backgroundService.shutdown(); - binding.destroy(); - log.info("Stopped"); - } - - @Override - public void onServerDetected(Device device) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - DriverHandler handler = driverService.createHandler(device.id()); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); - IpAddress ip = IpAddress.valueOf(ipAddress); - Sets.newHashSet(devices).stream() - .filter(d -> Device.Type.CONTROLLER == d.type()) - .filter(d -> !device.id().equals(d.id())).forEach(d -> { - String ipAddress1 = d.annotations() - .value(CONTROLLER_IP_KEY); - IpAddress ip1 = IpAddress.valueOf(ipAddress1); - applyTunnelConfig(ip, ip1, handler); - DriverHandler handler1 = driverService - .createHandler(d.id()); - applyTunnelConfig(ip1, ip, handler1); - - }); - } - - @Override - public void onServerVanished(Device device) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); - IpAddress dst = IpAddress.valueOf(ipAddress); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER) - .filter(d -> !device.id().equals(d.id())).forEach(d -> { - String ipAddress1 = d.annotations() - .value(CONTROLLER_IP_KEY); - DriverHandler handler = driverService.createHandler(d.id()); - IpAddress src = IpAddress.valueOf(ipAddress1); - removeTunnelConfig(src, dst, handler); - }); - } - - private void applyTunnelConfig(IpAddress src, IpAddress dst, - DriverHandler handler) { - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); - TunnelDescription tunnel = new DefaultTunnelDescription( - tunnelAsSrc, - tunnelAsDst, - TunnelDescription.Type.VXLAN, - null); - TunnelConfig config = handler.behaviour(TunnelConfig.class); - config.createTunnel(tunnel); - } - - private void removeTunnelConfig(IpAddress src, IpAddress dst, - DriverHandler handler) { - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); - TunnelDescription tunnel = new DefaultTunnelDescription( - tunnelAsSrc, - tunnelAsDst, - TunnelDescription.Type.VXLAN, - null); - TunnelConfig config = handler.behaviour(TunnelConfig.class); - config.removeTunnel(tunnel); - } - - @Override - public void onOvsDetected(Device device) { - programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); - programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); - } - - @Override - public void onOvsVanished(Device device) { - programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE); - programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE); - } - - @Override - public void onHostDetected(Host host) { - String ifaceId = host.annotations().value(IFACEID); - DeviceId deviceId = host.location().deviceId(); - String currentControllerIp = getControllerIpOfSwitch(deviceId); - Iterable<Device> devices = deviceService.getAvailableDevices(); - VirtualPortId portId = VirtualPortId.portId(ifaceId); - VirtualPort port = virtualPortService.getPort(portId); - TenantNetwork network = tenantNetworkService - .getNetwork(port.networkId()); - String tunnelName = "vxlan-" + currentControllerIp; - binding.put(host.id(), network.segmentationId()); - List<Port> allPorts = deviceService.getPorts(deviceId); - PortNumber inPort = host.location().port(); - List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); - List<PortNumber> localTunnelPorts = new ArrayList<>(); - Sets.newHashSet(allPorts.iterator()).stream() - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { - if (p.annotations().value("portName").startsWith(PORT_HEAD)) { - localTunnelPorts.add(p.number()); - } - }); - - localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, network.segmentationId(), lp, localVmPorts, - localTunnelPorts, appId, Objective.Operation.ADD)); - programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), - appId, Objective.Operation.ADD); - localTunnelPorts - .forEach(tp -> programTunnelFloodOut(deviceId, - network.segmentationId(), - tp, localVmPorts, - appId, - Objective.Operation.ADD)); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { - DriverHandler handler = driverService.createHandler(d.id()); - BridgeConfig bridgeConfig = handler - .behaviour(BridgeConfig.class); - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig - .getBridges(); - - Iterator<BridgeDescription> it = bridgeDescriptions - .iterator(); - if (it.hasNext()) { - BridgeDescription sw = it.next(); - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); - ports.stream() - .filter(p -> p.name() - .equalsIgnoreCase(tunnelName)) - .forEach(p -> programTunnelOut(sw.deviceId(), - network.segmentationId(), p, - host.mac(), appId, - Objective.Operation.ADD)); - } - }); - programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), - appId, Objective.Operation.ADD); - localTunnelPorts - .forEach(tp -> programTunnelIn(deviceId, - network.segmentationId(), - tp, inPort, host.mac(), - appId, Objective.Operation.ADD)); - - } - - @Override - public void onHostVanished(Host host) { - String ifaceId = host.annotations().value(IFACEID); - SegmentationId segId = binding.remove(host.id()); - DeviceId deviceId = host.location().deviceId(); - String currentControllerIp = getControllerIpOfSwitch(deviceId); - Iterable<Device> devices = deviceService.getAvailableDevices(); - - String tunnelName = "vxlan-" + currentControllerIp; - List<Port> allPorts = deviceService.getPorts(deviceId); - PortNumber inPort = host.location().port(); - - List<PortNumber> localTunnelPorts = new ArrayList<>(); - Sets.newHashSet(allPorts.iterator()).stream() - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { - if (p.annotations().value("portName").startsWith(PORT_HEAD)) { - localTunnelPorts.add(p.number()); - } - }); - - List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); - localVmPorts.add(inPort); - localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, segId, lp, localVmPorts, - localTunnelPorts, appId, Objective.Operation.REMOVE)); - programLocalOut(deviceId, segId, inPort, host.mac(), - appId, Objective.Operation.REMOVE); - localTunnelPorts - .forEach(tp -> programTunnelFloodOut(deviceId, - segId, - tp, localVmPorts, - appId, - Objective.Operation.REMOVE)); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { - DriverHandler handler = driverService.createHandler(d.id()); - BridgeConfig bridgeConfig = handler - .behaviour(BridgeConfig.class); - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig - .getBridges(); - - Iterator<BridgeDescription> it = bridgeDescriptions - .iterator(); - if (it.hasNext()) { - BridgeDescription sw = it.next(); - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); - ports.stream() - .filter(p -> p.name() - .equalsIgnoreCase(tunnelName)) - .forEach(p -> programTunnelOut(sw.deviceId(), - segId, p, - host.mac(), appId, - Objective.Operation.REMOVE)); - } - }); - programLocalIn(deviceId, segId, inPort, host.mac(), - appId, Objective.Operation.REMOVE); - localTunnelPorts - .forEach(tp -> programTunnelIn(deviceId, - segId, - tp, inPort, host.mac(), - appId, Objective.Operation.REMOVE)); - } - - private class InnerDeviceListener implements DeviceListener { - - @Override - public void event(DeviceEvent event) { - Device device = event.subject(); - if (Device.Type.CONTROLLER == device.type() - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { - backgroundService.execute(() -> onServerDetected(device)); - } else if (Device.Type.CONTROLLER == device.type() - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event - .type()) { - backgroundService.execute(() -> onServerVanished(device)); - } else if (Device.Type.SWITCH == device.type() - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { - backgroundService.execute(() -> onOvsDetected(device)); - } else if (Device.Type.SWITCH == device.type() - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event - .type()) { - backgroundService.execute(() -> onOvsVanished(device)); - } else { - log.info("Do nothing for this device type"); - } - } - - } - - private class InnerHostListener implements HostListener { - - @Override - public void event(HostEvent event) { - Host host = event.subject(); - if (HostEvent.Type.HOST_ADDED == event.type()) { - backgroundService.execute(() -> onHostDetected(host)); - } else if (HostEvent.Type.HOST_REMOVED == event.type()) { - backgroundService.execute(() -> onHostVanished(host)); - } else if (HostEvent.Type.HOST_UPDATED == event.type()) { - backgroundService.execute(() -> { - onHostVanished(host); - onHostDetected(host); - }); - } - } - - } - - // Used to forward the flows to the local VM. - private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, - PortNumber outPort, MacAddress sourceMac, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchTunnelId(Long.parseLong(segmentationId.toString())) - .matchEthDst(sourceMac).build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder() - .setOutput(outPort).build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).withFlag(Flag.SPECIFIC) - .withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - - } - - // Used to forward the flows into the VXLAN tunnel. - private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, - PortNumber tunnelOutPort, MacAddress dstMac, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder() - - .setOutput(tunnelOutPort).build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).withFlag(Flag.SPECIFIC) - .withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - - } - - // Used to forward multicast flows to remote VMs of the same tenant via - // VXLAN tunnel. - private void programTunnelFloodOut(DeviceId deviceId, - SegmentationId segmentationId, - PortNumber ofPortOut, - List<PortNumber> localVmPorts, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(ofPortOut) - - .add(Criteria.matchTunnelId(Long.parseLong(segmentationId - .toString()))).matchEthDst(MacAddress.BROADCAST) - .build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - - for (PortNumber outPort : localVmPorts) { - treatment.setOutput(outPort); - } - - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(deviceId, objective.add()); - } else { - flowServiceForward(deviceId, objective.remove()); - } - } - - // Applies default flows to mac table. - private void programMacDefaultRules(DeviceId dpid, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder().build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop() - .build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(DEFAULT_MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to forward the flows to the local VMs with the same tenant. - private void programLocalBcastRules(DeviceId deviceId, - SegmentationId segmentationId, - PortNumber inPort, - List<PortNumber> localVmPorts, - List<PortNumber> localTunnelPorts, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) - .add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - for (PortNumber outPort : localVmPorts) { - if (inPort != outPort) { - treatment.setOutput(outPort); - } - } - for (PortNumber outport : localTunnelPorts) { - treatment.setOutput(outport); - } - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(deviceId, objective.add()); - } else { - flowServiceForward(deviceId, objective.remove()); - } - } - - // Used to apply local entry flow. - private void programLocalIn(DeviceId dpid, SegmentationId segmentationId, - PortNumber inPort, MacAddress srcMac, - ApplicationId appid, Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(inPort).matchEthSrc(srcMac).build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId - .toString()))); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to forward the flows from the egress tunnel to the VM. - private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, - PortNumber tunnelInPort, PortNumber outPort, - MacAddress sourceMac, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); - - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Applies the default flows to port table. - private void programPortDefaultRules(DeviceId dpid, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder().build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(DEFAULT_PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to get channelId from the device annotations. - private String getControllerIpOfSwitch(DeviceId deviceId) { - Device device = deviceService.getDevice(deviceId); - String url = device.annotations().value(SWITCH_CHANNEL_ID); - return url.substring(0, url.lastIndexOf(":")); - } - - private Iterable<String> getIfaceIds(String ifaceId) { - VirtualPortId portId = VirtualPortId.portId(ifaceId); - VirtualPort port = virtualPortService.getPort(portId); - if (port == null) { - return Collections.emptyList(); - } - - TenantNetwork network = tenantNetworkService - .getNetwork(port.networkId()); - if (network == null) { - return Collections.emptyList(); - } - - Collection<VirtualPort> ports = virtualPortService - .getPorts(network.id()); - return ports.stream().map(p -> p.portId().portId()) - .collect(Collectors.toSet()); - } - - private List<PortNumber> getLocalPorts(DeviceId deviceId, String ifaceId) { - DriverHandler handler = driverService - .createHandler(getController(deviceId)); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - Iterable<String> ifaceIds = getIfaceIds(ifaceId); - return bridgeConfig.getLocalPorts(ifaceIds); - } - - private DeviceId getController(DeviceId deviceId) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - for (Device device : devices) { - if (device.type() == Device.Type.CONTROLLER && device.id() - .toString().contains(getControllerIpOfSwitch(deviceId))) { - return device.id(); - } - } - log.info("Can not find controller for device : {}", deviceId); - return null; - } - - //Used to apply flowRule - private void flowServiceForward(DeviceId deviceId, ForwardingObjective forwardingObjective) { - Driver driver = driverService.getDriver(DRIVER_NAME); - Pipeliner pipeLiner = driver.createBehaviour(new DefaultDriverData(driver, deviceId), Pipeliner.class); - if (pipeLiner != null) { - final PipelinerContext context = new InnerPipelineContext(); - pipeLiner.init(deviceId, context); - pipeLiner.forward(forwardingObjective); - } - } - - // Processing context for initializing pipeline driver behaviours. - private class InnerPipelineContext implements PipelinerContext { - @Override - public ServiceDirectory directory() { - return serviceDirectory; - } - - @Override - public FlowObjectiveStore store() { - return flowObjectiveStore; - } - } - -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/pom.xml b/framework/src/onos/apps/vtn/vtnrsc/pom.xml index 8696295c..816624cb 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/pom.xml +++ b/framework/src/onos/apps/vtn/vtnrsc/pom.xml @@ -15,42 +15,42 @@ ~ limitations under the License. --> <project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-rsc</artifactId> - <packaging>bundle</packaging> + <artifactId>onos-app-vtn-rsc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-core-serializers</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-api</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-cli</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-core-serializers</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java index c715d08a..7dca32de 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java @@ -49,7 +49,7 @@ public final class BindingHostId { @Override public int hashCode() { - return Objects.hash(bindingHostId); + return bindingHostId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java index 39df2cff..7915ce08 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java @@ -43,6 +43,8 @@ public final class DefaultFlowClassifier implements FlowClassifier { private static final int NULL_PORT = 0; private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "FlowClassifier id can not be null."; private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null."; + private static final String NAME_NOT_NULL = "Name can not be null."; + private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null."; /** * Constructor to create default flow classifier. @@ -160,11 +162,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { private FlowClassifierId flowClassifierId; private TenantId tenantId; private String name; - private boolean isFlowClassifierNameSet = false; private String description; private boolean isFlowClassifierDescriptionSet = false; private String etherType; - private boolean isEtherTypeSet = false; private String protocol; private boolean isProtocolSet = false; private int minSrcPortRange; @@ -189,9 +189,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { checkNotNull(flowClassifierId, FLOW_CLASSIFIER_ID_NOT_NULL); checkNotNull(tenantId, TENANT_ID_NOT_NULL); - String name = null; + checkNotNull(name, NAME_NOT_NULL); + checkNotNull(etherType, ETHER_TYPE_NOT_NULL); String description = null; - String etherType = null; String protocol = null; int minSrcPortRange = NULL_PORT; int maxSrcPortRange = NULL_PORT; @@ -202,15 +202,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { VirtualPortId srcPort = null; VirtualPortId dstPort = null; - if (isFlowClassifierNameSet) { - name = this.name; - } if (isFlowClassifierDescriptionSet) { description = this.description; } - if (isEtherTypeSet) { - etherType = this.etherType; - } if (isProtocolSet) { protocol = this.protocol; } @@ -259,7 +253,6 @@ public final class DefaultFlowClassifier implements FlowClassifier { @Override public Builder setName(String name) { this.name = name; - this.isFlowClassifierNameSet = true; return this; } @@ -273,7 +266,6 @@ public final class DefaultFlowClassifier implements FlowClassifier { @Override public Builder setEtherType(String etherType) { this.etherType = etherType; - this.isEtherTypeSet = true; return this; } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java index b789abe3..df180ebe 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java @@ -15,6 +15,8 @@ */ package org.onosproject.vtnrsc; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.MoreObjects; import java.util.UUID; @@ -33,6 +35,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id. */ private FlowClassifierId(final UUID flowClassifierId) { + checkNotNull(flowClassifierId, "Flow classifier id can not be null"); this.flowClassifierId = flowClassifierId; } @@ -42,7 +45,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) { + public static FlowClassifierId of(final UUID flowClassifierId) { return new FlowClassifierId(flowClassifierId); } @@ -52,7 +55,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final String flowClassifierId) { + public static FlowClassifierId of(final String flowClassifierId) { return new FlowClassifierId(UUID.fromString(flowClassifierId)); } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java index e96e666a..30631d28 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java @@ -53,7 +53,7 @@ public final class PhysicalNetwork { @Override public int hashCode() { - return Objects.hash(physicalNetwork); + return physicalNetwork.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java index 66edbdcc..a42a700f 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Chain ID. @@ -40,22 +39,22 @@ public final class PortChainId { } /** - * Constructor to create port chain id from UUID. + * Returns newly created port chain id object. * * @param id UUID of port chain * @return object of port chain id */ - public static PortChainId portChainId(UUID id) { + public static PortChainId of(UUID id) { return new PortChainId(id); } /** - * Constructor to create port chain id from string. + * Returns newly created port chain id object. * * @param id port chain id in string * @return object of port chain id */ - public static PortChainId portChainId(String id) { + public static PortChainId of(String id) { return new PortChainId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortChainId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortChainId that = (PortChainId) obj; - return Objects.equal(this.portChainId, that.portChainId); + if (obj instanceof PortChainId) { + final PortChainId other = (PortChainId) obj; + return Objects.equals(this.portChainId, other.portChainId); } return false; } @@ -88,8 +86,6 @@ public final class PortChainId { @Override public String toString() { - return toStringHelper(this) - .add("portChainId", portChainId.toString()) - .toString(); + return toStringHelper(this).add("portChainId", portChainId).toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java index 0474901c..a52a2bb3 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Pair Group ID. @@ -40,22 +39,22 @@ public final class PortPairGroupId { } /** - * Constructor to create port pair group id from UUID. + * Returns newly created port pair group id object. * - * @param id UUID of port pair group id + * @param id port pair group id in UUID * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(UUID id) { + public static PortPairGroupId of(UUID id) { return new PortPairGroupId(id); } /** - * Constructor to create port pair group id from string. + * Returns newly created port pair group id object. * * @param id port pair group id in string * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(String id) { + public static PortPairGroupId of(String id) { return new PortPairGroupId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairGroupId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairGroupId that = (PortPairGroupId) obj; - return Objects.equal(this.portPairGroupId, that.portPairGroupId); + if (obj instanceof PortPairGroupId) { + final PortPairGroupId other = (PortPairGroupId) obj; + return Objects.equals(this.portPairGroupId, other.portPairGroupId); } return false; } @@ -88,8 +86,7 @@ public final class PortPairGroupId { @Override public String toString() { - return toStringHelper(this) - .add("portPairGroupId", portPairGroupId.toString()) + return toStringHelper(this).add("portPairGroupId", portPairGroupId) .toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java index 05c31aac..1f45e80e 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Pair ID. @@ -40,22 +39,22 @@ public final class PortPairId { } /** - * Constructor to create port pair id from UUID. + * Returns newly created port pair id object. * * @param id UUID of port pair id * @return object of port pair id */ - public static PortPairId portPairId(UUID id) { + public static PortPairId of(UUID id) { return new PortPairId(id); } /** - * Constructor to create port pair id from string. + * Returns newly created port pair id object. * * @param id port pair id in string * @return object of port pair id */ - public static PortPairId portPairId(String id) { + public static PortPairId of(String id) { return new PortPairId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairId that = (PortPairId) obj; - return Objects.equal(this.portPairId, that.portPairId); + if (obj instanceof PortPairId) { + final PortPairId other = (PortPairId) obj; + return Objects.equals(this.portPairId, other.portPairId); } return false; } @@ -89,7 +87,7 @@ public final class PortPairId { @Override public String toString() { return toStringHelper(this) - .add("portPairId", portPairId.toString()) + .add("portPairId", portPairId) .toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java new file mode 100644 index 00000000..e853ec2f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java @@ -0,0 +1,102 @@ +/*
+ * 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.vtnrsc;
+
+import java.util.List;
+
+/**
+ * Representation of a Router.
+ */
+public interface Router {
+
+ /**
+ * Coarse classification of the type of the Router.
+ */
+ public enum Status {
+ /**
+ * Signifies that a router is currently active.
+ */
+ ACTIVE,
+ /**
+ * Signifies that a router is currently inactive.
+ */
+ INACTIVE
+ }
+
+ /**
+ * Returns the router identifier.
+ *
+ * @return identifier
+ */
+ RouterId id();
+
+ /**
+ * Returns the router Name.
+ *
+ * @return routerName
+ */
+ String name();
+
+ /**
+ * Returns the router admin state.
+ *
+ * @return true or false
+ */
+ boolean adminStateUp();
+
+ /**
+ * Returns the status of router.
+ *
+ * @return RouterStatus
+ */
+ Status status();
+
+ /**
+ * Returns the distributed status of this router.
+ * If true, indicates a distributed router.
+ *
+ * @return true or false
+ */
+ boolean distributed();
+
+ /**
+ * Returns the RouterGateway of router.
+ *
+ * @return routerGateway
+ */
+ RouterGateway externalGatewayInfo();
+
+ /**
+ * Returns the gatewayPortid of router.
+ *
+ * @return virtualPortId
+ */
+ VirtualPortId gatewayPortid();
+
+ /**
+ * Returns the owner(tenant) of this router.
+ *
+ * @return tenantId
+ */
+ TenantId tenantId();
+
+ /**
+ * Returns the router list of router.
+ *
+ * @return routes
+ */
+ List<String> routes();
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java new file mode 100644 index 00000000..9a755561 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java @@ -0,0 +1,108 @@ +/*
+ * 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.vtnrsc;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * Representation of a Router gateway.
+ */
+public final class RouterGateway {
+
+ private final TenantNetworkId networkId;
+ private final boolean enableSnat;
+ private final Collection<FixedIp> externalFixedIps;
+
+ // Public construction is prohibited
+ private RouterGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ this.networkId = checkNotNull(networkId, "networkId cannot be null");
+ this.enableSnat = checkNotNull(enableSnat, "enableSnat cannot be null");
+ this.externalFixedIps = checkNotNull(externalFixedIps, "externalFixedIps cannot be null");
+ }
+
+ /**
+ * Creates router gateway object.
+ *
+ * @param networkId network identifier
+ * @param enableSnat SNAT enable or not
+ * @param externalFixedIps external fixed IP
+ * @return RouterGateway
+ */
+ public static RouterGateway routerGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ return new RouterGateway(networkId, enableSnat, externalFixedIps);
+ }
+
+ /**
+ * Returns network identifier.
+ *
+ * @return networkId
+ */
+ public TenantNetworkId networkId() {
+ return networkId;
+ }
+
+ /**
+ * Return SNAT enable or not.
+ *
+ * @return enableSnat
+ */
+ public boolean enableSnat() {
+ return enableSnat;
+ }
+
+ /**
+ * Return external fixed Ip.
+ *
+ * @return externalFixedIps
+ */
+ public Collection<FixedIp> externalFixedIps() {
+ return externalFixedIps;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkId, enableSnat, externalFixedIps);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof RouterGateway) {
+ final RouterGateway that = (RouterGateway) obj;
+ return Objects.equals(this.networkId, that.networkId)
+ && Objects.equals(this.enableSnat, that.enableSnat)
+ && Objects.equals(this.externalFixedIps, that.externalFixedIps);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("networkId", networkId)
+ .add("enableSnat", enableSnat)
+ .add("externalFixedIps", externalFixedIps)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java new file mode 100644 index 00000000..d396c0d1 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java @@ -0,0 +1,77 @@ +/* + * 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.vtnrsc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * Immutable representation of a router identifier. + */ +public final class RouterId { + + private final String routerId; + + // Public construction is prohibited + private RouterId(String routerId) { + checkNotNull(routerId, "routerId cannot be null"); + this.routerId = routerId; + } + + /** + * Creates a router identifier. + * + * @param routerId the router identifier + * @return the router identifier + */ + public static RouterId valueOf(String routerId) { + return new RouterId(routerId); + } + + /** + * Returns the router identifier. + * + * @return the router identifier + */ + public String routerId() { + return routerId; + } + + @Override + public int hashCode() { + return routerId.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof RouterId) { + final RouterId that = (RouterId) obj; + return Objects.equals(this.routerId, that.routerId); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("routerId", routerId).toString(); + } +} + diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java index 9ec1dc63..33ddcbfe 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java @@ -52,7 +52,7 @@ public final class SecurityGroup { @Override public int hashCode() { - return Objects.hash(securityGroup); + return securityGroup.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java index a076265f..651ebd89 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java @@ -53,7 +53,7 @@ public final class SegmentationId { @Override public int hashCode() { - return Objects.hash(segmentationId); + return segmentationId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java index 4bcc3329..eb93d153 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java @@ -53,7 +53,7 @@ public final class SubnetId { @Override public int hashCode() { - return Objects.hash(subnetId); + return subnetId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java index c4d99e49..0e7c9417 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java @@ -53,7 +53,7 @@ public final class TenantId { @Override public int hashCode() { - return Objects.hash(tenantId); + return tenantId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java index fbb9e480..8680d28f 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java @@ -52,7 +52,7 @@ public final class TenantNetworkId { @Override public int hashCode() { - return Objects.hash(networkId); + return networkId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java index 3038bdff..a3863483 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java @@ -46,7 +46,7 @@ public final class VirtualPortId { @Override public int hashCode() { - return Objects.hash(portId); + return portId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java index e379be81..c160d221 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.flowClassifier; +package org.onosproject.vtnrsc.flowclassifier; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; @@ -69,4 +69,4 @@ public interface FlowClassifierService { * @return true if Flow Classifier removal is success otherwise return false. */ boolean removeFlowClassifier(FlowClassifierId id); -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java index 7238558a..ee5873d6 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java @@ -13,23 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.flowClassifier.impl; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +package org.onosproject.vtnrsc.flowclassifier.impl; 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.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; import org.onosproject.vtnrsc.FlowClassifierId; import org.onosproject.vtnrsc.FlowClassifier; -import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; - +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; +import static org.slf4j.LoggerFactory.getLogger; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; /** @@ -44,16 +49,26 @@ public class FlowClassifierManager implements FlowClassifierService { private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; - private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore - = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>(); + private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; @Activate private void activate() { + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(FlowClassifier.class); + flowClassifierStore = storageService + .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() + .withName("flowclassifierstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); log.info("Flow Classifier service activated"); } @Deactivate private void deactivate() { + flowClassifierStore.destroy(); log.info("Flow Classifier service deactivated"); } @@ -92,7 +107,8 @@ public class FlowClassifierManager implements FlowClassifierService { public boolean updateFlowClassifier(FlowClassifier flowClassifier) { checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); FlowClassifierId id = flowClassifier.flowClassifierId(); - return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier); + flowClassifierStore.put(id, flowClassifier); + return true; } @Override @@ -105,4 +121,4 @@ public class FlowClassifierManager implements FlowClassifierService { } return true; } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java index 4ea050b3..62b5603d 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java @@ -17,4 +17,4 @@ /** * Provides implementation of the flow Classifier service. */ -package org.onosproject.vtnrsc.flowClassifier.impl; +package org.onosproject.vtnrsc.flowclassifier.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java index 07584170..c8c75bf3 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java @@ -17,4 +17,4 @@ /** * Service for interacting with flow Classifier of SFC. */ -package org.onosproject.vtnrsc.flowClassifier; +package org.onosproject.vtnrsc.flowclassifier; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java new file mode 100644 index 00000000..5201a2ca --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portchain.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.portchain.PortChainService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portChainService. + */ +@Component(immediate = true) +@Service +public class PortChainManager implements PortChainService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_CHAIN_ID_NULL = "PortChain ID cannot be null"; + private static final String PORT_CHAIN_NULL = "PortChain cannot be null"; + + private EventuallyConsistentMap<PortChainId, PortChain> portChainStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortChain.class); + + portChainStore = storageService + .<PortChainId, PortChain>eventuallyConsistentMapBuilder() + .withName("portchainstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portChainStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.containsKey(portChainId); + } + + @Override + public int getPortChainCount() { + return portChainStore.size(); + } + + @Override + public Iterable<PortChain> getPortChains() { + return Collections.unmodifiableCollection(portChainStore.values()); + } + + @Override + public PortChain getPortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.get(portChainId); + } + + @Override + public boolean createPortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + portChainStore.put(portChain.portChainId(), portChain); + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is created failed which identifier was {}", portChain.portChainId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is not exist whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + + portChainStore.put(portChain.portChainId(), portChain); + + if (!portChain.equals(portChainStore.get(portChain.portChainId()))) { + log.debug("The portChain is updated failed whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_NULL); + + portChainStore.remove(portChainId); + if (portChainStore.containsKey(portChainId)) { + log.debug("The portChain is removed failed whose identifier was {}", + portChainId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java index 0dba868c..424d54ab 100644 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * SFC Service manager for interacting with SFC. + * Implementation of service for interacting with the inventory of port chains. */ -package org.onosproject.sfc.impl; +package org.onosproject.vtnrsc.portchain.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java new file mode 100644 index 00000000..f99cc2cf --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java @@ -0,0 +1,80 @@ +/* + * 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.vtnrsc.portpair; + +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; + +/** + * Service for interacting with the inventory of port pairs. + */ +public interface PortPairService { + + /** + * Returns if the port pair is existed. + * + * @param portPairId port pair identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(PortPairId portPairId); + + /** + * Returns the number of port pairs known to the system. + * + * @return number of port pairs. + */ + int getPortPairCount(); + + /** + * Returns an iterable collection of the currently known port pairs. + * + * @return collection of port pairs. + */ + Iterable<PortPair> getPortPairs(); + + /** + * Returns the portPair with the given identifier. + * + * @param portPairId port pair identifier + * @return PortPair or null if port pair with the given identifier is not + * known. + */ + PortPair getPortPair(PortPairId portPairId); + + /** + * Creates a PortPair in the store. + * + * @param portPair the port pair to create + * @return true if given port pair is created successfully. + */ + boolean createPortPair(PortPair portPair); + + /** + * Updates the portPair in the store. + * + * @param portPair the port pair to update + * @return true if given port pair is updated successfully. + */ + boolean updatePortPair(PortPair portPair); + + /** + * Deletes portPair by given portPairId. + * + * @param portPairId id of port pair to remove + * @return true if the give port pair is deleted successfully. + */ + boolean removePortPair(PortPairId portPairId); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java new file mode 100644 index 00000000..93c8782a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portpair.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.portpair.PortPairService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairService. + */ +@Component(immediate = true) +@Service +public class PortPairManager implements PortPairService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null"; + private static final String PORT_PAIR_NULL = "PortPair cannot be null"; + + private EventuallyConsistentMap<PortPairId, PortPair> portPairStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPair.class); + + portPairStore = storageService + .<PortPairId, PortPair>eventuallyConsistentMapBuilder() + .withName("portpairstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.containsKey(portPairId); + } + + @Override + public int getPortPairCount() { + return portPairStore.size(); + } + + @Override + public Iterable<PortPair> getPortPairs() { + return Collections.unmodifiableCollection(portPairStore.values()); + } + + @Override + public PortPair getPortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.get(portPairId); + } + + @Override + public boolean createPortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + portPairStore.put(portPair.portPairId(), portPair); + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is created failed which identifier was {}", portPair.portPairId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is not exist whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + + portPairStore.put(portPair.portPairId(), portPair); + + if (!portPair.equals(portPairStore.get(portPair.portPairId()))) { + log.debug("The portPair is updated failed whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_NULL); + + portPairStore.remove(portPairId); + if (portPairStore.containsKey(portPairId)) { + log.debug("The portPair is removed failed whose identifier was {}", + portPairId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java index f18dbf8a..625fbdd4 100644 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * VTN application that applies configuration and flows to the device. + * Implementation of service for interacting with the inventory of port pairs. */ -package org.onosproject.vtn.impl; +package org.onosproject.vtnrsc.portpair.impl; diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java index 371466c3..e2c61531 100644 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java @@ -15,6 +15,6 @@ */ /** - * VTN application that applies configuration and flows to the device. + * Service for interacting with the inventory of port pairs. */ -package org.onosproject.vtn; +package org.onosproject.vtnrsc.portpair; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java new file mode 100644 index 00000000..55fb4e43 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portpairgroup.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.apache.felix.scr.annotations.Service; +import org.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairGroupService. + */ +@Component(immediate = true) +@Service +public class PortPairGroupManager implements PortPairGroupService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; + private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; + + private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPairGroup.class); + + portPairGroupStore = storageService + .<PortPairGroupId, PortPairGroup>eventuallyConsistentMapBuilder() + .withName("portpairgroupstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairGroupStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.containsKey(portPairGroupId); + } + + @Override + public int getPortPairGroupCount() { + return portPairGroupStore.size(); + } + + @Override + public Iterable<PortPairGroup> getPortPairGroups() { + return Collections.unmodifiableCollection(portPairGroupStore.values()); + } + + @Override + public PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.get(portPairGroupId); + } + + @Override + public boolean createPortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is created failed which identifier was {}", portPairGroup.portPairGroupId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is not exist whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + + if (!portPairGroup.equals(portPairGroupStore.get(portPairGroup.portPairGroupId()))) { + log.debug("The portPairGroup is updated failed whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.remove(portPairGroupId); + if (portPairGroupStore.containsKey(portPairGroupId)) { + log.debug("The portPairGroup is removed failed whose identifier was {}", + portPairGroupId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java index 1dcb9929..68c186bc 100644 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * Service for interacting with SFC. + * Implementation of service for interacting with the inventory of port pair groups. */ -package org.onosproject.sfc; +package org.onosproject.vtnrsc.portpairgroup.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java deleted file mode 100644 index 34636a9f..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/** - * Codecs for virtual tenant objects. - */ -package org.onosproject.vtnrsc.web; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java deleted file mode 100644 index b2fed347..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.vtnrsc.flowclassifier; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.FlowClassifierId; - -import com.google.common.testing.EqualsTester; -import java.util.UUID; - -/** - * Unit tests for FlowClassifierId class. - */ -public class FlowClassifierIdTest { - - final FlowClassifierId flowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - final FlowClassifierId flowClassifierId2 = FlowClassifierId - .flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); - - /** - * Checks that the FlowClassifierId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(FlowClassifierId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(flowClassifierId1, sameAsFlowClassifierId1) - .addEqualityGroup(flowClassifierId2).testEquals(); - } - - /** - * Checks the construction of a FlowClassifierId object. - */ - @Test - public void testConstruction() { - final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; - final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue); - assertThat(flowClassifierId, is(notNullValue())); - assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue))); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java deleted file mode 100644 index 4ce4def2..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onosproject.vtnrsc.AllocationPool; -import org.onosproject.vtnrsc.DefaultAllocationPool; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultAllocationPool class. - */ -public class DefaultAllocationPoolTest { - - final IpAddress startIP1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress startIP2 = IpAddress.valueOf("192.168.1.2"); - final IpAddress endIP1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress endIP2 = IpAddress.valueOf("192.168.1.2"); - - /** - * Checks that the DefaultAllocationPool class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultAllocationPool.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - AllocationPool pool1 = new DefaultAllocationPool(startIP1, endIP1); - AllocationPool pool2 = new DefaultAllocationPool(startIP1, endIP1); - AllocationPool pool3 = new DefaultAllocationPool(startIP2, endIP2); - new EqualsTester().addEqualityGroup(pool1, pool2) - .addEqualityGroup(pool3).testEquals(); - } - - /** - * Checks the construction of a DefaultAllocationPool object. - */ - @Test - public void testConstruction() { - final AllocationPool apool = new DefaultAllocationPool(startIP1, endIP1); - assertThat(startIP1, is(apool.startIp())); - assertThat(endIP1, is(apool.endIp())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java deleted file mode 100644 index 2f751742..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onosproject.vtnrsc.DefaultHostRoute; -import org.onosproject.vtnrsc.HostRoute; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultHostRoute class. - */ -public class DefaultHostRouteTest { - final IpAddress nexthop1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress nexthop2 = IpAddress.valueOf("192.168.1.2"); - final IpPrefix destination1 = IpPrefix.valueOf("1.1.1.1/1"); - final IpPrefix destination2 = IpPrefix.valueOf("1.1.1.1/2"); - - /** - * Checks that the DefaultHostRoute class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultHostRoute.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - HostRoute route1 = new DefaultHostRoute(nexthop1, destination1); - HostRoute route2 = new DefaultHostRoute(nexthop1, destination1); - HostRoute route3 = new DefaultHostRoute(nexthop2, destination2); - new EqualsTester().addEqualityGroup(route1, route2) - .addEqualityGroup(route3).testEquals(); - } - - /** - * Checks the construction of a DefaultHostRoute object. - */ - @Test - public void testConstruction() { - final HostRoute host = new DefaultHostRoute(nexthop1, destination1); - assertThat(nexthop1, is(host.nexthop())); - assertThat(destination1, is(host.destination())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java deleted file mode 100644 index d18dd41a..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SubnetId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SubnetId class. - */ -public class SubnetIdTest { - - final SubnetId subnetId1 = SubnetId.subnetId("1"); - final SubnetId sameAsSubnetId1 = SubnetId.subnetId("1"); - final SubnetId subnetId2 = SubnetId.subnetId("2"); - - /** - * Checks that the SubnetId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SubnetId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(subnetId1, sameAsSubnetId1).addEqualityGroup(subnetId2) - .testEquals(); - } - - /** - * Checks the construction of a SubnetId object. - */ - @Test - public void testConstruction() { - final String subnetIdValue = "s"; - final SubnetId subnetId = SubnetId.subnetId(subnetIdValue); - assertThat(subnetId, is(notNullValue())); - assertThat(subnetId.subnetId(), is(subnetIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java deleted file mode 100644 index 742d5933..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.vtnrsc.tenantnetwork; - -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.DefaultTenantNetwork; -import org.onosproject.vtnrsc.PhysicalNetwork; -import org.onosproject.vtnrsc.SegmentationId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.TenantNetwork; -import org.onosproject.vtnrsc.TenantNetworkId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultNeutronNetwork class. - */ -public class DefaultNeutronNetworkTest { - - private String networkIdStr1 = "123"; - private String networkIdStr2 = "234"; - private String physicalNetworkStr = "1234"; - private String tenantIdStr = "345"; - private String segmentationIdStr = "1"; - private String name = "456"; - - /** - * Checks that the DefaultNeutronNetwork class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultTenantNetwork.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquality() { - TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr1); - TenantNetworkId networkid2 = TenantNetworkId.networkId(networkIdStr2); - PhysicalNetwork physicalNetwork = PhysicalNetwork - .physicalNetwork(physicalNetworkStr); - TenantId tenantId = TenantId.tenantId(tenantIdStr); - SegmentationId segmentationID = SegmentationId - .segmentationId(segmentationIdStr); - TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - TenantNetwork p2 = new DefaultTenantNetwork(networkid1, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - TenantNetwork p3 = new DefaultTenantNetwork(networkid2, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) - .testEquals(); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java deleted file mode 100644 index e101795e..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.PhysicalNetwork; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for PhysicalNetwork class. - */ -public class PhysicalNetworkTest { - - final PhysicalNetwork physicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); - final PhysicalNetwork sameAsPhysicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); - final PhysicalNetwork physicalNetwork2 = PhysicalNetwork.physicalNetwork("2"); - - /** - * Checks that the PhysicalNetwork class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(PhysicalNetwork.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(physicalNetwork1, sameAsPhysicalNetwork1) - .addEqualityGroup(physicalNetwork2).testEquals(); - } - - /** - * Checks the construction of a PhysicalNetwork object. - */ - @Test - public void testConstruction() { - final String physicalNetworkValue = "s"; - final PhysicalNetwork physicalNetwork = PhysicalNetwork - .physicalNetwork(physicalNetworkValue); - assertThat(physicalNetwork, is(notNullValue())); - assertThat(physicalNetwork.physicalNetwork(), is(physicalNetworkValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java deleted file mode 100644 index dea7baf6..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SegmentationId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SegmentationId class. - */ -public class SegmentationIdTest { - - final SegmentationId segmentationID1 = SegmentationId.segmentationId("1"); - final SegmentationId sameAsSegmentationID1 = SegmentationId.segmentationId("1"); - final SegmentationId segmentationID2 = SegmentationId.segmentationId("2"); - - /** - * Checks that the SegmentationId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SegmentationId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(segmentationID1, sameAsSegmentationID1) - .addEqualityGroup(segmentationID2).testEquals(); - } - - /** - * Checks the construction of a segmentationId object. - */ - @Test - public void testConstruction() { - final String segmentationIdValue = "s"; - final SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdValue); - assertThat(segmentationId, is(notNullValue())); - assertThat(segmentationId.segmentationId(), is(segmentationIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java deleted file mode 100644 index e9216383..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.TenantId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for TenantId class. - */ -public class TenantIdTest { - - final TenantId tenantId1 = TenantId.tenantId("1"); - final TenantId sameAsTenantId1 = TenantId.tenantId("1"); - final TenantId tenantId2 = TenantId.tenantId("2"); - - /** - * Checks that the TenantId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(TenantId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(tenantId1, sameAsTenantId1).addEqualityGroup(tenantId2) - .testEquals(); - } - - /** - * Checks the construction of a TenantId object. - */ - @Test - public void testConstruction() { - final String tenantIdValue = "s"; - final TenantId tenantId = TenantId.tenantId(tenantIdValue); - assertThat(tenantId, is(notNullValue())); - assertThat(tenantId.tenantId(), is(tenantIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java deleted file mode 100644 index 8271b51c..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.TenantNetworkId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for TenantNetworkId class. - */ -public class TenantNetworkIdTest { - - final TenantNetworkId networkId1 = TenantNetworkId.networkId("1"); - final TenantNetworkId sameAsnetworkId1 = TenantNetworkId.networkId("1"); - final TenantNetworkId networkId2 = TenantNetworkId.networkId("2"); - - /** - * Checks that the TenantNetworkId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(TenantNetworkId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(networkId1, sameAsnetworkId1) - .addEqualityGroup(networkId2).testEquals(); - } - - /** - * Checks the construction of a TenantNetworkId object. - */ - @Test - public void testConstruction() { - final String networkIdValue = "s"; - final TenantNetworkId networkId = TenantNetworkId.networkId(networkIdValue); - assertThat(networkId, is(notNullValue())); - assertThat(networkId.networkId(), is(networkIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java deleted file mode 100644 index dabe5896..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onosproject.vtnrsc.AllowedAddressPair; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for AllowedAddressPair class. - */ -public class AllowedAddressPairTest { - - final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); - final IpAddress ip2 = IpAddress.valueOf("192.168.0.2"); - final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:76:83:88"); - final MacAddress mac2 = MacAddress.valueOf("aa:16:3e:76:83:88"); - - /** - * Checks that the AllowedAddressPair class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(AllowedAddressPair.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - AllowedAddressPair p1 = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - AllowedAddressPair p2 = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - AllowedAddressPair p3 = AllowedAddressPair - .allowedAddressPair(ip2, mac2); - new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) - .testEquals(); - } - - /** - * Checks the construction of a AllowedAddressPair object. - */ - @Test - public void testConstruction() { - AllowedAddressPair allowedAddressPair = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - assertThat(ip1, is(notNullValue())); - assertThat(ip1, is(allowedAddressPair.ip())); - assertThat(mac1, is(notNullValue())); - assertThat(mac1, is(allowedAddressPair.mac())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java deleted file mode 100644 index 8a0c8004..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.vtnrsc.virtualport; - -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import java.util.Map; -import java.util.Set; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onosproject.net.DeviceId; -import org.onosproject.vtnrsc.AllowedAddressPair; -import org.onosproject.vtnrsc.BindingHostId; -import org.onosproject.vtnrsc.DefaultVirtualPort; -import org.onosproject.vtnrsc.FixedIp; -import org.onosproject.vtnrsc.SecurityGroup; -import org.onosproject.vtnrsc.SubnetId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.TenantNetworkId; -import org.onosproject.vtnrsc.VirtualPort; -import org.onosproject.vtnrsc.VirtualPortId; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultVirtualPort class. - */ -public class DefaultVirtualPortTest { - - private Set<FixedIp> fixedIps; - private Map<String, String> propertyMap; - private Set<AllowedAddressPair> allowedAddressPairs; - private Set<SecurityGroup> securityGroups; - private VirtualPortId id1; - private VirtualPortId id2; - private String macAddressStr = "fa:12:3e:56:ee:a2"; - private String ipAddress = "10.1.1.1"; - private String deviceStr = "of:000000000000001"; - private String tenantIdStr = "123"; - private String portId1 = "1241"; - private String portId2 = "1242"; - private String tenantNetworkId = "1234567"; - private String subnet = "1212"; - private String hostIdStr = "fa:e2:3e:56:ee:a2"; - - private void initVirtualPortId() { - id1 = VirtualPortId.portId(portId1); - id2 = VirtualPortId.portId(portId2); - } - - private void initFixedIpSet() { - FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet), - IpAddress.valueOf(ipAddress)); - fixedIps = Sets.newHashSet(); - fixedIps.add(fixedIp); - } - - private void initPropertyMap() { - String deviceOwner = "james"; - propertyMap = Maps.newHashMap(); - propertyMap.putIfAbsent("deviceOwner", deviceOwner); - } - - private void initAddressPairSet() { - allowedAddressPairs = Sets.newHashSet(); - AllowedAddressPair allowedAddressPair = AllowedAddressPair - .allowedAddressPair(IpAddress.valueOf(ipAddress), - MacAddress.valueOf(macAddressStr)); - allowedAddressPairs.add(allowedAddressPair); - } - - private void initSecurityGroupSet() { - securityGroups = Sets.newHashSet(); - } - - /** - * Checks that the DefaultVirtualPort class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SecurityGroup.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - initVirtualPortId(); - initFixedIpSet(); - initPropertyMap(); - initAddressPairSet(); - initSecurityGroupSet(); - TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId); - MacAddress macAddress = MacAddress.valueOf(macAddressStr); - TenantId tenantId = TenantId.tenantId(tenantIdStr); - DeviceId deviceId = DeviceId.deviceId(deviceStr); - BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr); - - VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3) - .testEquals(); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java deleted file mode 100644 index 1e33da09..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onosproject.vtnrsc.FixedIp; -import org.onosproject.vtnrsc.SubnetId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for FixedIp class. - */ -public class FixedIpTest { - - final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c"); - final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c"); - final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); - final IpAddress ip2 = IpAddress.valueOf("192.168.1.1"); - - /** - * Checks that the FixedIp class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(FixedIp.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1); - FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1); - FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2); - new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2) - .addEqualityGroup(fixedIp3).testEquals(); - } - - /** - * Checks the construction of a FixedIp object. - */ - @Test - public void testConstruction() { - FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1); - assertThat(ip1, is(notNullValue())); - assertThat(ip1, is(fixedIp.ip())); - assertThat(subnetId1, is(notNullValue())); - assertThat(subnetId1, is(fixedIp.subnetId())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java deleted file mode 100644 index 8c04e499..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SecurityGroup; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SecurityGroup class. - */ -public class SecurityGroupTest { - - final SecurityGroup securityGroup1 = SecurityGroup.securityGroup("1"); - final SecurityGroup sameAssecurityGroup = SecurityGroup.securityGroup("1"); - final SecurityGroup securityGroup2 = SecurityGroup.securityGroup("2"); - - /** - * Checks that the SecurityGroup class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SecurityGroup.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(securityGroup1, sameAssecurityGroup) - .addEqualityGroup(securityGroup2).testEquals(); - } - - /** - * Checks the construction of a SecurityGroup object. - */ - @Test - public void testConstruction() { - final String securityGroupValue = "1"; - final SecurityGroup securityGroup = SecurityGroup.securityGroup(securityGroupValue); - assertThat(securityGroup, is(notNullValue())); - assertThat(securityGroup.securityGroup(), is(securityGroupValue)); - - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java deleted file mode 100644 index 2d63e91c..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.VirtualPortId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for VirtualPortId class. - */ -public class VirtualPortIdTest { - - final VirtualPortId virtualPortId1 = VirtualPortId.portId("1"); - final VirtualPortId sameAsVirtualPortId1 = VirtualPortId.portId("1"); - final VirtualPortId virtualPortId2 = VirtualPortId.portId("2"); - - /** - * Checks that the VirtualPortId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(VirtualPortId.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(virtualPortId1, sameAsVirtualPortId1) - .addEqualityGroup(virtualPortId2).testEquals(); - } - - /** - * Checks the construction of a VirtualPortId object. - */ - @Test - public void testConstruction() { - final String vPortIdValue = "aaa"; - final VirtualPortId virtualPortId = VirtualPortId.portId(vPortIdValue); - assertThat(virtualPortId, is(notNullValue())); - assertThat(virtualPortId.portId(), is(vPortIdValue)); - - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java index 1450e4ef..b0e2f38d 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java @@ -15,15 +15,12 @@ */ package org.onosproject.vtnweb.resources; -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; -import static org.onlab.util.Tools.nullIsNotFound; import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; import java.io.IOException; import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.UUID; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -36,13 +33,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.onosproject.rest.AbstractWebResource; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.rest.AbstractWebResource; -import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; -import org.onosproject.vtnrsc.web.FlowClassifierCodec; +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; +import org.onosproject.vtnweb.web.FlowClassifierCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -51,73 +52,51 @@ import com.fasterxml.jackson.databind.node.ObjectNode; @Path("flow_classifiers") public class FlowClassifierWebResource extends AbstractWebResource { + private final Logger log = LoggerFactory.getLogger(FlowClassifierWebResource.class); + final FlowClassifierService service = get(FlowClassifierService.class); - final ObjectNode root = mapper().createObjectNode(); public static final String FLOW_CLASSIFIER_NOT_FOUND = "Flow classifier not found"; /** - * Get all flow classifiers created. Returns list of all flow classifiers - * created. + * Get all flow classifiers created. * * @return 200 OK */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getFlowClassifiers() { - Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers(); + final Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers(); ObjectNode result = new ObjectMapper().createObjectNode(); - result.set("flow_classifiers", new FlowClassifierCodec().encode(flowClassifiers, this)); + ArrayNode flowClassifierEntry = result.putArray("flow_classifiers"); + if (flowClassifiers != null) { + for (final FlowClassifier flowClassifier : flowClassifiers) { + flowClassifierEntry.add(new FlowClassifierCodec().encode(flowClassifier, this)); + } + } return ok(result.toString()).build(); } /** - * Get details of a flow classifier. Returns details of a specified flow - * classifier id. + * Get details of a flow classifier. * * @param id flow classifier id - * @return 200 OK + * @return 200 OK , 404 if given identifier does not exist */ @GET @Path("{flow_id}") @Produces(MediaType.APPLICATION_JSON) public Response getFlowClassifier(@PathParam("flow_id") String id) { - if (!service.hasFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id)))) { + if (!service.hasFlowClassifier(FlowClassifierId.of(id))) { return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); } - FlowClassifier flowClassifier = nullIsNotFound( - service.getFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id))), + FlowClassifier flowClassifier = nullIsNotFound(service.getFlowClassifier(FlowClassifierId.of(id)), FLOW_CLASSIFIER_NOT_FOUND); ObjectNode result = new ObjectMapper().createObjectNode(); result.set("flow_classifier", new FlowClassifierCodec().encode(flowClassifier, this)); - return ok(result.toString()).build(); - } - /** - * Creates and stores a new flow classifier. - * - * @param flowClassifierId flow classifier identifier - * @param stream flow classifier from JSON - * @return status of the request - CREATED if the JSON is correct, - * BAD_REQUEST if the JSON is invalid - */ - @POST - @Path("{flow_id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createFlowClassifier(@PathParam("flow_id") String flowClassifierId, InputStream stream) { - URI location; - try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); - service.createFlowClassifier(flowClassifier); - location = new URI(flowClassifierId); - } catch (IOException | URISyntaxException ex) { - throw new IllegalArgumentException(ex); - } - return Response.created(location).build(); + return ok(result.toString()).build(); } /** @@ -125,32 +104,32 @@ public class FlowClassifierWebResource extends AbstractWebResource { * * @param stream flow classifier from JSON * @return status of the request - CREATED if the JSON is correct, - * BAD_REQUEST if the JSON is invalid + * BAD_REQUEST if the JSON is invalid */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createFlowClassifier(InputStream stream) { - URI location; try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); - service.createFlowClassifier(flowClassifier); - location = new URI(flowClassifier.flowClassifierId().toString()); - } catch (IOException | URISyntaxException ex) { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode flow = jsonTree.get("flow_classifier"); + + FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); + Boolean issuccess = nullIsNotFound(service.createFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException ex) { + log.error("Exception while creating flow classifier {}.", ex.toString()); throw new IllegalArgumentException(ex); } - return Response.created(location).build(); } /** - * Update details of a flow classifier. Update details of a specified flow - * classifier id. + * Update details of a flow classifier. * * @param id flow classifier id * @param stream InputStream - * @return 200 OK + * @return 200 OK, 404 if given identifier does not exist */ @PUT @Path("{flow_id}") @@ -158,35 +137,29 @@ public class FlowClassifierWebResource extends AbstractWebResource { @Consumes(MediaType.APPLICATION_JSON) public Response updateFlowClassifier(@PathParam("flow_id") String id, final InputStream stream) { try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); + + JsonNode jsonTree = mapper().readTree(stream); + JsonNode flow = jsonTree.get("flow_classifier"); + FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); Boolean result = nullIsNotFound(service.updateFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND); - if (!result) { - return Response.status(204).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); - } - return Response.status(203).entity(result.toString()).build(); - } catch (Exception e) { - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build(); + return Response.status(OK).entity(result.toString()).build(); + } catch (IOException e) { + log.error("Update flow classifier failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); } } /** - * Delete details of a flow classifier. Delete details of a specified flow - * classifier id. + * Delete details of a flow classifier. * * @param id flow classifier id - * @return 200 OK - * @throws IOException when input doesn't match. */ @Path("{flow_id}") @DELETE - public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException { - try { - FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(UUID.fromString(id)); - service.removeFlowClassifier(flowClassifierId); - return Response.status(201).entity("SUCCESS").build(); - } catch (Exception e) { - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build(); - } + public void deleteFlowClassifier(@PathParam("flow_id") String id) { + log.debug("Deletes flow classifier by identifier {}.", id); + FlowClassifierId flowClassifierId = FlowClassifierId.of(id); + Boolean issuccess = nullIsNotFound(service.removeFlowClassifier(flowClassifierId), FLOW_CLASSIFIER_NOT_FOUND); + } } diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java new file mode 100644 index 00000000..db12bcc7 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java @@ -0,0 +1,157 @@ +/* + * 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.vtnweb.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.portchain.PortChainService; +import org.onosproject.vtnweb.web.PortChainCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port chain. + */ + +@Path("port_chains") +public class PortChainWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortChainWebResource.class); + private final PortChainService service = get(PortChainService.class); + public static final String PORT_CHAIN_NOT_FOUND = "Port chain not found"; + public static final String PORT_CHAIN_ID_EXIST = "Port chain exists"; + public static final String PORT_CHAIN_ID_NOT_EXIST = "Port chain does not exist with identifier"; + + /** + * Get details of all port chains created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortChains() { + Iterable<PortChain> portChains = service.getPortChains(); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_chains", new PortChainCodec().encode(portChains, this)); + return ok(result).build(); + } + + /** + * Get details of a specified port chain id. + * + * @param id port chain id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{chain_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPain(@PathParam("chain_id") String id) { + + if (!service.exists(PortChainId.of(id))) { + return Response.status(NOT_FOUND).entity(PORT_CHAIN_NOT_FOUND).build(); + } + PortChain portChain = nullIsNotFound(service.getPortChain(PortChainId.of(id)), + PORT_CHAIN_NOT_FOUND); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_chain", new PortChainCodec().encode(portChain, this)); + return ok(result).build(); + } + + /** + * Creates a new port chain. + * + * @param stream port chain from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortChain(InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortChain portChain = codec(PortChain.class).decode(jsonTree, this); + Boolean issuccess = nullIsNotFound(service.createPortChain(portChain), PORT_CHAIN_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port chain {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port chain id. + * + * @param id port chain id + * @param stream port chain json + * @return 200 OK, 404 if given identifier does not exist + */ + @PUT + @Path("{chain_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPain(@PathParam("chain_id") String id, + final InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortChain portChain = codec(PortChain.class).decode(jsonTree, this); + Boolean result = nullIsNotFound(service.updatePortChain(portChain), PORT_CHAIN_NOT_FOUND); + return Response.status(OK).entity(result.toString()).build(); + } catch (IOException e) { + log.error("Update port chain failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port chain id. + * + * @param id port chain id + */ + @Path("{chain_id}") + @DELETE + public void deletePortPain(@PathParam("chain_id") String id) { + log.debug("Deletes port chain by identifier {}.", id); + PortChainId portChainId = PortChainId.of(id); + + Boolean issuccess = nullIsNotFound(service.removePortChain(portChainId), PORT_CHAIN_NOT_FOUND); + if (!issuccess) { + log.debug("Port Chain identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java new file mode 100644 index 00000000..69daad37 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java @@ -0,0 +1,163 @@ +/* + * 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.vtnweb.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; +import org.onosproject.vtnweb.web.PortPairGroupCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port pair group. + */ + +@Path("port_pair_groups") +public class PortPairGroupWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortPairGroupWebResource.class); + private final PortPairGroupService service = get(PortPairGroupService.class); + public static final String PORT_PAIR_GROUP_NOT_FOUND = "Port pair group not found"; + public static final String PORT_PAIR_GROUP_ID_EXIST = "Port pair group exists"; + public static final String PORT_PAIR_GROUP_ID_NOT_EXIST = "Port pair group does not exist with identifier"; + + /** + * Get details of all port pair groups created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairGroups() { + Iterable<PortPairGroup> portPairGroups = service.getPortPairGroups(); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair_groups", new PortPairGroupCodec().encode(portPairGroups, this)); + return ok(result).build(); + } + + /** + * Get details of a specified port pair group id. + * + * @param id port pair group id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{group_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairGroup(@PathParam("group_id") String id) { + + if (!service.exists(PortPairGroupId.of(id))) { + return Response.status(NOT_FOUND) + .entity(PORT_PAIR_GROUP_NOT_FOUND).build(); + } + PortPairGroup portPairGroup = nullIsNotFound(service.getPortPairGroup(PortPairGroupId.of(id)), + PORT_PAIR_GROUP_NOT_FOUND); + + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair_group", new PortPairGroupCodec().encode(portPairGroup, this)); + return ok(result).build(); + } + + /** + * Creates a new port pair group. + * + * @param stream port pair group from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortPairGroup(InputStream stream) { + + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + + PortPairGroup portPairGroup = codec(PortPairGroup.class).decode(jsonTree, this); + Boolean issuccess = nullIsNotFound(service.createPortPairGroup(portPairGroup), + PORT_PAIR_GROUP_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port pair group {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port pair group id. + * + * @param id port pair group id + * @param stream port pair group from json + * @return 200 OK, 404 if given identifier does not exist + */ + @PUT + @Path("{group_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPairGroup(@PathParam("group_id") String id, + final InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortPairGroup portPairGroup = codec(PortPairGroup.class).decode(jsonTree, this); + Boolean isSuccess = nullIsNotFound(service.updatePortPairGroup(portPairGroup), PORT_PAIR_GROUP_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Update port pair group failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port pair group id. + * + * @param id port pair group id + */ + @Path("{group_id}") + @DELETE + public void deletePortPairGroup(@PathParam("group_id") String id) { + log.debug("Deletes port pair group by identifier {}.", id); + PortPairGroupId portPairGroupId = PortPairGroupId.of(id); + Boolean issuccess = nullIsNotFound(service.removePortPairGroup(portPairGroupId), + PORT_PAIR_GROUP_NOT_FOUND); + if (!issuccess) { + log.debug("Port pair group identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java new file mode 100644 index 00000000..b9012898 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java @@ -0,0 +1,166 @@ +/* + * 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.vtnweb.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.portpair.PortPairService; +import org.onosproject.vtnweb.web.PortPairCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port pair. + */ +@Path("port_pairs") +public class PortPairWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortPairWebResource.class); + private final PortPairService service = get(PortPairService.class); + public static final String PORT_PAIR_NOT_FOUND = "Port pair not found"; + public static final String PORT_PAIR_ID_EXIST = "Port pair exists"; + public static final String PORT_PAIR_ID_NOT_EXIST = "Port pair does not exist with identifier"; + + /** + * Get details of all port pairs created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairs() { + Iterable<PortPair> portPairs = service.getPortPairs(); + ObjectNode result = new ObjectMapper().createObjectNode(); + ArrayNode portPairEntry = result.putArray("port_pairs"); + if (portPairs != null) { + for (final PortPair portPair : portPairs) { + portPairEntry.add(new PortPairCodec().encode(portPair, this)); + } + } + return ok(result.toString()).build(); + } + + /** + * Get details of a specified port pair id. + * + * @param id port pair id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{pair_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPair(@PathParam("pair_id") String id) { + + if (!service.exists(PortPairId.of(id))) { + return Response.status(NOT_FOUND).entity(PORT_PAIR_NOT_FOUND).build(); + } + PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)), PORT_PAIR_NOT_FOUND); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair", new PortPairCodec().encode(portPair, this)); + return ok(result.toString()).build(); + } + + /** + * Creates a new port pair. + * + * @param stream port pair from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortPair(InputStream stream) { + try { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode port = jsonTree.get("port_pair"); + PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this); + Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair), PORT_PAIR_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port pair {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port pair id. + * + * @param id port pair id + * @param stream port pair from json + * @return 200 OK, 404 if the given identifier does not exist + */ + @PUT + @Path("{pair_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPair(@PathParam("pair_id") String id, + final InputStream stream) { + try { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode port = jsonTree.get("port_pair"); + PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this); + Boolean isSuccess = nullIsNotFound(service.updatePortPair(portPair), PORT_PAIR_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Update port pair failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port pair id. + * + * @param id port pair id + */ + @Path("{pair_id}") + @DELETE + public void deletePortPair(@PathParam("pair_id") String id) { + + PortPairId portPairId = PortPairId.of(id); + Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId), PORT_PAIR_NOT_FOUND); + if (!isSuccess) { + log.debug("Port pair identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java index fd5b1ee4..a18ca362 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java @@ -13,21 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.web; +package org.onosproject.vtnweb.web; import static com.google.common.base.Preconditions.checkNotNull; import static org.onlab.util.Tools.nullIsIllegal; -import java.util.UUID; - import org.onlab.packet.IpPrefix; import org.onosproject.codec.CodecContext; import org.onosproject.codec.JsonCodec; import org.onosproject.vtnrsc.DefaultFlowClassifier; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.vtnrsc.VirtualPortId; import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.VirtualPortId; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -40,7 +38,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { private static final String TENANT_ID = "tenant_id"; private static final String NAME = "name"; private static final String DESCRIPTION = "description"; - private static final String ETHER_TYPE = "etherType"; + private static final String ETHER_TYPE = "ethertype"; private static final String PROTOCOL = "protocol"; private static final String MIN_SRC_PORT_RANGE = "source_port_range_min"; private static final String MAX_SRC_PORT_RANGE = "source_port_range_max"; @@ -62,7 +60,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID), FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setFlowClassifierId(FlowClassifierId.flowClassifierId(UUID.fromString(flowClassifierId))); + resultBuilder.setFlowClassifierId(FlowClassifierId.of(flowClassifierId)); String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setTenantId(TenantId.tenantId(tenantId)); @@ -70,44 +68,46 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { String flowClassiferName = nullIsIllegal(json.get(NAME), NAME + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setName(flowClassiferName); - String flowClassiferDescription = nullIsIllegal(json.get(DESCRIPTION), DESCRIPTION + MISSING_MEMBER_MESSAGE) - .asText(); + String flowClassiferDescription = (json.get(DESCRIPTION)).asText(); resultBuilder.setDescription(flowClassiferDescription); String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setEtherType(etherType); - String protocol = nullIsIllegal(json.get(PROTOCOL), PROTOCOL + MISSING_MEMBER_MESSAGE).asText(); + String protocol = (json.get(PROTOCOL)).asText(); resultBuilder.setProtocol(protocol); - int minSrcPortRange = nullIsIllegal(json.get(MIN_SRC_PORT_RANGE), MIN_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt(); resultBuilder.setMinSrcPortRange(minSrcPortRange); - int maxSrcPortRange = nullIsIllegal(json.get(MAX_SRC_PORT_RANGE), MAX_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int maxSrcPortRange = (json.get(MAX_SRC_PORT_RANGE)).asInt(); resultBuilder.setMaxSrcPortRange(maxSrcPortRange); - int minDstPortRange = nullIsIllegal(json.get(MIN_DST_PORT_RANGE), MIN_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int minDstPortRange = (json.get(MIN_DST_PORT_RANGE)).asInt(); resultBuilder.setMinDstPortRange(minDstPortRange); - int maxDstPortRange = nullIsIllegal(json.get(MAX_DST_PORT_RANGE), MAX_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int maxDstPortRange = (json.get(MAX_DST_PORT_RANGE)).asInt(); resultBuilder.setMaxDstPortRange(maxDstPortRange); - String srcIpPrefix = nullIsIllegal(json.get(SRC_IP_PREFIX), SRC_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); - - String dstIpPrefix = nullIsIllegal(json.get(DST_IP_PREFIX), DST_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); + String srcIpPrefix = (json.get(SRC_IP_PREFIX)).asText(); + if (!srcIpPrefix.isEmpty()) { + resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); + } - String srcPort = nullIsIllegal(json.get(SRC_PORT), SRC_PORT + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); + String dstIpPrefix = (json.get(DST_IP_PREFIX)).asText(); + if (!dstIpPrefix.isEmpty()) { + resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); + } - String dstPort = nullIsIllegal(json.get(DST_PORT), DST_PORT + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); + String srcPort = json.get(SRC_PORT) != null ? (json.get(SRC_PORT)).asText() : ""; + if (!srcPort.isEmpty()) { + resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); + } + String dstPort = json.get(DST_PORT) != null ? (json.get(DST_PORT)).asText() : ""; + if (!dstPort.isEmpty()) { + resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); + } return resultBuilder.build(); } @@ -115,20 +115,20 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) { checkNotNull(flowClassifier, "flowClassifier cannot be null"); ObjectNode result = context.mapper().createObjectNode() - .put("FLOW_CLASSIFIER_ID", flowClassifier.flowClassifierId().toString()) - .put("TENANT_ID", flowClassifier.tenantId().toString()) - .put("NAME", flowClassifier.name()) - .put("DESCRIPTION", flowClassifier.description()) - .put("ETHER_TYPE", flowClassifier.etherType()) - .put("PROTOCOL", flowClassifier.protocol()) - .put("MIN_SRC_PORT_RANGE", flowClassifier.minSrcPortRange()) - .put("MAX_SRC_PORT_RANGE", flowClassifier.maxSrcPortRange()) - .put("MIN_DST_PORT_RANGE", flowClassifier.minDstPortRange()) - .put("MAX_DST_PORT_RANGE", flowClassifier.maxDstPortRange()) - .put("SRC_IP_PREFIX", flowClassifier.srcIpPrefix().toString()) - .put("DST_IP_PREFIX", flowClassifier.dstIpPrefix().toString()) - .put("SRC_PORT", flowClassifier.srcPort().toString()) - .put("DST_PORT", flowClassifier.dstPort().toString()); + .put(FLOW_CLASSIFIER_ID, flowClassifier.flowClassifierId().toString()) + .put(TENANT_ID, flowClassifier.tenantId().toString()) + .put(NAME, flowClassifier.name()) + .put(DESCRIPTION, flowClassifier.description()) + .put(ETHER_TYPE, flowClassifier.etherType()) + .put(PROTOCOL, flowClassifier.protocol()) + .put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange()) + .put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange()) + .put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange()) + .put(MAX_DST_PORT_RANGE, flowClassifier.maxDstPortRange()) + .put(SRC_IP_PREFIX, flowClassifier.srcIpPrefix().toString()) + .put(DST_IP_PREFIX, flowClassifier.dstIpPrefix().toString()) + .put(SRC_PORT, flowClassifier.srcPort().toString()) + .put(DST_PORT, flowClassifier.dstPort().toString()); return result; } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java index 28da5cd1..1e9cf009 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java @@ -59,7 +59,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { String id = nullIsIllegal(json.get(ID), ID + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setId(PortChainId.portChainId(id)); + resultBuilder.setId(PortChainId.of(id)); String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); @@ -76,14 +76,14 @@ public final class PortChainCodec extends JsonCodec<PortChain> { ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIR_GROUPS); if (arrayNode != null) { List<PortPairGroupId> list = Lists.newArrayList(); - arrayNode.forEach(i -> list.add(PortPairGroupId.portPairGroupId(i.asText()))); + arrayNode.forEach(i -> list.add(PortPairGroupId.of(i.asText()))); resultBuilder.setPortPairGroups(list); } arrayNode = (ArrayNode) json.path(FLOW_CLASSIFIERS); if (arrayNode != null) { List<FlowClassifierId> list = Lists.newArrayList(); - arrayNode.forEach(i -> list.add(FlowClassifierId.flowClassifierId(UUID.fromString(i.asText())))); + arrayNode.forEach(i -> list.add(FlowClassifierId.of(UUID.fromString(i.asText())))); resultBuilder.setFlowClassifiers(list); } diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java new file mode 100644 index 00000000..691536f4 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java @@ -0,0 +1,94 @@ +/* + * 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.vtnweb.web; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.nullIsIllegal; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.core.CoreService; +import org.onosproject.vtnrsc.DefaultPortPair; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Port Pair JSON codec. + */ +public final class PortPairCodec extends JsonCodec<PortPair> { + + private static final String ID = "id"; + private static final String TENANT_ID = "tenant_id"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private static final String INGRESS = "ingress"; + private static final String EGRESS = "egress"; + private static final String MISSING_MEMBER_MESSAGE = + " member is required in PortPair"; + + @Override + public PortPair decode(ObjectNode json, CodecContext context) { + if (json == null || !json.isObject()) { + return null; + } + + PortPair.Builder resultBuilder = new DefaultPortPair.Builder(); + + CoreService coreService = context.getService(CoreService.class); + + String id = nullIsIllegal(json.get(ID), + ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setId(PortPairId.of(id)); + + String tenantId = nullIsIllegal(json.get(TENANT_ID), + TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setTenantId(TenantId.tenantId(tenantId)); + + String name = nullIsIllegal(json.get(NAME), + NAME + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setName(name); + + String description = nullIsIllegal(json.get(DESCRIPTION), + DESCRIPTION + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDescription(description); + + String ingressPort = nullIsIllegal(json.get(INGRESS), + INGRESS + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setIngress(ingressPort); + + String egressPort = nullIsIllegal(json.get(EGRESS), + EGRESS + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setEgress(egressPort); + + return resultBuilder.build(); + } + + @Override + public ObjectNode encode(PortPair portPair, CodecContext context) { + checkNotNull(portPair, "port pair cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put(ID, portPair.portPairId().toString()) + .put(TENANT_ID, portPair.tenantId().toString()) + .put(NAME, portPair.name()) + .put(DESCRIPTION, portPair.description()) + .put(INGRESS, portPair.ingress()) + .put(EGRESS, portPair.egress()); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.java new file mode 100644 index 00000000..b5ae266b --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.java @@ -0,0 +1,95 @@ +/* + * 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.vtnweb.web; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.nullIsIllegal; + +import java.util.List; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.core.CoreService; +import org.onosproject.vtnrsc.DefaultPortPairGroup; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Lists; + +/** + * Port Pair Group JSON codec. + */ +public final class PortPairGroupCodec extends JsonCodec<PortPairGroup> { + + private static final String ID = "id"; + private static final String TENANT_ID = "tenant_id"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private static final String PORT_PAIRS = "port_pairs"; + private static final String MISSING_MEMBER_MESSAGE = + " member is required in PortPairGroup"; + + @Override + public PortPairGroup decode(ObjectNode json, CodecContext context) { + if (json == null || !json.isObject()) { + return null; + } + + PortPairGroup.Builder resultBuilder = new DefaultPortPairGroup.Builder(); + + CoreService coreService = context.getService(CoreService.class); + + String id = nullIsIllegal(json.get(ID), + ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setId(PortPairGroupId.of(id)); + + String tenantId = nullIsIllegal(json.get(TENANT_ID), + TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setTenantId(TenantId.tenantId(tenantId)); + + String name = nullIsIllegal(json.get(NAME), + NAME + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setName(name); + + String description = nullIsIllegal(json.get(DESCRIPTION), + DESCRIPTION + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDescription(description); + + List<PortPairId> list = Lists.newArrayList(); + ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIRS); + arrayNode.forEach(i -> list.add(PortPairId.of(i.asText()))); + resultBuilder.setPortPairs(list); + + return resultBuilder.build(); + } + + @Override + public ObjectNode encode(PortPairGroup portPairGroup, CodecContext context) { + checkNotNull(portPairGroup, "port pair group cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put(ID, portPairGroup.portPairGroupId().toString()) + .put(TENANT_ID, portPairGroup.tenantId().toString()) + .put(NAME, portPairGroup.name()) + .put(DESCRIPTION, portPairGroup.description()) + .put(PORT_PAIRS, portPairGroup.portPairs().toString()); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml index 4cc12455..97337960 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml @@ -33,6 +33,10 @@ org.onosproject.vtnweb.resources.TenantNetworkWebResource, org.onosproject.vtnweb.resources.SubnetWebResource, org.onosproject.vtnweb.resources.VirtualPortWebResource + org.onosproject.vtnweb.resources.FlowClassifierWebResource + org.onosproject.vtnweb.resources.PortChainWebResource + org.onosproject.vtnweb.resources.PortPairGroupWebResource + org.onosproject.vtnweb.resources.PortPairWebResource </param-value> </init-param> <load-on-startup>1</load-on-startup> diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java new file mode 100644 index 00000000..02681db3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java @@ -0,0 +1,95 @@ +/* + * 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.vtnweb.web; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Flow rule codec unit tests. + */ +public class PortChainCodecTest { + + SfcCodecContext context; + JsonCodec<PortChain> portChainCodec; + /** + * Sets up for each test. Creates a context and fetches the flow rule + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portChainCodec = context.codec(PortChain.class); + assertThat(portChainCodec, notNullValue()); + } + + /** + * Reads in a rule from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the rule + * @return decoded flow rule + * @throws IOException if processing the resource fails + */ + private PortChain getPortChain(String resourceName) throws IOException { + InputStream jsonStream = PortChainCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortChain portChain = portChainCodec.decode((ObjectNode) json, context); + assertThat(portChain, notNullValue()); + return portChain; + } + + /** + * Checks that a simple rule decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortChainTest() throws IOException { + + PortChain portChain = getPortChain("portChain.json"); + + assertThat(portChain, notNullValue()); + + PortChainId portChainId = PortChainId.of("1278dcd4-459f-62ed-754b-87fc5e4a6751"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portChain.portChainId().toString(), is(portChainId.toString())); + assertThat(portChain.name(), is("PC2")); + assertThat(portChain.tenantId().toString(), is(tenantId.toString())); + assertThat(portChain.description(), is("Two flows and two port-pair-groups")); + + assertThat(portChain.flowClassifiers(), notNullValue()); + assertThat(portChain.portPairGroups(), notNullValue()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java new file mode 100644 index 00000000..7651e098 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java @@ -0,0 +1,94 @@ +/* + * 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.vtnweb.web; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Port pair codec unit tests. + */ +public class PortPairCodecTest { + + SfcCodecContext context; + JsonCodec<PortPair> portPairCodec; + /** + * Sets up for each test. Creates a context and fetches the port pair + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portPairCodec = context.codec(PortPair.class); + assertThat(portPairCodec, notNullValue()); + } + + /** + * Reads in a port pair from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the port pair + * @return decoded port pair + * @throws IOException if processing the resource fails + */ + private PortPair getPortPair(String resourceName) throws IOException { + InputStream jsonStream = PortPairCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortPair portPair = portPairCodec.decode((ObjectNode) json, context); + assertThat(portPair, notNullValue()); + return portPair; + } + + /** + * Checks that a simple port pair decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortPairTest() throws IOException { + + PortPair portPair = getPortPair("portPair.json"); + + assertThat(portPair, notNullValue()); + + PortPairId portPairId = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portPair.portPairId().toString(), is(portPairId.toString())); + assertThat(portPair.name(), is("PP1")); + assertThat(portPair.tenantId().toString(), is(tenantId.toString())); + assertThat(portPair.description(), is("SF-A")); + assertThat(portPair.ingress().toString(), is("dace4513-24fc-4fae-af4b-321c5e2eb3d1")); + assertThat(portPair.egress().toString(), is("aef3478a-4a56-2a6e-cd3a-9dee4e2ec345")); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java new file mode 100644 index 00000000..de2ee001 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java @@ -0,0 +1,93 @@ +/* + * 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.vtnweb.web; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Flow rule codec unit tests. + */ +public class PortPairGroupCodecTest { + + SfcCodecContext context; + JsonCodec<PortPairGroup> portPairGroupCodec; + /** + * Sets up for each test. Creates a context and fetches the flow rule + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portPairGroupCodec = context.codec(PortPairGroup.class); + assertThat(portPairGroupCodec, notNullValue()); + } + + /** + * Reads in a rule from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the rule + * @return decoded flow rule + * @throws IOException if processing the resource fails + */ + private PortPairGroup getPortPairGroup(String resourceName) throws IOException { + InputStream jsonStream = PortPairGroupCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortPairGroup portPairGroup = portPairGroupCodec.decode((ObjectNode) json, context); + assertThat(portPairGroup, notNullValue()); + return portPairGroup; + } + + /** + * Checks that a simple rule decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortPairGroupTest() throws IOException { + + PortPairGroup portPairGroup = getPortPairGroup("portPairGroup.json"); + + assertThat(portPairGroup, notNullValue()); + + PortPairGroupId portPairGroupId = PortPairGroupId.of("4512d643-24fc-4fae-af4b-321c5e2eb3d1"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portPairGroup.portPairGroupId().toString(), is(portPairGroupId.toString())); + assertThat(portPairGroup.name(), is("PG1")); + assertThat(portPairGroup.tenantId().toString(), is(tenantId.toString())); + assertThat(portPairGroup.description(), is("Two port-pairs")); + assertThat(portPairGroup.portPairs(), notNullValue()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java new file mode 100644 index 00000000..fe9d7995 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java @@ -0,0 +1,77 @@ +/* + * 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.vtnweb.web; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.FlowClassifier; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairGroup; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Mock codec context for use in codec unit tests. + */ +public class SfcCodecContext implements CodecContext { + + private final ObjectMapper mapper = new ObjectMapper(); + private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>(); + + /** + * Constructs a new mock codec context. + */ + public SfcCodecContext() { + codecs.clear(); + registerCodec(PortPair.class, new PortPairCodec()); + registerCodec(PortChain.class, new PortChainCodec()); + registerCodec(PortPairGroup.class, new PortPairGroupCodec()); + registerCodec(FlowClassifier.class, new FlowClassifierCodec()); + } + + @Override + public ObjectMapper mapper() { + return mapper; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getService(Class<T> serviceClass) { + // TODO + return null; + } + + /** + * Registers the specified JSON codec for the given entity class. + * + * @param entityClass entity class + * @param codec JSON codec + * @param <T> entity type + */ + public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) { + codecs.putIfAbsent(entityClass, codec); + } + + @SuppressWarnings("unchecked") + @Override + public <T> JsonCodec<T> codec(Class<T> entityClass) { + return codecs.get(entityClass); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json new file mode 100644 index 00000000..07a1bc21 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json @@ -0,0 +1,14 @@ +{ + "id": "1278dcd4-459f-62ed-754b-87fc5e4a6751", + "name": "PC2", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "Two flows and two port-pair-groups", + "flow_classifiers": [ + "456a4a34-2e9c-14ae-37fb-765feae2eb05", + "4a334cd4-fe9c-4fae-af4b-321c5e2eb051" + ], + "port_pair_groups": [ + "4512d643-24fc-4fae-af4b-321c5e2eb3d1", + "4a634d49-76dc-4fae-af4b-321c5e23d651" + ] +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPair.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPair.json new file mode 100644 index 00000000..f858c88c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPair.json @@ -0,0 +1,9 @@ +{ + "id": "78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae", + "name": "PP1", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "SF-A", + "ingress": "dace4513-24fc-4fae-af4b-321c5e2eb3d1", + "egress": "aef3478a-4a56-2a6e-cd3a-9dee4e2ec345" +} + diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json new file mode 100644 index 00000000..e19a66fc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json @@ -0,0 +1,10 @@ +{ + "id": "4512d643-24fc-4fae-af4b-321c5e2eb3d1", + "name": "PG1", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "Two port-pairs", + "port_pairs": [ + "875dfeda-43ed-23fe-454b-764feab2c342", + "78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae" + ] +} |