From cd6c6247e078821638c486019e609f32f4bb4157 Mon Sep 17 00:00:00 2001 From: Zhigang Ji Date: Tue, 17 Nov 2015 17:55:58 +0800 Subject: [PATCH] Modify the openflow renderer to support physical topology monitoring and ARP handling. Change-Id: Ic25ad709e953d687db4941addfe318bc9662a4c6 Signed-off-by: Zhigang Ji --- nemo-features/pom.xml | 31 +- nemo-features/src/main/features/features.xml | 7 +- nemo-renderers/openflow-renderer/pom.xml | 31 +- .../renderer/openflow/FlowTableManager.java | 60 +- .../nemo/renderer/openflow/FlowUtils.java | 1069 +++++++++++++++-- .../renderer/openflow/OpenflowRenderer.java | 63 +- .../renderer/openflow/ResourceManager.java | 1 - .../renderer/openflow/entity/HostBean.java | 65 - .../renderer/openflow/entity/LinkBean.java | 69 -- .../renderer/openflow/entity/NodeBean.java | 53 - .../renderer/openflow/entity/PortBean.java | 57 - .../openflow/entity/ResourceBean.java | 49 - .../physicalnetwork/DataBrokerAdapter.java | 197 +++ .../physicalnetwork/OFLinkListener.java | 82 ++ .../physicalnetwork/OFNodeListener.java | 82 ++ .../physicalnetwork/OFPacketInListener.java | 62 + .../physicalnetwork/PhyConfigLoader.java | 1 + .../physicalnetwork/PhysicalFlowUtils.java | 195 +++ .../PhysicalNetworkAdapter.java | 390 ++++++ .../openflow/physicalnetwork/Utils.java | 70 ++ .../nemo/renderer/openflow/utils/ARP.java | 278 +++++ .../rev151010/OpenflowRendererModule.java | 11 +- .../main/resources/etc/nemo/resource-bod.json | 435 ------- .../etc/nemo/resource-servicechain.json | 612 ---------- .../src/main/resources/etc/nemo/resource.json | 612 ---------- .../karaf/external-resource-bod.json | 14 + .../karaf/external-resource-servicechain.json | 34 + .../opendaylight/karaf/external-resource.json | 14 + .../opendaylight/karaf/host-resource-bod.json | 44 + .../karaf/host-resource-servicechain.json | 5 + .../etc/opendaylight/karaf/host-resource.json | 44 + .../opendaylight/karaf/link-resource-bod.json | 42 + .../karaf/link-resource-servicechain.json | 42 + .../etc/opendaylight/karaf/link-resource.json | 42 + .../opendaylight/karaf/node-resource-bod.json | 172 +++ .../karaf/node-resource-servicechain.json | 172 +++ .../etc/opendaylight/karaf/node-resource.json | 172 +++ .../openflow/FlowTableManagerTest.java | 34 - .../nemo/renderer/openflow/FlowUtilsTest.java | 177 --- .../openflow/OpenflowRendererTest.java | 40 - .../openflow/ResourceManagerTest.java | 72 -- .../openflow/entity/HostBeanTest.java | 119 -- .../openflow/entity/LinkBeanTest.java | 133 -- .../openflow/entity/NodeBeanTest.java | 99 -- .../openflow/entity/PortBeanTest.java | 113 -- .../openflow/entity/ResourceBeanTest.java | 87 -- 46 files changed, 3229 insertions(+), 3024 deletions(-) delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/ResourceManager.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/HostBean.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBean.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBean.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/PortBean.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBean.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/DataBrokerAdapter.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFLinkListener.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFNodeListener.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFPacketInListener.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoader.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalFlowUtils.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalNetworkAdapter.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/Utils.java create mode 100644 nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/utils/ARP.java delete mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-bod.json delete mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-servicechain.json delete mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-bod.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-servicechain.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-bod.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-servicechain.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-bod.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-servicechain.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-bod.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-servicechain.json create mode 100644 nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource.json delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowUtilsTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/OpenflowRendererTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/ResourceManagerTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/HostBeanTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBeanTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBeanTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/PortBeanTest.java delete mode 100644 nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBeanTest.java diff --git a/nemo-features/pom.xml b/nemo-features/pom.xml index e4db9ed..8f32032 100644 --- a/nemo-features/pom.xml +++ b/nemo-features/pom.xml @@ -30,7 +30,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html 1.3.0-SNAPSHOT 1.3.0-SNAPSHOT 0.3.0-SNAPSHOT - 0.2.0-SNAPSHOT + 0.2.0-SNAPSHOT @@ -98,11 +98,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html xml runtime - - + org.opendaylight.openflowplugin features-openflowplugin - ${openflowplugin.version} + ${openflowplugin.version} features xml @@ -113,7 +112,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html features xml - ${project.groupId} nemo-api @@ -147,7 +145,28 @@ and is available at http://www.eclipse.org/legal/epl-v10.html ${project.groupId} openflow-renderer ${project.version} - resource + node-resource + json + + + ${project.groupId} + openflow-renderer + ${project.version} + host-resource + json + + + ${project.groupId} + openflow-renderer + ${project.version} + link-resource + json + + + ${project.groupId} + openflow-renderer + ${project.version} + external-resource json diff --git a/nemo-features/src/main/features/features.xml b/nemo-features/src/main/features/features.xml index f14ab7c..2cfb0c4 100644 --- a/nemo-features/src/main/features/features.xml +++ b/nemo-features/src/main/features/features.xml @@ -36,7 +36,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-nemo-engine-rest mvn:org.opendaylight.nemo/openflow-renderer/${project.version} mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/xml/config - mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/json/resource + mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/json/node-resource + mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/json/link-resource + mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/json/host-resource + mvn:org.opendaylight.nemo/openflow-renderer/${project.version}/json/external-resource odl-nemo-engine-rest @@ -46,4 +49,4 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-nemo-engine-rest mvn:org.opendaylight.nemo/nemo-ui/${project.version} - + \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/pom.xml b/nemo-renderers/openflow-renderer/pom.xml index ab0b3f5..0c9915d 100644 --- a/nemo-renderers/openflow-renderer/pom.xml +++ b/nemo-renderers/openflow-renderer/pom.xml @@ -31,17 +31,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - org.opendaylight.mdsal.model yang-ext - org.opendaylight.openflowplugin openflowplugin-extension-nicira ${openflowplugin.version} + + org.opendaylight.controller.model + model-topology + org.opendaylight.controller liblldp @@ -162,16 +164,31 @@ and is available at http://www.eclipse.org/legal/epl-v10.html package - - ${project.build.directory}/classes/etc/nemo/resource.json - json - resource - ${project.build.directory}/classes/etc/opendaylight/karaf/config.xml xml config + + ${project.build.directory}/classes/etc/opendaylight/karaf/node-resource.json + json + node-resource + + + ${project.build.directory}/classes/etc/opendaylight/karaf/host-resource.json + json + host-resource + + + ${project.build.directory}/classes/etc/opendaylight/karaf/link-resource.json + json + link-resource + + + ${project.build.directory}/classes/etc/opendaylight/karaf/external-resource.json + json + external-resource + diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowTableManager.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowTableManager.java index 6ba4a0f..21e913b 100644 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowTableManager.java +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowTableManager.java @@ -9,23 +9,14 @@ package org.opendaylight.nemo.renderer.openflow; import com.google.common.base.Optional; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import com.google.common.util.concurrent.CheckedFuture; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; - +import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoader; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; @@ -37,19 +28,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.m import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNetworkId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNetworkId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; import java.util.Map; import java.util.Set; @@ -57,20 +47,32 @@ public class FlowTableManager implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(FlowTableManager.class); private final DataBroker dataProvider; + private final PacketProcessingService packetProcessingService; private ListenerRegistration userVnPnMappingChangeListenerReg; private FlowUtils flowUtils = null; - public FlowTableManager(DataBroker dataProvider, ResourceManager resourceManager){ + public FlowTableManager(DataBroker dataProvider, + PacketProcessingService packetProcessingService, + PhyConfigLoader phyConfigLoader) { + super(); this.dataProvider = dataProvider; - LOG.info("Initialized FlowTableManager."); - flowUtils = new FlowUtils(dataProvider, resourceManager); - //register listener + this.packetProcessingService = packetProcessingService; + + LOG.debug("Initialized FlowTableManager."); + + flowUtils = new FlowUtils(dataProvider, packetProcessingService, phyConfigLoader); + + // Register listener; registerUserVnPnMappingListener(); } + protected FlowUtils getFlowUtils() { + return flowUtils; + } + private void registerUserVnPnMappingListener() { //build userVnPnMappingIid @@ -99,11 +101,11 @@ public class FlowTableManager implements AutoCloseable { e.printStackTrace(); } if (result.isPresent()){ - LOG.info("getUser OK"); + LOG.debug("getUser OK"); return (result.get()); }else{ - LOG.info("getUser ERROR"); + LOG.debug("getUser ERROR"); return null; } } @@ -128,11 +130,11 @@ public class FlowTableManager implements AutoCloseable { e.printStackTrace(); } if (result.isPresent()) { - LOG.info("getVirtualNetwork OK"); + LOG.debug("getVirtualNetwork OK"); return (result.get()); }else{ - LOG.info("getVirtualNetwork ERROR"); + LOG.debug("getVirtualNetwork ERROR"); return null; } } @@ -151,11 +153,11 @@ public class FlowTableManager implements AutoCloseable { e.printStackTrace(); } if (result.isPresent()) { - LOG.info("getUserIntentVnMapping OK"); + LOG.debug("getUserIntentVnMapping OK"); return (result.get()); }else{ - LOG.info("getUserIntentVnMapping ERROR"); + LOG.debug("getUserIntentVnMapping ERROR"); return null; } } @@ -173,11 +175,11 @@ public class FlowTableManager implements AutoCloseable { e.printStackTrace(); } if (result.isPresent()) { - LOG.info("getPhysicalNetwork OK"); + LOG.debug("getPhysicalNetwork OK"); return (result.get()); }else{ - LOG.info("getPhysicalNetwork ERROR"); + LOG.debug("getPhysicalNetwork ERROR"); return null; } } @@ -196,7 +198,7 @@ public class FlowTableManager implements AutoCloseable { if ( null != createdData && !createdData.isEmpty() ) { for ( DataObject dataObject : createdData.values() ) { if ( dataObject instanceof UserVnPnMapping ) { - LOG.info("Ready to update flow table."); + LOG.debug("Ready to update flow table."); UserVnPnMapping userVnPnMapping = (UserVnPnMapping)dataObject; UserId userId = userVnPnMapping.getUserId(); @@ -214,7 +216,7 @@ public class FlowTableManager implements AutoCloseable { flowUtils.init(physicalNodeList); flowUtils.updateFlowTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); - LOG.info("Already call flowUtils.updateFlowTable()."); + LOG.debug("Already call flowUtils.updateFlowTable()."); } } } diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowUtils.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowUtils.java index e5d3254..275a0e1 100644 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowUtils.java +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/FlowUtils.java @@ -8,11 +8,19 @@ package org.opendaylight.nemo.renderer.openflow; +import org.apache.commons.lang3.tuple.ImmutableTriple; +import org.opendaylight.controller.liblldp.Ethernet; +import org.opendaylight.controller.liblldp.HexEncode; +import org.opendaylight.controller.liblldp.NetUtils; +import org.opendaylight.controller.liblldp.PacketException; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoader; +import org.opendaylight.nemo.renderer.openflow.utils.ARP; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.*; @@ -76,6 +84,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.*; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalPaths; @@ -86,7 +98,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArpKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArpBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.nodes.VirtualNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.paths.VirtualPath; @@ -98,11 +110,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.m import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.user.vn.pn.mapping.VnPnMappingResult; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.IntentId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.MatchItemName; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.PropertyName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.MatchItem; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,6 +141,7 @@ public class FlowUtils implements AutoCloseable { private static final int ETH_TYPE_ARP = 0x0806; private final DataBroker dataBroker; + private final PacketProcessingService packetProcessingService; private Map mplsGenerators; private Map meterIdGenerators; @@ -135,22 +150,27 @@ public class FlowUtils implements AutoCloseable { private Map metadatas; private long currentMetadata = 0; + private Map users; + private Map userIntentVnMappings; + private Map userVnPnMappings; + private PhysicalNetworkHelper physicalNetworkHelper; - private VirtualNetworkHelper virtualNetworkHelper; + private Map virtualNetworkHelpers; + private ArpHandlerHelper arpHandlerHelper; - //liushixing + // liushixing private Map>> flowIdsOfUsers; private Map>> meterIdIdsOfUsers; -// private List assignedPortForInPort; - private ResourceManager resourceManager; - - private Map gatewayMacAddress; + private PhyConfigLoader phyConfigLoader; - public FlowUtils(DataBroker dataBroker, ResourceManager resourceManager) { + public FlowUtils(DataBroker dataBroker, + PacketProcessingService packetProcessingService, + PhyConfigLoader phyConfigLoader) { super(); this.dataBroker = dataBroker; - this.resourceManager = resourceManager; + this.packetProcessingService = packetProcessingService; + this.phyConfigLoader = phyConfigLoader; mplsGenerators = new HashMap(); meterIdGenerators = new HashMap(); @@ -158,18 +178,18 @@ public class FlowUtils implements AutoCloseable { meterIdsOfPhysicalPaths = new HashMap(); metadatas = new HashMap(); - //liushixing + users = new HashMap(); + userIntentVnMappings = new HashMap(); + userVnPnMappings = new HashMap(); + + virtualNetworkHelpers = new HashMap(); + arpHandlerHelper = new ArpHandlerHelper(); + + // liushixing flowIdsOfUsers = new HashMap>>(); meterIdIdsOfUsers = new HashMap>>(); -// assignedPortForInPort = new ArrayList(); - - gatewayMacAddress = new HashMap(); - // Gateway of the DMZ group. - gatewayMacAddress.put(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId("b46cfa7f-93a3-43f4-ac20-09307c75feca"), - new MacAddress("00:00:0a:0b:0c:01")); - // Gateway of the interior group. - gatewayMacAddress.put(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId("175425f7-c9c9-474a-962c-70cb6c180d4d"), - new MacAddress("00:00:0a:0b:0c:02")); + + return; } public void init(List physicalNodes) { @@ -191,9 +211,7 @@ public class FlowUtils implements AutoCloseable { private InstanceIdentifier generateFlowInsId(UserId userId, NodeId nodeId, Short tableId, - FlowId flowId){ - - + FlowId flowId) { InstanceIdentifier flowInsId = createFlowPath(nodeId, tableId, flowId); if(flowIdsOfUsers.containsKey(userId) == false){ @@ -204,7 +222,7 @@ public class FlowUtils implements AutoCloseable { List> flowInsIds = flowIdsOfUsers.get(userId); flowInsIds.add(flowInsId); } - LOG.info("nemo:generateFlowInsId"); + LOG.debug("nemo:generateFlowInsId"); return flowInsId; } @@ -232,28 +250,48 @@ public class FlowUtils implements AutoCloseable { List> meterInsIds = meterIdIdsOfUsers.get(userId); meterInsIds.add(meterInsId); } - LOG.info("nemo:getMeterInsId"); + LOG.debug("nemo:getMeterInsId"); return meterInsId; } - public void updateFlowTable(User user, - VirtualNetwork virtualNetwork, - UserIntentVnMapping userIntentVnMapping, - UserVnPnMapping userVnPnMapping, - PhysicalNetwork physicalNetwork) { - //If new user, generate metadata; + /** + * TODO + * + * @author Zhigang Ji + * @param user TODO + * @param virtualNetwork TODO + * @param userIntentVnMapping TODO + * @param userVnPnMapping TODO + * @param physicalNetwork TODO + */ + protected void updateFlowTable(User user, + VirtualNetwork virtualNetwork, + UserIntentVnMapping userIntentVnMapping, + UserVnPnMapping userVnPnMapping, + PhysicalNetwork physicalNetwork) { + // If new user, generate metadata; if ( !metadatas.containsKey(user.getUserId()) ) { metadatas.put(user.getUserId(), ++currentMetadata); } + users.put(user.getUserId(), user); + userIntentVnMappings.put(user.getUserId(), userIntentVnMapping); + userVnPnMappings.put(user.getUserId(), userVnPnMapping); + physicalNetworkHelper = new PhysicalNetworkHelper(physicalNetwork); - virtualNetworkHelper = new VirtualNetworkHelper(virtualNetwork); + virtualNetworkHelpers.put(virtualNetwork.getNetworkId(), new VirtualNetworkHelper(virtualNetwork)); + arpHandlerHelper.update(userVnPnMapping); + + flowIdsOfUsers.put(user.getUserId(), new LinkedList>()); + meterIdIdsOfUsers.put(user.getUserId(), new LinkedList>()); updateInPortTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); updateMeterTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); updateMplsTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); updateIpTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); updateArpTable(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); + + return; } /** @@ -262,12 +300,259 @@ public class FlowUtils implements AutoCloseable { * @author Zhigang Ji * @param userId TODO */ - public void deleteFlowEntries(UserId userId) { + protected void deleteFlowEntries(UserId userId) { deleteFlowTableEntries(userId); deleteMeterTableEntries(userId); - flowIdsOfUsers.put(userId, new LinkedList>()); - meterIdIdsOfUsers.put(userId, new LinkedList>()); + users.remove(userId); + userIntentVnMappings.remove(userId); + userVnPnMappings.remove(userId); + + virtualNetworkHelpers.remove(new VirtualNetworkId(userId.getValue())); + + flowIdsOfUsers.remove(userId); + meterIdIdsOfUsers.remove(userId); + + return; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param packetReceived TODO + * @param ingress TODO + */ + public void handleArp(PacketReceived packetReceived, NodeConnectorRef ingress) { + byte[] payload = packetReceived.getPayload(); + Ethernet ethernet = new Ethernet(); + + try { + ethernet.deserialize(payload, 0, NetUtils.NumBitsInAByte * payload.length); + } catch ( PacketException exception ) { + LOG.error("Failed to decode the received packet to ethernet packet."); + + return; + } + + ARP arp = new ARP(); + + try { + arp.deserialize(ethernet.getRawPayload(), + 0, NetUtils.NumBitsInAByte * ethernet.getRawPayload().length); + } catch ( PacketException exception ) { + LOG.error("Failed to decode the raw payload of ethernet packet to arp packet."); + + return; + } + + ImmutableTriple mappingValueForExternalPhysicalPort = + arpHandlerHelper.getMappingValueForExternalPhysicalPort(ingress); + VirtualNetworkId virtualNetworkId = mappingValueForExternalPhysicalPort.getLeft(); + VirtualNodeId ingressVirtualNodeId = mappingValueForExternalPhysicalPort.getMiddle(); + VirtualPortId ingressVirtualPortId = mappingValueForExternalPhysicalPort.getRight(); + + IpAddress srcIpAddress = convertByteArray4ToIpAddress(arp.getSenderProtocolAddress()); + IpAddress dstIpAddress = convertByteArray4ToIpAddress(arp.getTargetProtocolAddress()); + + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetworkId); + VirtualNode ingressVirtualNode = virtualNetworkHelper.getVirtualNode(ingressVirtualNodeId); + VirtualArp virtualArp; + + switch ( ingressVirtualNode.getNodeType() ) { + case Vswitch: + virtualArp = virtualNetworkHelper.getVirtualArp(srcIpAddress); + + if ( null == virtualArp ) { + virtualArp = new VirtualArpBuilder() + .setIpAddress(srcIpAddress) + .setMacAddress(convertByteArray6ToMacAddress(arp.getSenderHardwareAddress())) + .setNodeId(ingressVirtualNodeId) + .setPortId(ingressVirtualPortId) + .build(); + virtualNetworkHelper.addVirtualArp(virtualArp); + + UserId userId = new UserId(virtualNetworkId.getValue()); + Map> connectedVirtualRouters = + virtualNetworkHelper.getConnectedVirtualRouters(ingressVirtualNodeId); + + if ( null != connectedVirtualRouters && !connectedVirtualRouters.isEmpty() ) { + VirtualLink virtualLink = virtualNetworkHelper.getVirtualLink( + connectedVirtualRouters.keySet().iterator().next(), ingressVirtualNodeId); + VnPnMappingResult vnPnMappingResult = getVnPnMappingResult( + userVnPnMappings.get(userId).getVnPnMappingResult(), + new VirtualResourceEntityId(virtualLink.getLinkId().getValue())); + PhysicalPathId physicalPathId = new PhysicalPathId( + vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + PhysicalPath physicalPath = physicalNetworkHelper.getPhysicalPath(physicalPathId); + + configArpTableEntry(userId, virtualArp, physicalPath); + } + + PhysicalNodeId ingressPhysicalNodeId = convertNodeConnectorRefToPhysicalNodeId(ingress); + PhysicalPortId ingressPhysicalPortId = convertNodeConnectorRefToPhysicalPortId(ingress); + + configMacTableEntry(userId, virtualArp.getMacAddress(), + ingressPhysicalNodeId, ingressPhysicalPortId); + + Map> connectedVirtualSwitches = + virtualNetworkHelper.getConnectedVirtualSwitches(ingressVirtualNodeId); + + if ( null != connectedVirtualSwitches && !connectedVirtualSwitches.isEmpty() ) { + List vnPnMappingResults = + userVnPnMappings.get(userId).getVnPnMappingResult(); + VirtualLink virtualLink; + VnPnMappingResult vnPnMappingResult; + PhysicalPathId physicalPathId; + PhysicalPath physicalPath; + + for ( VirtualNodeId virtualNodeId : connectedVirtualSwitches.keySet() ) { + virtualLink = virtualNetworkHelper.getVirtualLink(virtualNodeId, ingressVirtualNodeId); + vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, + new VirtualResourceEntityId(virtualLink.getLinkId().getValue())); + physicalPathId = new PhysicalPathId( + vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + physicalPath = physicalNetworkHelper.getPhysicalPath(physicalPathId); + + configMacTableEntry(userId, virtualArp.getMacAddress(), physicalPath); + } + } + } + + if ( ARP.REQUEST == arp.getOpCode() ) { + IpAddress gatewayIpAddress = getGatewayIpAddress(virtualNetworkId, ingressVirtualNode); + + if ( dstIpAddress.equals(gatewayIpAddress) ) { + MacAddress gatewayMacAddress = getGatewayMacAddress(virtualNetworkId, ingressVirtualNode); + byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); + + arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); + arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); + arp.setSenderHardwareAddress(convertMacAddressToByteArray6(gatewayMacAddress)); + arp.setSenderProtocolAddress(targetProtocolAddress); + arp.setOpCode(ARP.REPLY); + + ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); + ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); + + sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); + break; + } + + virtualArp = virtualNetworkHelper.getVirtualArp(dstIpAddress); + + if ( null != virtualArp ) { + byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); + + arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); + arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); + arp.setSenderHardwareAddress(convertMacAddressToByteArray6(virtualArp.getMacAddress())); + arp.setSenderProtocolAddress(targetProtocolAddress); + arp.setOpCode(ARP.REPLY); + + ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); + ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); + + sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); + break; + } + + Map> connectedVirtualSwitches = + virtualNetworkHelper.getConnectedVirtualSwitches(ingressVirtualNodeId); + + if ( null != connectedVirtualSwitches && !connectedVirtualSwitches.isEmpty() ) { + UserId userId = new UserId(virtualNetworkId.getValue()); + UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); + List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); + VirtualPort layer2ExternalVirtualPort; + VnPnMappingResult vnPnMappingResult; + PhysicalNodeId physicalNodeId; + PhysicalPortId physicalPortId; + + for ( VirtualNodeId virtualNodeId : connectedVirtualSwitches.keySet() ) { + layer2ExternalVirtualPort = + virtualNetworkHelper.getLayer2ExternalVirtualPort(virtualNodeId); + + if ( null != layer2ExternalVirtualPort ) { + vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, + new VirtualResourceEntityId(layer2ExternalVirtualPort.getPortId().getValue())); + physicalNodeId = new PhysicalNodeId( + vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); + physicalPortId = new PhysicalPortId( + vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + + sendPacketOut(payload, ingress, createNodeConnectorRef(physicalNodeId, physicalPortId)); + } + } + } + } else { + virtualArp = virtualNetworkHelper.getVirtualArp(dstIpAddress); + + if ( null != virtualArp ) { + UserId userId = new UserId(virtualNetworkId.getValue()); + UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); + List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); + VnPnMappingResult vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, + new VirtualResourceEntityId(virtualArp.getPortId().getValue())); + + PhysicalNodeId physicalNodeId = new PhysicalNodeId( + vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); + PhysicalPortId physicalPortId = new PhysicalPortId( + vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + + sendPacketOut(payload, ingress, createNodeConnectorRef(physicalNodeId, physicalPortId)); + } + } + break; + + case Vrouter: + VirtualPort ingressVirtualPort = virtualNetworkHelper + .getVirtualPort(ingressVirtualNodeId, ingressVirtualPortId); + + if ( virtualNetworkHelper.isLayer2ExternalVirtualPort(ingressVirtualPort) ) { + virtualArp = virtualNetworkHelper.getVirtualArp(srcIpAddress); + + if ( null == virtualArp ) { + virtualArp = new VirtualArpBuilder() + .setIpAddress(srcIpAddress) + .setMacAddress(convertByteArray6ToMacAddress(arp.getSenderHardwareAddress())) + .setNodeId(ingressVirtualNodeId) + .setPortId(ingressVirtualPortId) + .build(); + virtualNetworkHelper.addVirtualArp(virtualArp); + + UserId userId = new UserId(virtualNetworkId.getValue()); + PhysicalNodeId ingressPhysicalNodeId = convertNodeConnectorRefToPhysicalNodeId(ingress); + PhysicalPortId ingressPhysicalPortId = convertNodeConnectorRefToPhysicalPortId(ingress); + + configArpTableEntry(userId, virtualArp, ingressPhysicalNodeId, ingressPhysicalPortId); + } + + if ( ARP.REQUEST == arp.getOpCode() ) { + IpAddress gatewayIpAddress = getGatewayIpAddress(virtualNetworkId, ingressVirtualNode); + + if ( dstIpAddress.equals(gatewayIpAddress) ) { + MacAddress gatewayMacAddress = getGatewayMacAddress(virtualNetworkId, ingressVirtualNode); + byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); + + arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); + arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); + arp.setSenderHardwareAddress(convertMacAddressToByteArray6(gatewayMacAddress)); + arp.setSenderProtocolAddress(targetProtocolAddress); + arp.setOpCode(ARP.REPLY); + + ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); + ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); + + sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); + } + } + } + break; + + default: + break; + } return; } @@ -311,7 +596,7 @@ public class FlowUtils implements AutoCloseable { writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInsId, flow, true); writeTransaction.submit(); - LOG.info("nemo:configInternalInPortFlowTable"); + LOG.debug("nemo:configInternalInPortFlowTable"); return; } @@ -339,7 +624,7 @@ public class FlowUtils implements AutoCloseable { Instruction instructionMeta = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(writeMetadataCase).build(); instructionList.add(instructionMeta); - GoToTable gotoTable = new GoToTableBuilder().setTableId((destNodeType==VirtualNode.NodeType.Vswitch)? MAC_TABLE_ID : IP_TABLE_ID).build(); + GoToTable gotoTable = new GoToTableBuilder().setTableId((destNodeType == VirtualNode.NodeType.Vswitch) ? MAC_TABLE_ID : IP_TABLE_ID).build(); GoToTableCase gotoTableCase = new GoToTableCaseBuilder().setGoToTable(gotoTable).build(); Instruction instructionGoto = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(gotoTableCase).build(); instructionList.add(instructionGoto); @@ -358,7 +643,7 @@ public class FlowUtils implements AutoCloseable { writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInsId, flow, true); writeTransaction.submit(); - LOG.info("nemo:configExternalInPortFlowTable"); + LOG.debug("nemo:configExternalInPortFlowTable"); return; } @@ -381,7 +666,7 @@ public class FlowUtils implements AutoCloseable { List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); for(VnPnMappingResult vnPnMappingResult:vnPnMappingResults){ - LOG.info("nemo:inport for(VnPnMappingResult vnPnMappingResult:vnPnMappingResults)"); + LOG.debug("nemo:inport for(VnPnMappingResult vnPnMappingResult:vnPnMappingResults)"); if(VirtualResource.VirtualResourceType.Vport == vnPnMappingResult.getVirtualResourceType()) { VirtualPortId virtualPortid = new VirtualPortId(vnPnMappingResult.getVirtualResourceEntityId().getValue()); VirtualNodeId virtualNodeId = new VirtualNodeId(vnPnMappingResult.getParentVirtualResourceEntityId().getValue()); @@ -447,10 +732,10 @@ public class FlowUtils implements AutoCloseable { UserVnPnMapping userVnPnMapping, PhysicalNetwork physicalNetwork) { - LOG.info("nemo:meter updateMeterTable()"); + LOG.debug("nemo:meter updateMeterTable()"); PhysicalPaths physicalPaths = physicalNetwork.getPhysicalPaths(); if(null == physicalPaths.getPhysicalPath()){ - LOG.info("PhysicalPath are null"); + LOG.debug("PhysicalPath are null"); return; } @@ -462,41 +747,41 @@ public class FlowUtils implements AutoCloseable { for(PhysicalPath physicalPath:physicalPathList) { if(physicalPath.getBandwidth() > 0 ) { - LOG.info("nemo: meter physicalPath.getBandwidth() = {}", physicalPath.getBandwidth()); + LOG.debug("nemo: meter physicalPath.getBandwidth() = {}", physicalPath.getBandwidth()); if(meterIdsOfPhysicalPaths.containsKey(physicalPath.getPathId())== false){ - LOG.info("nemo:meter meterIdsOfPhysicalPaths.containsKey(physicalPath.getPathId())== false"); + LOG.debug("nemo:meter meterIdsOfPhysicalPaths.containsKey(physicalPath.getPathId())== false"); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink physicalLinkInPath = physicalPath.getPhysicalLink().get(0); - LOG.info("nemo:meter physicalLinkInPath"+physicalLinkInPath.getLinkId().getValue()); + LOG.debug("nemo:meter physicalLinkInPath" + physicalLinkInPath.getLinkId().getValue()); for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink physicalLink : physicalLinksList) { - LOG.info("nemo:meter physicalLink "+physicalLink.getLinkId().getValue()); + LOG.debug("nemo:meter physicalLink " + physicalLink.getLinkId().getValue()); if (physicalLinkInPath.getLinkId().getValue().equals(physicalLink.getLinkId().getValue())) { - LOG.info("nemo:meter find plink for ppath."); + LOG.debug("nemo:meter find plink for ppath."); PhysicalNodeId physicalSrcNodeId = physicalLink.getSrcNodeId(); PhysicalPortId physicalSrcPortId = physicalLink.getSrcPortId(); - LOG.info("nemo:meter meterIdGenerators.size() = "+ meterIdGenerators.size()); - LOG.info("nemo:meter physicalSrcNodeId =" + physicalSrcNodeId.getValue()); + LOG.debug("nemo:meter meterIdGenerators.size() = " + meterIdGenerators.size()); + LOG.debug("nemo:meter physicalSrcNodeId =" + physicalSrcNodeId.getValue()); - LOG.info("nemo:meter Assign meter id"); + LOG.debug("nemo:meter Assign meter id"); Long meterId = (long)0; if(meterIdGenerators.containsKey(physicalSrcNodeId) == false){ - LOG.info("meterIdGenerators.containsKey(physicalSrcNodeId) == false"); + LOG.debug("meterIdGenerators.containsKey(physicalSrcNodeId) == false"); MeterIdGenerator meterIdGenerator = new MeterIdGenerator(); meterIdGenerators.put(physicalSrcNodeId, meterIdGenerator); meterId = meterIdGenerators.get(physicalSrcNodeId).generateMeterId(); meterIdsOfPhysicalPaths.put(physicalPath.getPathId(),meterId); } else{ - LOG.info("meterIdGenerators.containsKey(physicalSrcNodeId) == true"); + LOG.debug("meterIdGenerators.containsKey(physicalSrcNodeId) == true"); meterId = meterIdGenerators.get(physicalSrcNodeId).generateMeterId(); meterIdsOfPhysicalPaths.put(physicalPath.getPathId(),meterId); } //Generate meter flow entries - LOG.info("nemo:meter Generate meter flow entries"); + LOG.debug("nemo:meter Generate meter flow entries"); NodeKey nodeKey = new NodeKey(new NodeId(physicalSrcNodeId.getValue())); MeterKey meterKey = new MeterKey(new MeterId(meterId)); @@ -555,7 +840,7 @@ public class FlowUtils implements AutoCloseable { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); writeTransaction.put(LogicalDatastoreType.CONFIGURATION, meterInsId, meter); writeTransaction.submit(); - LOG.info("nemo:meter writeTransaction.submit();"); + LOG.debug("nemo:meter writeTransaction.submit();"); break; } } @@ -574,17 +859,17 @@ public class FlowUtils implements AutoCloseable { public void assignMPLSLabelForPPath(PhysicalPath physicalPath, List physicalLinksList){ - LOG.info("nemo: for(1)"); + LOG.debug("nemo: for(1)"); List mplsLabels = new ArrayList(); List physicalLinksInPath = physicalPath.getPhysicalLink(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.path.instance.PhysicalLink physicalLinkinPath : physicalLinksInPath) { - LOG.info("nemo: for(2)"); + LOG.debug("nemo: for(2)"); for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink physicalLink : physicalLinksList) { - LOG.info("nemo: for(3)"); + LOG.debug("nemo: for(3)"); if (physicalLinkinPath.getLinkId().getValue().equals(physicalLink.getLinkId().getValue())) { - LOG.info("nemo: physicalLinkinPath.getLinkId() == physicalLink.getLinkId()"); + LOG.debug("nemo: physicalLinkinPath.getLinkId() == physicalLink.getLinkId()"); PhysicalNodeId physicalDestNodeId = physicalLink.getDestNodeId(); if(mplsGenerators.containsKey(physicalDestNodeId) == true){ @@ -618,16 +903,15 @@ public class FlowUtils implements AutoCloseable { UserIntentVnMapping userIntentVnMapping, UserVnPnMapping userVnPnMapping, PhysicalNetwork physicalNetwork) { - - LOG.info("nemo:mpls: updateMplsTable()"); + LOG.debug("nemo:mpls: updateMplsTable()"); PhysicalPaths physicalPaths = physicalNetwork.getPhysicalPaths(); if(null == physicalPaths.getPhysicalPath()){ - LOG.info("PhysicalPaths are null"); + LOG.debug("PhysicalPaths are null"); return; } - List physicalPathList = physicalPaths.getPhysicalPath(); + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetwork.getNetworkId()); PhysicalLinks physicalLinks = physicalNetwork.getPhysicalLinks(); List @@ -672,11 +956,11 @@ public class FlowUtils implements AutoCloseable { PhysicalPortId physicalSrcPortId = physicalLink.getSrcPortId(); if (0 == counter++) { - LOG.info("nemo:mpls:0 == counter"); + LOG.debug("nemo:mpls:0 == counter"); mplsLabelIter = mplsLabelsOfPhysicalPaths.get(physicalPath.getPathId()).iterator(); inMPLSLabel = mplsLabelIter.next(); } else { - LOG.info("nemo:mpls:counter="+counter); + LOG.debug("nemo:mpls:counter=" + counter); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List instructionList = new LinkedList(); List actionList = new LinkedList(); @@ -716,7 +1000,7 @@ public class FlowUtils implements AutoCloseable { FlowBuilder flowBuilder = baseFlowBuilder().setId(flowId).setTableId(MPLS_LABEL_TABLE_ID).setPriority(DEFAULT_FLOW_PRIORITY); Flow flow = flowBuilder.setMatch(match).setInstructions(instructions).build(); - LOG.info("nemo:mpls"+physicalSrcNodeId.getValue()); + LOG.debug("nemo:mpls" + physicalSrcNodeId.getValue()); NodeId nodeId = new NodeId(physicalSrcNodeId.getValue()); @@ -729,7 +1013,7 @@ public class FlowUtils implements AutoCloseable { } //The last hop if (physicalPath.getPhysicalLink().size() == counter) { - LOG.info("nemo:mpls: last hop"); + LOG.debug("nemo:mpls: last hop"); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List instructionList = new LinkedList(); List actionList = new LinkedList(); @@ -768,7 +1052,7 @@ public class FlowUtils implements AutoCloseable { FlowBuilder flowBuilder = baseFlowBuilder().setId(flowId).setTableId(MPLS_LABEL_TABLE_ID).setPriority(DEFAULT_FLOW_PRIORITY); Flow flow = flowBuilder.setMatch(match).setInstructions(instructions).build(); - LOG.info("nemo:mpls:"+physicalDestNodeId.getValue()); + LOG.debug("nemo:mpls:" + physicalDestNodeId.getValue()); NodeId nodeId = new NodeId(physicalDestNodeId.getValue()); InstanceIdentifier flowInsId = generateFlowInsId(user.getUserId(), nodeId, flow.getTableId(), flow.getId()); @@ -797,6 +1081,7 @@ public class FlowUtils implements AutoCloseable { UserIntentVnMapping userIntentVnMapping, UserVnPnMapping userVnPnMapping, PhysicalNetwork physicalNetwork) { + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetwork.getNetworkId()); List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); Map virtualRouters = virtualNetworkHelper.getVirtualRouters(); Map> connectedVirtualSwitches; @@ -883,9 +1168,8 @@ public class FlowUtils implements AutoCloseable { if ( null != connectedVirtualSwitches ) { virtualPort = connectedVirtualSwitches.values().iterator().next().getKey(); ipPrefix = virtualPort.getExternalIpPrefixes().getExternalIpPrefix().get(0); - gatewayMacAddress = getGateWayMacAddress(userIntentVnMapping, virtualNodeId); - configIpTableEntry(user.getUserId(), ipPrefix, gatewayMacAddress, physicalNodeId); + configIpTableEntry(user.getUserId(), ipPrefix, physicalNodeId); for ( Map.Entry> entry : connectedVirtualSwitches.entrySet() ) { @@ -900,6 +1184,9 @@ public class FlowUtils implements AutoCloseable { .getConnectedVirtualRouters(entry.getKey()); if ( null != connectedVirtualRouters1 ) { + gatewayMacAddress = getGatewayMacAddress(virtualNetwork.getNetworkId(), + virtualNetworkHelper.getVirtualNode(entry.getKey())); + virtualLink1 = connectedVirtualRouters1.values().iterator().next().getValue(); vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink1.getLinkId().getValue())); @@ -949,7 +1236,6 @@ public class FlowUtils implements AutoCloseable { vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); physicalPortId = new PhysicalPortId( vnPnMappingResult.getPhysicalResourceEntityId().getValue()); - physicalPort = physicalNetworkHelper.getPhysicalPort(physicalNodeId1, physicalPortId); macAddresses = layer2ExternalVirtualPort1 .getExternalMacAddresses().getExternalMacAddress(); @@ -958,7 +1244,7 @@ public class FlowUtils implements AutoCloseable { virtualArp = virtualNetworkHelper.getVirtualArp(macAddress); configArpTableEntry(user.getUserId(), virtualArp, physicalPath); - configMacTableEntry(user.getUserId(), macAddress, physicalNodeId1, physicalPort); + configMacTableEntry(user.getUserId(), macAddress, physicalNodeId1, physicalPortId); } } } @@ -988,8 +1274,8 @@ public class FlowUtils implements AutoCloseable { updateIpTableForOperations(user, virtualNetwork, userIntentVnMapping, userVnPnMapping, physicalNetwork); - // for testing - jizhigang // log format: vnode(nodetype) --> vnode(nodetype): vlink; ppath; plinks; mplslabels; meterid; + StringBuilder stringBuilder = new StringBuilder(); Set printedVirtualLinks = new HashSet(); VirtualNode srcVirtualNode; VirtualNode dstVirtualNode; @@ -1002,11 +1288,24 @@ public class FlowUtils implements AutoCloseable { vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink2.getLinkId().getValue())); physicalPath2 = physicalNetworkHelper.getPhysicalPath(new PhysicalPathId(vnPnMappingResult.getPhysicalResourceEntityId().getValue())); - System.out.println(srcVirtualNode.getNodeId().getValue() + "(" + srcVirtualNode.getNodeType() + ") --> " + - dstVirtualNode.getNodeId().getValue() + "(" + dstVirtualNode.getNodeType() + "): " + virtualLink2.getLinkId().getValue() + "; " + - physicalPath2.getPathId().getValue() + "; " + physicalPath2.getPhysicalLink() + "; " + - mplsLabelsOfPhysicalPaths.get(physicalPath2.getPathId()) + "; " + - meterIdsOfPhysicalPaths.get(physicalPath2.getPathId()) + ";"); + stringBuilder.append(srcVirtualNode.getNodeId().getValue()); + stringBuilder.append("("); + stringBuilder.append(srcVirtualNode.getNodeType()); + stringBuilder.append(") --> "); + stringBuilder.append(dstVirtualNode.getNodeId().getValue()); + stringBuilder.append("("); + stringBuilder.append(dstVirtualNode.getNodeType()); + stringBuilder.append("): "); + stringBuilder.append(virtualLink2.getLinkId().getValue()); + stringBuilder.append("; "); + stringBuilder.append(physicalPath2.getPathId().getValue()); + stringBuilder.append("; "); + stringBuilder.append(physicalPath2.getPhysicalLink()); + stringBuilder.append("; "); + stringBuilder.append(mplsLabelsOfPhysicalPaths.get(physicalPath2.getPathId())); + stringBuilder.append("; "); + stringBuilder.append(meterIdsOfPhysicalPaths.get(physicalPath2.getPathId())); + stringBuilder.append(";\n"); for ( VirtualLink virtualLink3 : virtualNetwork.getVirtualLinks().getVirtualLink() ) { if ( virtualLink3.getSrcNodeId().equals(dstVirtualNode.getNodeId()) @@ -1014,11 +1313,24 @@ public class FlowUtils implements AutoCloseable { vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink3.getLinkId().getValue())); physicalPath2 = physicalNetworkHelper.getPhysicalPath(new PhysicalPathId(vnPnMappingResult.getPhysicalResourceEntityId().getValue())); - System.out.println(dstVirtualNode.getNodeId().getValue() + "(" + dstVirtualNode.getNodeType() + ") --> " + - srcVirtualNode.getNodeId().getValue() + "(" + srcVirtualNode.getNodeType() + "): " + virtualLink3.getLinkId().getValue() + "; " + - physicalPath2.getPathId().getValue() + "; " + physicalPath2.getPhysicalLink() + "; " + - mplsLabelsOfPhysicalPaths.get(physicalPath2.getPathId()) + "; " + - meterIdsOfPhysicalPaths.get(physicalPath2.getPathId()) + ";"); + stringBuilder.append(dstVirtualNode.getNodeId().getValue()); + stringBuilder.append("("); + stringBuilder.append(dstVirtualNode.getNodeType()); + stringBuilder.append(") --> "); + stringBuilder.append(srcVirtualNode.getNodeId().getValue()); + stringBuilder.append("("); + stringBuilder.append(srcVirtualNode.getNodeType()); + stringBuilder.append("): "); + stringBuilder.append(virtualLink3.getLinkId().getValue()); + stringBuilder.append("; "); + stringBuilder.append(physicalPath2.getPathId().getValue()); + stringBuilder.append("; "); + stringBuilder.append(physicalPath2.getPhysicalLink()); + stringBuilder.append("; "); + stringBuilder.append(mplsLabelsOfPhysicalPaths.get(physicalPath2.getPathId())); + stringBuilder.append("; "); + stringBuilder.append(meterIdsOfPhysicalPaths.get(physicalPath2.getPathId())); + stringBuilder.append(";\n"); printedVirtualLinks.add(virtualLink3.getLinkId()); } @@ -1027,7 +1339,8 @@ public class FlowUtils implements AutoCloseable { printedVirtualLinks.add(virtualLink2.getLinkId()); } } - // for testing - jizhigang + + LOG.debug(stringBuilder.toString()); return; } @@ -1120,8 +1433,15 @@ public class FlowUtils implements AutoCloseable { org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow nemoFlow = getFlow(nemoFlows, nemoFlowId); - long priority = 1 + operation.getPriority(); + long priority; + if ( null == operation.getPriority() ) { + priority = 1; + } else { + priority = 1 + operation.getPriority(); + } + + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetwork.getNetworkId()); List intentVnMappingResults = userIntentVnMapping.getIntentVnMappingResult(); List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); IntentId intentId = new IntentId(operation.getOperationId().getValue()); @@ -1362,7 +1682,7 @@ public class FlowUtils implements AutoCloseable { /** * TODO * - * @author Zhigang Ji, Shixing Liu + * @author Zhigang Ji, Shixing Liu, Jie Hou * @param physicalNodeId TODO * @param physicalPortId TODO * @return TODO @@ -1370,13 +1690,13 @@ public class FlowUtils implements AutoCloseable { private MacAddress getMacAddressOfConnectedExternalDevice(PhysicalNodeId physicalNodeId, PhysicalPortId physicalPortId) { com.google.common.collect.Table externalNetworkMacTable = - this.resourceManager.getExternalNetworkMacTable(); + this.phyConfigLoader.getExternalNetworkMac(); MacAddress macAddress = externalNetworkMacTable.get(physicalNodeId, physicalPortId); if(macAddress == null){ - LOG.info("nemo: cannot find external network device mac address"); + LOG.debug("nemo: cannot find external network device mac address"); } - LOG.info("nemo: external network device mac address"); + LOG.debug("nemo: external network device mac address"); return macAddress; } @@ -1385,23 +1705,202 @@ public class FlowUtils implements AutoCloseable { * TODO * * @author Zhigang Ji - * @param userIntentVnMapping TODO - * @param virtualNodeId TODO + * @param virtualNetworkId TODO + * @param virtualNode TODO * @return TODO */ - private MacAddress getGateWayMacAddress(UserIntentVnMapping userIntentVnMapping, - VirtualNodeId virtualNodeId) { + private IpAddress getGatewayIpAddress(VirtualNetworkId virtualNetworkId, + VirtualNode virtualNode) { + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetworkId); + VirtualNodeId virtualNodeId = virtualNode.getNodeId(); + VirtualNodeId virtualRouterId = null; + + switch ( virtualNode.getNodeType() ) { + case Vswitch: + Map> connectedVirtualRouters = + virtualNetworkHelper.getConnectedVirtualRouters(virtualNodeId); + + if ( null != connectedVirtualRouters && !connectedVirtualRouters.isEmpty() ) { + virtualRouterId = connectedVirtualRouters.keySet().iterator().next(); + } + break; + + case Vrouter: + virtualRouterId = virtualNodeId; + break; + + default: + break; + } + + if ( null == virtualRouterId ) { + return null; + } + + UserId userId = new UserId(virtualNetworkId.getValue()); + UserIntentVnMapping userIntentVnMapping = userIntentVnMappings.get(userId); List intentVnMappingResults = userIntentVnMapping.getIntentVnMappingResult(); + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId nodeId = null; VirtualResource virtualResource; - for ( IntentVnMappingResult intentVnMappingResult : intentVnMappingResults ) { - virtualResource = intentVnMappingResult.getVirtualResource().get(0); + VirtualPort layer2ExternalVirtualPort = + virtualNetworkHelper.getLayer2ExternalVirtualPort(virtualRouterId); + + if ( null != layer2ExternalVirtualPort ) { + for ( IntentVnMappingResult intentVnMappingResult : intentVnMappingResults ) { + if ( IntentVnMappingResult.IntentType.Node == intentVnMappingResult.getIntentType() ) { + if ( 1 == intentVnMappingResult.getVirtualResource().size() ) { + virtualResource = intentVnMappingResult.getVirtualResource().get(0); + + if ( VirtualResource.VirtualResourceType.Vport + == virtualResource.getVirtualResourceType() ) { + if ( virtualResource.getParentVirtualResourceEntityId().getValue() + .equals(virtualRouterId.getValue()) ) { + nodeId = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId( + intentVnMappingResult.getIntentId().getValue()); + + break; + } + } + } + } + } + } else { + Map> connectedVirtualSwitches = + virtualNetworkHelper.getConnectedVirtualSwitches(virtualRouterId); + + if ( null != connectedVirtualSwitches && !connectedVirtualSwitches.isEmpty() ) { + for ( IntentVnMappingResult intentVnMappingResult : intentVnMappingResults ) { + if ( IntentVnMappingResult.IntentType.Node == intentVnMappingResult.getIntentType() ) { + if ( 1 == intentVnMappingResult.getVirtualResource().size() ) { + virtualResource = intentVnMappingResult.getVirtualResource().get(0); + + if ( VirtualResource.VirtualResourceType.Vnode + == virtualResource.getVirtualResourceType() ) { + if ( virtualResource.getVirtualResourceEntityId().getValue() + .equals(virtualRouterId.getValue()) ) { + nodeId = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId( + intentVnMappingResult.getIntentId().getValue()); + + break; + } + } + } + } + } + } + } + + if ( null == nodeId ) { + return null; + } + + User user = users.get(userId); + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node node = + getNode(user.getObjects().getNode(), nodeId); + Property gatewayIpProperty = getNodeProperty(node.getProperty(), new PropertyName("gateway-ip")); + + if ( null != gatewayIpProperty ) { + String propertyValue = gatewayIpProperty.getPropertyValues().getStringValue().get(0).getValue(); + + return new IpAddress(new Ipv4Address(propertyValue)); + } else { + Property ipPrefixProperty = getNodeProperty(node.getProperty(), new PropertyName("ip-prefix")); - if ( virtualResource.getVirtualResourceEntityId().getValue().equals(virtualNodeId.getValue()) ) { - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId nodeId = - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId(intentVnMappingResult.getIntentId().getValue()); + if ( null != ipPrefixProperty ) { + String propertyValue = ipPrefixProperty.getPropertyValues().getStringValue().get(0).getValue(); + + return generateDefaultGatewayIpAddress(propertyValue); + } + } - return gatewayMacAddress.get(nodeId); + return null; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param virtualNetworkId TODO + * @param virtualNode TODO + * @return TODO + */ + private MacAddress getGatewayMacAddress(VirtualNetworkId virtualNetworkId, + VirtualNode virtualNode) { + VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetworkId); + VirtualNodeId virtualNodeId = virtualNode.getNodeId(); + + switch ( virtualNode.getNodeType() ) { + case Vswitch: + Map> connectedVirtualRouters = + virtualNetworkHelper.getConnectedVirtualRouters(virtualNodeId); + + if ( null != connectedVirtualRouters && !connectedVirtualRouters.isEmpty() ) { + VirtualNodeId virtualRouterId = connectedVirtualRouters.keySet().iterator().next(); + VirtualLink virtualLink = virtualNetworkHelper.getVirtualLink(virtualRouterId, virtualNodeId); + + UserId userId = new UserId(virtualNetworkId.getValue()); + UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); + List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); + VnPnMappingResult vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, + new VirtualResourceEntityId(virtualLink.getLinkId())); + + PhysicalPathId physicalPathId = + new PhysicalPathId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + PhysicalPath physicalPath = physicalNetworkHelper.getPhysicalPath(physicalPathId); + PhysicalLink physicalLink = + physicalNetworkHelper.getFirstPhysicalLinkOfPhysicalPath(physicalPath); + PhysicalPort physicalPort = physicalNetworkHelper + .getPhysicalPort(physicalLink.getSrcNodeId(), physicalLink.getSrcPortId()); + + return physicalPort.getMacAddress(); + } + break; + + case Vrouter: + VirtualPort layer2ExternalVirtualPort = + virtualNetworkHelper.getLayer2ExternalVirtualPort(virtualNodeId); + + if ( null != layer2ExternalVirtualPort ) { + UserId userId = new UserId(virtualNetworkId.getValue()); + UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); + List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); + VnPnMappingResult vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, + new VirtualResourceEntityId(layer2ExternalVirtualPort.getPortId().getValue())); + + PhysicalNodeId physicalNodeId = + new PhysicalNodeId(vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); + PhysicalPortId physicalPortId = + new PhysicalPortId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + PhysicalPort physicalPort = + physicalNetworkHelper.getPhysicalPort(physicalNodeId, physicalPortId); + + return physicalPort.getMacAddress(); + } + break; + + default: + break; + } + + return null; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param nodes TODO + * @param nodeId TODO + * @return TODO + */ + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node getNode( + List nodes, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId nodeId) { + for ( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node + node : nodes ) { + if ( node.getNodeId().equals(nodeId) ) { + return node; } } @@ -1429,6 +1928,26 @@ public class FlowUtils implements AutoCloseable { return null; } + /** + * TODO + * + * @author Zhigang Ji + * @param properties TODO + * @param propertyName TODO + * @return TODO + */ + private Property getNodeProperty(List properties, PropertyName propertyName) { + if ( null != properties ) { + for ( Property property : properties ) { + if ( property.getPropertyName().equals(propertyName) ) { + return property; + } + } + } + + return null; + } + /** * TODO * @@ -1515,10 +2034,10 @@ public class FlowUtils implements AutoCloseable { * @param userId TODO * @param macAddress TODO * @param physicalNodeId TODO - * @param physicalPort TODO + * @param physicalPortId TODO */ private void configMacTableEntry(UserId userId, MacAddress macAddress, - PhysicalNodeId physicalNodeId, PhysicalPort physicalPort) { + PhysicalNodeId physicalNodeId, PhysicalPortId physicalPortId) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List instructionList = new LinkedList(); List actionList = new LinkedList(); @@ -1531,7 +2050,7 @@ public class FlowUtils implements AutoCloseable { Match match = new MatchBuilder().setEthernetMatch(ethernetMatch).setMetadata(metadata).build(); - OutputAction outputAction = new OutputActionBuilder().setOutputNodeConnector(createNodeConnectorId(physicalPort.getPortId())).build(); + OutputAction outputAction = new OutputActionBuilder().setOutputNodeConnector(createNodeConnectorId(physicalPortId)).build(); OutputActionCase outputActionCase = new OutputActionCaseBuilder().setOutputAction(outputAction).build(); Action actionOutput = new ActionBuilder().setOrder(actionList.size()).setAction(outputActionCase).build(); actionList.add(actionOutput); @@ -1631,7 +2150,7 @@ public class FlowUtils implements AutoCloseable { List instructionList = new LinkedList(); List actionList = new LinkedList(); - EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long)ETH_TYPE_IP)).build()); + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long) ETH_TYPE_IP)).build()); EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); MetadataBuilder metadataBuilder = new MetadataBuilder().setMetadata(BigInteger.valueOf(metadatas.get(userId))); @@ -1725,7 +2244,7 @@ public class FlowUtils implements AutoCloseable { PhysicalLink physicalLink = physicalNetworkHelper.getFirstPhysicalLinkOfPhysicalPath(physicalPath); - EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long)ETH_TYPE_IP)).build()); + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long) ETH_TYPE_IP)).build()); EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); MetadataBuilder metadataBuilder = new MetadataBuilder().setMetadata(BigInteger.valueOf(metadatas.get(userId))); @@ -1821,11 +2340,9 @@ public class FlowUtils implements AutoCloseable { * @author Zhigang Ji * @param userId TODO * @param ipPrefix TODO - * @param macAddress TODO * @param physicalNodeId TODO */ - private void configIpTableEntry(UserId userId, IpPrefix ipPrefix, - MacAddress macAddress, PhysicalNodeId physicalNodeId) { + private void configIpTableEntry(UserId userId, IpPrefix ipPrefix, PhysicalNodeId physicalNodeId) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List instructionList = new LinkedList(); List actionList = new LinkedList(); @@ -1846,14 +2363,6 @@ public class FlowUtils implements AutoCloseable { Action actionDecNW = new ActionBuilder().setOrder(actionList.size()).setAction(decNwTtlCase).build(); actionList.add(actionDecNW); - ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetSource(new EthernetSourceBuilder().setAddress(macAddress).build()); - ethernetMatch = ethernetMatchBuilder.build(); - - SetField setField = new SetFieldBuilder().setEthernetMatch(ethernetMatch).build(); - SetFieldCase setFieldCase = new SetFieldCaseBuilder().setSetField(setField).build(); - Action actionSetField = new ActionBuilder().setOrder(actionList.size()).setAction(setFieldCase).build(); - actionList.add(actionSetField); - ApplyActions applyActions = new ApplyActionsBuilder().setAction(actionList).build(); ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build(); Instruction instructionApply = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(applyActionsCase).build(); @@ -1884,6 +2393,65 @@ public class FlowUtils implements AutoCloseable { return; } + /** + * TODO + * + * @author Zhigang Ji + * @param userId TODO + * @param virtualArp TODO + * @param physicalNodeId TODO + * @param physicalPortId TODO + */ + private void configArpTableEntry(UserId userId, VirtualArp virtualArp, + PhysicalNodeId physicalNodeId, PhysicalPortId physicalPortId) { + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + List instructionList = new LinkedList(); + List actionList = new LinkedList(); + + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long)ETH_TYPE_IP)).build()); + EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); + + Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder().setIpv4Destination(convertIpAddressToIpPrefix(virtualArp.getIpAddress()).getIpv4Prefix()); + Ipv4Match ipv4Match = ipv4MatchBuilder.build(); + + MetadataBuilder metadataBuilder = new MetadataBuilder().setMetadata(BigInteger.valueOf(metadatas.get(userId))); + Metadata metadata = metadataBuilder.build(); + + Match match = new MatchBuilder().setEthernetMatch(ethernetMatch).setLayer3Match(ipv4Match).setMetadata(metadata).build(); + + ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetDestination(new EthernetDestinationBuilder().setAddress(virtualArp.getMacAddress()).build()); + ethernetMatch = ethernetMatchBuilder.build(); + + SetField setField = new SetFieldBuilder().setEthernetMatch(ethernetMatch).build(); + SetFieldCase setFieldCase = new SetFieldCaseBuilder().setSetField(setField).build(); + Action actionSetField = new ActionBuilder().setOrder(actionList.size()).setAction(setFieldCase).build(); + actionList.add(actionSetField); + + OutputAction outputAction = new OutputActionBuilder().setOutputNodeConnector(createNodeConnectorId(physicalPortId)).build(); + OutputActionCase outputActionCase = new OutputActionCaseBuilder().setOutputAction(outputAction).build(); + Action actionOutput = new ActionBuilder().setOrder(actionList.size()).setAction(outputActionCase).build(); + actionList.add(actionOutput); + + ApplyActions applyActions = new ApplyActionsBuilder().setAction(actionList).build(); + ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build(); + Instruction instructionApply = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(applyActionsCase).build(); + instructionList.add(instructionApply); + + Instructions instructions = new InstructionsBuilder().setInstruction(instructionList).build(); + + FlowId flowId = new FlowId(UUID.randomUUID().toString()); + FlowBuilder flowBuilder = baseFlowBuilder().setId(flowId).setTableId(ARP_TABLE_ID).setPriority(DEFAULT_FLOW_PRIORITY); + Flow flow = flowBuilder.setMatch(match).setInstructions(instructions).build(); + + NodeId nodeId = createNodeId(physicalNodeId); + InstanceIdentifier flowInsId = generateFlowInsId(userId, nodeId, flow.getTableId(), flow.getId()); + + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInsId, flow, true); + writeTransaction.submit(); + + return; + } + /** * TODO * @@ -1892,14 +2460,16 @@ public class FlowUtils implements AutoCloseable { * @param virtualArp TODO * @param physicalPath TODO */ - private void configArpTableEntry(UserId userId, VirtualArp virtualArp, PhysicalPath physicalPath) { + private void configArpTableEntry(UserId userId, VirtualArp virtualArp, + PhysicalPath physicalPath) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); List instructionList = new LinkedList(); List actionList = new LinkedList(); PhysicalLink physicalLink = physicalNetworkHelper.getFirstPhysicalLinkOfPhysicalPath(physicalPath); + PhysicalPort physicalPort = physicalNetworkHelper.getPhysicalPort(physicalLink.getSrcNodeId(), physicalLink.getSrcPortId()); - EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long)ETH_TYPE_IP)).build()); + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(new EthernetTypeBuilder().setType(new EtherType((long) ETH_TYPE_IP)).build()); EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder().setIpv4Destination(convertIpAddressToIpPrefix(virtualArp.getIpAddress()).getIpv4Prefix()); @@ -1920,6 +2490,14 @@ public class FlowUtils implements AutoCloseable { Action actionSetField = new ActionBuilder().setOrder(actionList.size()).setAction(setFieldCase).build(); actionList.add(actionSetField); + ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetSource(new EthernetSourceBuilder().setAddress(physicalPort.getMacAddress()).build()); + ethernetMatch = ethernetMatchBuilder.build(); + + setField = new SetFieldBuilder().setEthernetMatch(ethernetMatch).build(); + setFieldCase = new SetFieldCaseBuilder().setSetField(setField).build(); + actionSetField = new ActionBuilder().setOrder(actionList.size()).setAction(setFieldCase).build(); + actionList.add(actionSetField); + ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetDestination(new EthernetDestinationBuilder().setAddress(virtualArp.getMacAddress()).build()); ethernetMatch = ethernetMatchBuilder.build(); @@ -2064,7 +2642,7 @@ public class FlowUtils implements AutoCloseable { Action actionPushMPLS = new ActionBuilder().setOrder(actionList.size()).setAction(pushMplsActionCase).build(); actionList.add(actionPushMPLS); - SetField setField = new SetFieldBuilder().setProtocolMatchFields(new ProtocolMatchFieldsBuilder().setMplsLabel((long)mplsLabelsOfPhysicalPaths.get(outPhysicalPath.getPathId()).get(0)).build()).build(); + SetField setField = new SetFieldBuilder().setProtocolMatchFields(new ProtocolMatchFieldsBuilder().setMplsLabel((long) mplsLabelsOfPhysicalPaths.get(outPhysicalPath.getPathId()).get(0)).build()).build(); SetFieldCase setFieldCase = new SetFieldCaseBuilder().setSetField(setField).build(); Action actionSetField = new ActionBuilder().setOrder(actionList.size()).setAction(setFieldCase).build(); actionList.add(actionSetField); @@ -2158,6 +2736,59 @@ public class FlowUtils implements AutoCloseable { return matchBuilder.build(); } + /** + * TODO + * + * @author Zhigang Ji + * @param payload TODO + * @param ingress TODO + * @param egress TODO + */ + private void sendPacketOut(byte[] payload, NodeConnectorRef ingress, NodeConnectorRef egress) { + TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder().setPayload(payload).setNode(createNodeRef(egress)); + TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.setEgress(egress).setIngress(ingress).build(); + + packetProcessingService.transmitPacket(transmitPacketInput); + + return; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param ethernet TODO + * @param arp TODO + * @return TODO + */ + private byte[] createArpPacket(Ethernet ethernet, ARP arp) { + try { + ethernet.setRawPayload(arp.serialize()); + } catch ( PacketException exception ) { + LOG.error("Failed to encode the arp packet, smac: {}, sip: {}, dmac: {}, dip: {}.", + convertByteArray6ToMacAddress(arp.getSenderHardwareAddress()).getValue(), + convertByteArray4ToIpAddress(arp.getSenderProtocolAddress()).getIpv4Address().getValue(), + convertByteArray6ToMacAddress(arp.getTargetHardwareAddress()).getValue(), + convertByteArray4ToIpAddress(arp.getTargetProtocolAddress()).getIpv4Address().getValue()); + + return null; + } + + byte[] arpPacket; + + try { + arpPacket = ethernet.serialize(); + } catch ( PacketException exception ) { + LOG.error("Failed to encode the ethernet packet, smac: {}, dmac: {}.", + convertByteArray6ToMacAddress(ethernet.getSourceMACAddress()).getValue(), + convertByteArray6ToMacAddress(ethernet.getDestinationMACAddress()).getValue()); + + return null; + } + + return arpPacket; + } + /** * TODO * @@ -2229,11 +2860,11 @@ public class FlowUtils implements AutoCloseable { * TODO * * @author Zhigang Ji - * @param physicalNodeId TODO + * @param nodeConnectorRef TODO * @return TODO */ - private NodeRef createNodeRef(PhysicalNodeId physicalNodeId) { - return new NodeRef(createNodePath(createNodeId(physicalNodeId))); + private NodeRef createNodeRef(NodeConnectorRef nodeConnectorRef) { + return new NodeRef(nodeConnectorRef.getValue().firstIdentifierOf(Node.class)); } /** @@ -2261,6 +2892,36 @@ public class FlowUtils implements AutoCloseable { return createTablePath(nodeId, tableId).child(Flow.class, new FlowKey(flowId)); } + /** + * TODO + * + * @author Zhigang Ji + * @param nodeConnectorRef TODO + * @return TODO + */ + private PhysicalPortId convertNodeConnectorRefToPhysicalPortId(NodeConnectorRef nodeConnectorRef) { + PhysicalPortId physicalPortId = new PhysicalPortId( + nodeConnectorRef.getValue().firstIdentifierOf(NodeConnector.class) + .firstKeyOf(NodeConnector.class).getId().getValue()); + + return physicalPortId; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param nodeConnectorRef TODO + * @return TODO + */ + private PhysicalNodeId convertNodeConnectorRefToPhysicalNodeId(NodeConnectorRef nodeConnectorRef) { + PhysicalNodeId physicalNodeId = new PhysicalNodeId( + nodeConnectorRef.getValue().firstIdentifierOf(Node.class) + .firstKeyOf(Node.class).getId().getValue()); + + return physicalNodeId; + } + /** * TODO * @@ -2272,6 +2933,76 @@ public class FlowUtils implements AutoCloseable { return new IpPrefix(new Ipv4Prefix(ipAddress.getIpv4Address().getValue() + "/32")); } + /** + * TODO + * + * @author Zhigang Ji + * @param byteArray TODO + * @return TODO + */ + private IpAddress convertByteArray4ToIpAddress(byte[] byteArray) { + char[] charArray = NetUtils + .getInetAddress(NetUtils.byteArray4ToInt(byteArray)).getHostAddress().toCharArray(); + + return new IpAddress(charArray); + } + + /** + * TODO + * + * @author Zhigang Ji + * @param byteArray TODO + * @return TODO + */ + private MacAddress convertByteArray6ToMacAddress(byte[] byteArray) { + return new MacAddress(HexEncode.bytesToHexStringFormat(byteArray)); + } + + /** + * TODO + * + * @author Zhigang Ji + * @param macAddress TODO + * @return TODO + */ + private byte[] convertMacAddressToByteArray6(MacAddress macAddress) { + byte[] byteArray = new byte[6]; + String[] segments = macAddress.getValue().split(":"); + + for ( int i = 0; i < 6; i++ ) { + byteArray[i] = (byte)Integer.parseInt(segments[i], 16); + } + + return byteArray; + } + + /** + * TODO + * + * @author Zhigang Ji + * @param ipPrefix TODO + * @return TODO + */ + private IpAddress generateDefaultGatewayIpAddress(String ipPrefix) { + int indexOfSlash = ipPrefix.indexOf('/'); + + String strIpAddress = ipPrefix.substring(0, indexOfSlash); + int mask = Integer.parseInt(ipPrefix.substring(indexOfSlash + 1)); + + String[] segments = strIpAddress.split("\\."); + + int intIpAddress = (Integer.parseInt(segments[0]) << 24) | (Integer.parseInt(segments[1]) << 16); + intIpAddress |= (Integer.parseInt(segments[2]) << 8) | (Integer.parseInt(segments[3])); + + int intGatewayIpAddress = ((intIpAddress >> (32 - mask)) << (32 - mask)) + 1; + String strGatewayIpAddress = ((intGatewayIpAddress >> 24) & 0xff) + "." + + ((intGatewayIpAddress >> 16) & 0xff) + "." + + ((intGatewayIpAddress >> 8) & 0xff) + "." + + (intGatewayIpAddress & 0xff); + + return new IpAddress(new Ipv4Address(strGatewayIpAddress)); + } + /** * TODO * @@ -2441,7 +3172,7 @@ public class FlowUtils implements AutoCloseable { private Map layer3ExternalVirtualPortMap; private Map>> virtualSwitchConnectedInternalVirtualPortMap; private Map>> virtualRouterConnectedInternalVirtualPortMap; - private Map virtualArpMap; + private Map ipAddressKeyVirtualArpMap; private Map macAddressKeyVirtualArpMap; public VirtualNetworkHelper(VirtualNetwork virtualNetwork) { @@ -2456,7 +3187,7 @@ public class FlowUtils implements AutoCloseable { new HashMap>>(); virtualRouterConnectedInternalVirtualPortMap = new HashMap>>(); - virtualArpMap = new HashMap(); + ipAddressKeyVirtualArpMap = new HashMap(); macAddressKeyVirtualArpMap = new HashMap(); List virtualNodes = virtualNetwork.getVirtualNodes().getVirtualNode(); @@ -2535,21 +3266,40 @@ public class FlowUtils implements AutoCloseable { List virtualArps = virtualNetwork.getVirtualArps().getVirtualArp(); for ( VirtualArp virtualArp : virtualArps ) { - virtualArpMap.put(virtualArp.getKey(), virtualArp); + ipAddressKeyVirtualArpMap.put(virtualArp.getIpAddress(), virtualArp); macAddressKeyVirtualArpMap.put(virtualArp.getMacAddress(), virtualArp); } return; } + protected VirtualNode getVirtualNode(VirtualNodeId virtualNodeId) { + return virtualNodeMap.get(virtualNodeId); + } + protected VirtualLink getVirtualLink(VirtualLinkId virtualLinkId) { return virtualLinkMap.get(virtualLinkId); } + protected VirtualLink getVirtualLink(VirtualNodeId source, VirtualNodeId destination) { + for ( VirtualLink virtualLink : virtualLinkMap.values() ) { + if ( virtualLink.getSrcNodeId().equals(source) + && virtualLink.getDestNodeId().equals(destination) ) { + return virtualLink; + } + } + + return null; + } + protected VirtualPath getVirtualPath(VirtualPathId virtualPathId) { return virtualPathMap.get(virtualPathId); } + protected VirtualPort getVirtualPort(VirtualNodeId virtualNodeId, VirtualPortId virtualPortId) { + return virtualPortMap.get(virtualNodeId).get(virtualPortId); + } + protected Map getVirtualRouters() { return virtualRouterMap; } @@ -2572,8 +3322,85 @@ public class FlowUtils implements AutoCloseable { return virtualRouterConnectedInternalVirtualPortMap.get(virtualNodeId); } + protected VirtualArp getVirtualArp(IpAddress ipAddress) { + return ipAddressKeyVirtualArpMap.get(ipAddress); + } + protected VirtualArp getVirtualArp(MacAddress macAddress) { return macAddressKeyVirtualArpMap.get(macAddress); } + + protected void addVirtualArp(VirtualArp virtualArp) { + ipAddressKeyVirtualArpMap.put(virtualArp.getIpAddress(), virtualArp); + macAddressKeyVirtualArpMap.put(virtualArp.getMacAddress(), virtualArp); + + // TODO: Store this new virtual arp into the data store. + + return; + } + + protected boolean isLayer2ExternalVirtualPort(VirtualPort virtualPort) { + if ( VirtualPort.PortType.External == virtualPort.getPortType() + && null != virtualPort.getExternalMacAddresses() ) { + return true; + } + + return false; + } + } + + /** + * TODO + * + * @author Zhigang Ji + */ + private class ArpHandlerHelper { + Map> externalPhysicalPortMapping; + + public ArpHandlerHelper() { + super(); + + externalPhysicalPortMapping = + new HashMap>(); + + return; + } + + protected void update(UserVnPnMapping userVnPnMapping) { + VirtualNetworkId virtualNetworkId = userVnPnMapping.getVirtualNetworkId(); + List vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); + NodeConnectorRef nodeConnectorRef; + PhysicalNodeId physicalNodeId; + PhysicalPortId physicalPortId; + VirtualNodeId virtualNodeId; + VirtualPortId virtualPortId; + + for ( VnPnMappingResult vnPnMappingResult : vnPnMappingResults ) { + if ( VirtualResource.VirtualResourceType.Vport + == vnPnMappingResult.getVirtualResourceType() ) { + physicalNodeId = + new PhysicalNodeId(vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); + physicalPortId = + new PhysicalPortId(vnPnMappingResult.getPhysicalResourceEntityId().getValue()); + nodeConnectorRef = createNodeConnectorRef(physicalNodeId, physicalPortId); + + virtualNodeId = + new VirtualNodeId(vnPnMappingResult.getParentVirtualResourceEntityId().getValue()); + virtualPortId = + new VirtualPortId(vnPnMappingResult.getVirtualResourceEntityId().getValue()); + + externalPhysicalPortMapping.put(nodeConnectorRef, + new ImmutableTriple( + virtualNetworkId, virtualNodeId, virtualPortId)); + } + } + + return; + } + + protected ImmutableTriple getMappingValueForExternalPhysicalPort( + NodeConnectorRef nodeConnectorRef) { + return externalPhysicalPortMapping.get(nodeConnectorRef); + } } } diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/OpenflowRenderer.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/OpenflowRenderer.java index 3181776..32bff19 100644 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/OpenflowRenderer.java +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/OpenflowRenderer.java @@ -9,46 +9,53 @@ package org.opendaylight.nemo.renderer.openflow; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoader; +import org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhysicalNetworkAdapter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; - public class OpenflowRenderer implements AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(OpenflowRenderer.class); - - private DataBroker dataBroker; - private final ResourceManager resourceManager; - private final FlowTableManager flowTableMng; - - public OpenflowRenderer(DataBroker dataBroker) { - super(); - this.dataBroker = dataBroker; - System.out.println(); - System.out.println("Waiting for loading config file about 30s..."); + private static final Logger LOG = LoggerFactory.getLogger(OpenflowRenderer.class); - LOG.info("New ResourceManager."); - resourceManager = new ResourceManager(dataBroker); + private final DataBroker dataBroker; + private final NotificationProviderService notificationProviderService; + private final PacketProcessingService packetProcessingService; - LOG.info("New FlowTableManager."); - flowTableMng = new FlowTableManager(dataBroker, resourceManager); + private final PhyConfigLoader phyConfigLoader; + private final FlowTableManager flowTableMng; + private PhysicalNetworkAdapter physicalNetworkAdapter; - LOG.info("Initialized openflow renderer."); + public OpenflowRenderer(DataBroker dataBroker, + NotificationProviderService notificationProviderService, + PacketProcessingService packetProcessingService) { + super(); + + this.dataBroker = dataBroker; + this.notificationProviderService = notificationProviderService; + this.packetProcessingService = packetProcessingService; + + phyConfigLoader = new PhyConfigLoader(dataBroker); + LOG.debug("New FlowTableManager."); + flowTableMng = new FlowTableManager(dataBroker + , packetProcessingService + , phyConfigLoader); + physicalNetworkAdapter = new PhysicalNetworkAdapter(dataBroker + , notificationProviderService + , phyConfigLoader + , flowTableMng.getFlowUtils()); + + LOG.info("Initialized the NEMO OpenFlow renderer."); } - - // ************* + + // ************* // AutoCloseable // ************* @Override public void close() throws Exception { - if (flowTableMng != null) flowTableMng.close(); - if (resourceManager != null) resourceManager.close(); + if (flowTableMng != null) flowTableMng.close(); + if (physicalNetworkAdapter != null) physicalNetworkAdapter.close(); } } - diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/ResourceManager.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/ResourceManager.java deleted file mode 100644 index 5101748..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/ResourceManager.java +++ /dev/null @@ -1 +0,0 @@ -/* * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.nemo.renderer.openflow; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import com.google.common.util.concurrent.CheckedFuture; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.lang.*; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetworkBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.AttributeName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalPortId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalLinkId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddresses; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalHosts; import org.opendaylight.nemo.renderer.openflow.entity.ResourceBean; public class ResourceManager implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(ResourceManager.class); public final static String PROPERTY_FILE_PATH = "etc/nemo/nemo-openflow-renderer-resource.json"; final private DataBroker dataProvider; private ObjectMapper objectMapper = null; private Table externalNetworkMacTable; public ResourceManager(DataBroker dataProvider){ this.dataProvider = dataProvider; this.objectMapper = new ObjectMapper(); this.externalNetworkMacTable = HashBasedTable.create(); String resourceInfo = ReadFile(PROPERTY_FILE_PATH); buildPhysicalNetworkFromConfig(resourceInfo); LOG.info("nemo:Initialized resource manager for Openflow renderer."); } public Table getExternalNetworkMacTable(){ return this.externalNetworkMacTable; } private void buildPhysicalNetworkFromConfig(String resource) { try { PhysicalNetworkBuilder phyNetwrokBuilder= new PhysicalNetworkBuilder(); PhysicalNodeBuilder phyNodeBuilder = new PhysicalNodeBuilder(); JsonNode rootNode = objectMapper.readTree(resource); JsonNode pn = rootNode.path("physicalnetwork"); JsonNode nodes = pn.path("node"); JsonNode links = pn.path("link"); JsonNode hosts = pn.path("host"); LOG.debug("Import physical nodes into DataStore."); for(int i = 0; i< nodes.size(); i++){ LOG.debug("build physical node execution body"); //JsonNode node = nodeIt.next(); JsonNode node = nodes.get(i); JsonNode ports = node.path("port"); PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder(); nodeBuilder.setNodeId(new PhysicalNodeId(node.get("node-id").asText())); PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId()); nodeBuilder.setKey(key); String nodetype = node.get("node-type").asText(); if((!(nodetype.equals("switch"))) && (!(nodetype.equals("router")))){ continue; } if(nodetype.equals("switch")) { nodeBuilder.setNodeType(PhysicalNodeInstance.NodeType.Switch); }else if(nodetype.equals("router")){ nodeBuilder.setNodeType(PhysicalNodeInstance.NodeType.Router); } List phyPortList = new ArrayList(); //for (Iterator portIt = ports.elements(); portIt.hasNext(); ) { for(int j =0; j < ports.size(); j++){ LOG.debug("build physical port execution body"); //JsonNode port = portIt.next(); JsonNode port = ports.get(j); PhysicalPortBuilder phyPortbuilder = new PhysicalPortBuilder(); phyPortbuilder.setPortId(new PhysicalPortId(port.get("port-id").asText())); if((port.get("port-type").asText()).equals("external")) { phyPortbuilder.setPortType(PhysicalPortInstance.PortType.External); } else { phyPortbuilder.setPortType(PhysicalPortInstance.PortType.Internal); } //add mac-address for each port LOG.info("nemo:j=" + j); MacAddress mac = new MacAddress(port.get("port-mac-address").asText()); phyPortbuilder.setMacAddress(mac); phyPortbuilder.setBandwidth((long) (port.get("bandwidth").asInt())); JsonNode attrs = port.path("attribute"); List AttrList = new ArrayList(); for(int r = 0; r < attrs.size(); r++){ LOG.debug("build physical port attribute execution body."); JsonNode portattr = attrs.get(r); AttributeBuilder attrbuilder = new AttributeBuilder(); attrbuilder.setAttributeName(new AttributeName(portattr.path("name").asText())); AttributeValueBuilder avbd = new AttributeValueBuilder(); avbd.setStringValue(portattr.path("value").asText()); attrbuilder.setKey(new AttributeKey(attrbuilder.getAttributeName())); attrbuilder.setAttributeValue(avbd.build()); Attribute attr_instance = attrbuilder.build(); AttrList.add(attr_instance); } /* Iterator keys = attrs.fieldNames(); while(keys.hasNext()) { LOG.info("build physical port attribute execution body."); String fieldName = keys.next(); attrbuilder.setAttributeName(new AttributeName(fieldName)); AttributeValueBuilder avbd = new AttributeValueBuilder(); avbd.setStringValue(attrs.path(fieldName).asText()); attrbuilder.setKey(new AttributeKey(attrbuilder.getAttributeName())); attrbuilder.setAttributeValue(avbd.build()); Attribute attr_instance = attrbuilder.build(); AttrList.add(attr_instance); } */ phyPortbuilder.setAttribute(AttrList); phyPortList.add(phyPortbuilder.build()); } nodeBuilder.setPhysicalPort(phyPortList); /*node attribute list*/ JsonNode node_attrs = node.path("attribute"); List node_AttrList = new ArrayList(); for(int t = 0; t < node_attrs.size(); t++){ LOG.debug("build physical node attribute execution body."); JsonNode node_attr = node_attrs.get(t); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attrbuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder(); attrbuilder.setAttributeName(new AttributeName(node_attr.path("name").asText())); AttributeValueBuilder avbd = new AttributeValueBuilder(); avbd.setStringValue(node_attr.path("value").asText()); attrbuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attrbuilder.getAttributeName())); attrbuilder.setAttributeValue(avbd.build()); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute node_attr_instance = attrbuilder.build(); node_AttrList.add(node_attr_instance); } nodeBuilder.setAttribute((List) node_AttrList); PhysicalNode phyNode = nodeBuilder.build(); //phyNodeList.add(phyNode); LOG.debug("Ready to write node to data store."); try { WriteTransaction t = dataProvider.newWriteOnlyTransaction(); InstanceIdentifier phynode_iid = InstanceIdentifier .builder(PhysicalNetwork.class) .child(PhysicalNodes.class) .child(PhysicalNode.class, key) .build(); t.put(LogicalDatastoreType.OPERATIONAL, phynode_iid, phyNode, true); CheckedFuture f = t.submit(); Futures.addCallback(f, new FutureCallback() { @Override public void onFailure(Throwable t) { System.out.println("write transaction onFailure."); LOG.error("Could not write PhysicalNode", t); } @Override public void onSuccess(Void result) { //System.out.println("write transaction onSuccess."); LOG.debug("write transaction onSuccess."); } }); } catch (Exception e) { e.printStackTrace(); } } LOG.debug("Import physical links into DataStore."); for(int m = 0; m< links.size(); m++){ LOG.debug("build physical link execution body"); JsonNode link = links.get(m); String strLeftNodeId = link.get("left-node-id").asText(); String strRightNodeId = link.get("right-node-id").asText(); if(strLeftNodeId.contains("external")||strRightNodeId.contains("external")){ String strExternalNodeId = ""; PhysicalNodeId accessNodeId = null; PhysicalPortId accessPortId = null; if(strLeftNodeId.contains("external")){ strExternalNodeId = strLeftNodeId; accessNodeId = new PhysicalNodeId(link.get("right-node-id").asText()); accessPortId = new PhysicalPortId(link.get("right-port-id").asText()); }else{ strExternalNodeId = strRightNodeId; accessNodeId = new PhysicalNodeId(link.get("left-node-id").asText()); accessPortId = new PhysicalPortId(link.get("left-port-id").asText()); } for(int b = 0; b < nodes.size(); b++){ JsonNode pnode = nodes.get(b); if(strExternalNodeId.equals(pnode.get("node-id").asText())){ MacAddress macAddress = new MacAddress(pnode.get("mac-address").asText()); this.externalNetworkMacTable.put(accessNodeId, accessPortId, macAddress); break; } } continue; } PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); PhysicalLinkId phylinkid = new PhysicalLinkId(link.get("link-id").asText()); linkBuilder.setLinkId(phylinkid); linkBuilder.setSrcNodeId(new PhysicalNodeId(link.get("left-node-id").asText())); linkBuilder.setSrcPortId(new PhysicalPortId(link.get("left-port-id").asText())); linkBuilder.setDestNodeId(new PhysicalNodeId(link.get("right-node-id").asText())); linkBuilder.setDestPortId(new PhysicalPortId(link.get("right-port-id").asText())); linkBuilder.setBandwidth((long) (link.get("link-bandwidth").asLong())); linkBuilder.setDelay((long) (link.get("delay").asLong())); linkBuilder.setMetric((long) (link.get("metric").asLong())); linkBuilder.setLossRate((short) (link.get("delay").asInt())); PhysicalLink phyLink = linkBuilder.build(); LOG.debug("Ready to write link to data store."); try { WriteTransaction t = dataProvider.newWriteOnlyTransaction(); InstanceIdentifier phylink_iid = InstanceIdentifier .builder(PhysicalNetwork.class) .child(PhysicalLinks.class) .child(PhysicalLink.class, new PhysicalLinkKey(linkBuilder.getLinkId())) .build(); t.put(LogicalDatastoreType.OPERATIONAL, phylink_iid, phyLink, true); CheckedFuture f = t.submit(); Futures.addCallback(f, new FutureCallback() { @Override public void onFailure(Throwable t) { System.out.println("write transaction onFailure."); LOG.error("Could not write PhysicalLink", t); } @Override public void onSuccess(Void result) { //System.out.println("write transaction onSuccess."); LOG.debug("write transaction onSuccess."); } }); } catch (Exception e) { e.printStackTrace(); } } LOG.debug("Import hosts into DataStore."); for(int n = 0; n< hosts.size(); n++){ LOG.debug("build host execution body"); JsonNode host = hosts.get(n); PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder(); hostBuilder.setHostId(new PhysicalHostId(host.get("id").asText())); hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId())); hostBuilder.setHostName(new PhysicalHostName(host.get("name").asText())); IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder(); List ipList = new ArrayList(); JsonNode ipaddrs = host.path("ip-addresses"); for(int p = 0 ; p < ipaddrs.size(); p++){ JsonNode ipaddr = ipaddrs.get(p); IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get("ip-address").asText())); ipList.add(ip); } IpAddrBuilder.setIpAddress(ipList); hostBuilder.setIpAddresses(IpAddrBuilder.build()); MacAddress mac = new MacAddress(host.get("mac-address").asText()); hostBuilder.setMacAddress(mac); hostBuilder.setNodeId(new PhysicalNodeId(host.get("node-id").asText())); hostBuilder.setPortId(new PhysicalPortId(host.get("connector-id").asText())); PhysicalHost phyHost = hostBuilder.build(); LOG.debug("Ready to write host to data store."); try { WriteTransaction t = dataProvider.newWriteOnlyTransaction(); InstanceIdentifier phyhost_iid = InstanceIdentifier .builder(PhysicalNetwork.class) .child(PhysicalHosts.class) .child(PhysicalHost.class, new PhysicalHostKey(hostBuilder.getHostId())) .build(); t.put(LogicalDatastoreType.OPERATIONAL, phyhost_iid, phyHost, true); CheckedFuture f = t.submit(); Futures.addCallback(f, new FutureCallback() { @Override public void onFailure(Throwable t) { System.out.println("write transaction onFailure."); LOG.error("Could not write PhysicalHost", t); } @Override public void onSuccess(Void result) { //System.out.println("write transaction onSuccess."); LOG.debug("write transaction onSuccess."); } }); } catch (Exception e) { e.printStackTrace(); } } } catch (JsonProcessingException e) { e.printStackTrace(); } catch(IOException e){ e.printStackTrace(); } LOG.debug("buildPhysicalNetworkFromConfig end."); System.out.print("Loading physical network configuration has been completed."); } private String ReadFile(String Path){ BufferedReader reader = null; String laststr = ""; try{ FileInputStream fileInputStream = new FileInputStream(Path); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); reader = new BufferedReader(inputStreamReader); String tempString = null; while((tempString = reader.readLine()) != null){ laststr += tempString; } reader.close(); }catch(IOException e){ e.printStackTrace(); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } return laststr; } @Override public void close() throws Exception { } } \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/HostBean.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/HostBean.java deleted file mode 100644 index 66056fb..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/HostBean.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.nemo.renderer.openflow.entity; - -import java.util.List; - -public class HostBean { - - public String getHostName() { - return hostName; - } - - public void setHostName(String hostName) { - this.hostName = hostName; - } - - private String hostName; - - public List getIPAddressList() { - return this.IPAddressList; - } - - public void setStringList(List IPAddressList) { - this.IPAddressList = IPAddressList; - } - - private List IPAddressList; - - public String getMacAddress() { - return macAddress; - } - - public void setMacAddress(String macAddress) { - this.macAddress = macAddress; - } - - private String macAddress; - - public String getNodeID() { - return nodeID; - } - - public void setNodeID(String nodeID) { - this.nodeID = nodeID; - } - - private String nodeID; - - public String getConnectorID() { - return connectorID; - } - - public void setConnectorID(String connectorID) { - this.connectorID = connectorID; - } - - private String connectorID; - -} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBean.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBean.java deleted file mode 100644 index 20196a9..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBean.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.nemo.renderer.openflow.entity; - -public class LinkBean { - - private String linkID; - private String leftNodeID; - private String leftPortID; - private String rightPortID; - private String linkBandwidth; - - public String getLinkID() { - return linkID; - } - - public void setLinkID(String linkID) { - this.linkID = linkID; - } - - public String getLeftNodeID() { - return leftNodeID; - } - - public void setLeftNodeID(String leftNodeID) { - this.leftNodeID = leftNodeID; - } - - public String getLeftPortID() { - return leftPortID; - } - - public void setLeftPortID(String leftPortID) { - this.leftPortID = leftPortID; - } - - public String getRightNodeID() { - return rightNodeID; - } - - public void setRightNodeID(String rightNodeID) { - this.rightNodeID = rightNodeID; - } - - private String rightNodeID; - - public String getRightPortID() { - return rightPortID; - } - - public void setRightPortID(String rightPortID) { - this.rightPortID = rightPortID; - } - - public String getLinkBandwidth() { - return linkBandwidth; - } - - public void setLinkBandwidth(String linkBandwidth) { - this.linkBandwidth = linkBandwidth; - } - -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBean.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBean.java deleted file mode 100644 index c503726..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBean.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.nemo.renderer.openflow.entity; - -import org.opendaylight.nemo.renderer.openflow.entity.PortBean; -import java.util.List; - -public class NodeBean { - - private String nodeID; - private String nodeType; - private String nodeCapacity; - private List portList; - - public String getNodeID() { - return nodeID; - } - - public void setNodeID(String nodeID) { - this.nodeID = nodeID; - } - - public String getNodeType() { - return nodeType; - } - - public void setNodeType(String nodeType) { - this.nodeType = nodeType; - } - - public String getNodeCapacity() { - return nodeCapacity; - } - - public void setNodeCapacity(String nodeCapacity) { - this.nodeCapacity = nodeCapacity; - } - - public List getPortList() { - return portList; - } - - public void setPortList(List portList) { - this.portList = portList; - } - -} - diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/PortBean.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/PortBean.java deleted file mode 100644 index f369677..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/PortBean.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.nemo.renderer.openflow.entity; - -public class PortBean { - - private String portID; - private String portIPAddress; - private String mask; - private String location; - private String bandwidth; - - public String getPortID() { - return portID; - } - - public void setPortID(String portID) { - this.portID = portID; - } - - public String getPortIPAddress() { - return portIPAddress; - } - - public void setPortIPAddress(String portIPAddress) { - this.portIPAddress = portIPAddress; - } - - public String getMask() { - return mask; - } - - public void setMask(String mask) { - this.mask = mask; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - public String getBandwidth() { - return bandwidth; - } - - public void setBandwidth(String bandwidth) { - this.bandwidth = bandwidth; - } -} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBean.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBean.java deleted file mode 100644 index d3085d9..0000000 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBean.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.nemo.renderer.openflow.entity; -import org.opendaylight.nemo.renderer.openflow.entity.NodeBean; -import org.opendaylight.nemo.renderer.openflow.entity.LinkBean; -import org.opendaylight.nemo.renderer.openflow.entity.HostBean; - -import java.util.List; - -public class ResourceBean { - public List getNodelist() { - return nodelist; - } - - public void setNodelist(List nodelist) { - this.nodelist = nodelist; - } - - private List nodelist; - - public List getLinklist() { - return linklist; - } - - public void setLinklist(List linklist) { - this.linklist = linklist; - } - - private List linklist; - - public List getHostlist() { - return hostlist; - } - - public void setHostlist(List hostlist) { - this.hostlist = hostlist; - } - - private List hostlist; - - //getter ,setter -} - diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/DataBrokerAdapter.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/DataBrokerAdapter.java new file mode 100644 index 0000000..4885762 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/DataBrokerAdapter.java @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalHosts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** +* Created by hj on 11/6/15. +*/ +public class DataBrokerAdapter { + private static final Logger log = LoggerFactory.getLogger(DataBrokerAdapter.class); + final private DataBroker dataBroker; + private static final String DEFAULT_TOPOLOGY_ID = "flow:1"; + + + public DataBrokerAdapter(DataBroker dataBroker) { + this.dataBroker = dataBroker; + } + + + + private InstanceIdentifier getPhysicalHostIdentifier(PhysicalHostKey physicalHostKey) { + return InstanceIdentifier + .builder(PhysicalNetwork.class) + .child(PhysicalHosts.class) + .child(PhysicalHost.class, physicalHostKey) + .build(); + } + private InstanceIdentifier getPhysicalNodeIdentifier(PhysicalNodeKey physicalNodeKey) { + return InstanceIdentifier + .builder(PhysicalNetwork.class) + .child(PhysicalNodes.class) + .child(PhysicalNode.class, physicalNodeKey) + .build(); + } + private InstanceIdentifier getPhysicalLinkIdentifier(PhysicalLinkKey physicalLinkKey) { + return InstanceIdentifier + .builder(PhysicalNetwork.class) + .child(PhysicalLinks.class) + .child(PhysicalLink.class, physicalLinkKey) + .build(); + } + + protected void addPhysicalHost(final PhysicalHost physicalHost) { + try { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + final InstanceIdentifier instanceIdentifier = getPhysicalHostIdentifier(physicalHost.getKey()); + + transaction.put(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, physicalHost, true); + + CheckedFuture future = transaction.submit(); + Futures.addCallback(future, new FutureCallback() { + @Override + public void onFailure(Throwable t) { + log.warn("Could not write PhysicalHost: {} {}", physicalHost, t); + } + + @Override + public void onSuccess(Void result) { + //System.out.println("write transaction onSuccess."); + log.debug("Write PhysicalHost transaction onSuccess: {}.", physicalHost); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + protected boolean addPhysicalNode(final PhysicalNode physicalNode){ + final boolean[] addResult = {false}; + try { + WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + InstanceIdentifier identifier = getPhysicalNodeIdentifier(physicalNode.getKey()); + t.put(LogicalDatastoreType.OPERATIONAL, identifier, physicalNode, true); + + CheckedFuture future = t.submit(); + Futures.addCallback(future, new FutureCallback() { + @Override + public void onFailure(Throwable t) { + log.warn("Could not write PhysicalNode {} : {}",physicalNode, t); + } + + @Override + public void onSuccess(Void result) { + addResult[0] = true; + log.debug("write transaction onSuccess."); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + return addResult[0]; + } + protected boolean removePhysicalNode(final PhysicalNodeKey nodeKey){ + final boolean[] removeResult = {false}; + try { + WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + InstanceIdentifier identifier = getPhysicalNodeIdentifier(nodeKey); + t.delete(LogicalDatastoreType.OPERATIONAL, identifier); + + CheckedFuture future = t.submit(); + Futures.addCallback(future, new FutureCallback() { + @Override + public void onFailure(Throwable t) { + log.error("Could not delete PhysicalNode {} : {}",nodeKey, t); + } + + @Override + public void onSuccess(Void result) { + removeResult[0]=true; + log.debug("Delete {} transaction onSuccess.",nodeKey); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + return removeResult[0]; + } + + protected void addPhysicalLink(final PhysicalLink physicalLink){ + try { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + final InstanceIdentifier linkIdentifier = getPhysicalLinkIdentifier(physicalLink.getKey()); + transaction.put(LogicalDatastoreType.OPERATIONAL, linkIdentifier, physicalLink, true); + + CheckedFuture f = transaction.submit(); + Futures.addCallback(f, new FutureCallback() { + @Override + public void onFailure(Throwable t) { + log.warn("Could not put PhysicalLink {} : {}",physicalLink.getKey(), t); + } + + @Override + public void onSuccess(Void result) { + //System.out.println("write transaction onSuccess."); + log.debug("Put transaction onSuccess:{}.",physicalLink.getKey()); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + } + protected void removePhysicalLink(final PhysicalLinkKey physicalLinkKey){ + try { + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + final InstanceIdentifier linkIdentifier = getPhysicalLinkIdentifier(physicalLinkKey); + transaction.delete(LogicalDatastoreType.OPERATIONAL, linkIdentifier); + + CheckedFuture f = transaction.submit(); + Futures.addCallback(f, new FutureCallback() { + @Override + public void onFailure(Throwable t) { + log.warn("Could not remove PhysicalLink {} : {}",physicalLinkKey, t); + } + + @Override + public void onSuccess(Void result) { + //System.out.println("write transaction onSuccess."); + log.debug("Remove transaction onSuccess:{}.", physicalLinkKey); + } + }); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFLinkListener.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFLinkListener.java new file mode 100644 index 0000000..cf28492 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFLinkListener.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.Set; + +/** + * Created by hj on 11/5/15. + */ +public class OFLinkListener implements DataChangeListener { + private static final Logger log = LoggerFactory.getLogger(OFLinkListener.class); + final private PhysicalNetworkAdapter pnConverter; + + protected OFLinkListener(PhysicalNetworkAdapter pnConverter) { + this.pnConverter = pnConverter; + } + + @Override + public void onDataChanged(AsyncDataChangeEvent, DataObject> change) { + if (null == change) { + return; + } + Link tmpOfLink = null; + + Map, DataObject> createdData = change.getCreatedData(); + if (null != createdData && !createdData.isEmpty()) { + for (DataObject data : createdData.values()) { + if (!(data instanceof Link)) { + log.warn("PFNodeListener accept an [{}] created event.", data); + break; + } + tmpOfLink = (Link)data; + log.debug("OF link created:{}",tmpOfLink.getKey()); + pnConverter.ofLinkAdded(tmpOfLink); + } + } + + Map, DataObject> updateData = change.getUpdatedData(); + if (null != updateData && !updateData.isEmpty()) { + for (DataObject data : updateData.values()) { + if (!(data instanceof Link)) { + log.warn("PFNodeListener accept an [{}] created event.", data); + break; + } + tmpOfLink = (Link)data; + log.debug("OF link updated:{}",tmpOfLink.getKey()); + pnConverter.ofLinkAdded(tmpOfLink); + } + } + + Map, DataObject> originalData = change.getOriginalData(); + Set> removedPaths = change.getRemovedPaths(); + + if ( null != removedPaths && !removedPaths.isEmpty() ) { + DataObject dataObject ; + for ( InstanceIdentifier instanceId : removedPaths ) { + dataObject = originalData.get(instanceId); + + if ( null != dataObject && dataObject instanceof Link) { + log.debug("OF link removed:{}",((Link)dataObject).getKey()); + pnConverter.ofLinkRemoved((Link) dataObject); + } + } + } + + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFNodeListener.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFNodeListener.java new file mode 100644 index 0000000..d6fde36 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFNodeListener.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.Set; + +/** + * Created by hj on 11/5/15. + */ +public class OFNodeListener implements DataChangeListener { + private static final Logger log = LoggerFactory.getLogger(OFNodeListener.class); + final private PhysicalNetworkAdapter pnConverter; + + protected OFNodeListener(PhysicalNetworkAdapter pnConverter) { + this.pnConverter = pnConverter; + } + + @Override + public void onDataChanged(AsyncDataChangeEvent, DataObject> change) { + if (null == change) { + return; + } + Node tmpOfNode = null; + + Map, DataObject> createdData = change.getCreatedData(); + if (null != createdData && !createdData.isEmpty()) { + for (DataObject data : createdData.values()) { + if (!(data instanceof Node)) { + log.warn("PFNodeListener accept an [{}] created event.", data); + break; + } + tmpOfNode = (Node)data; + log.debug("OF node added:{}",tmpOfNode.getKey()); + pnConverter.ofNodeAdded(tmpOfNode); + } + } + + Map, DataObject> updateData = change.getUpdatedData(); + if (null != updateData && !updateData.isEmpty()) { + for (DataObject data : updateData.values()) { + if (!(data instanceof Node)) { + log.warn("PFNodeListener accept an [{}] update event.", data); + break; + } + tmpOfNode = (Node)data; + log.debug("OF node updated:{}",tmpOfNode.getKey()); + pnConverter.ofNodeAdded(tmpOfNode); + } + } + + Map, DataObject> originalData = change.getOriginalData(); + Set> removedPaths = change.getRemovedPaths(); + + if ( null != removedPaths && !removedPaths.isEmpty() ) { + DataObject dataObject ; + for ( InstanceIdentifier instanceId : removedPaths ) { + dataObject = originalData.get(instanceId); + + if ( null != dataObject && dataObject instanceof Node) { + log.debug("OF node removed:{}",((Node)dataObject).getKey()); + pnConverter.ofNodeRemoved((Node)dataObject); + } + } + } + + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFPacketInListener.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFPacketInListener.java new file mode 100644 index 0000000..ac66e28 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/OFPacketInListener.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import org.opendaylight.controller.liblldp.EtherTypes; +import org.opendaylight.controller.liblldp.Ethernet; +import org.opendaylight.controller.liblldp.NetUtils; +import org.opendaylight.controller.liblldp.PacketException; +import org.opendaylight.nemo.renderer.openflow.FlowUtils; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by hj on 11/10/15. + */ +public class OFPacketInListener implements PacketProcessingListener { + private static final Logger log = LoggerFactory.getLogger(OFPacketInListener.class); + private FlowUtils ofFlowUtils; + public OFPacketInListener(FlowUtils ofFlowUtils) { + this.ofFlowUtils = ofFlowUtils; + } + + @Override + public void onPacketReceived(PacketReceived packetReceived) { + if (null == packetReceived) { + return; + } + byte[] payload = packetReceived.getPayload(); + Ethernet ethernet = new Ethernet(); + try { + ethernet.deserialize(payload, 0, NetUtils.NumBitsInAByte * payload.length); + } catch (PacketException e) { + log.warn("Failed to decode packet in message: {}", packetReceived); + } + if (EtherTypes.ARP.shortValue() == ethernet.getEtherType()) { + NodeConnectorRef ingressNodeConnectorRef = packetReceived.getIngress(); +// String strNodeId = ingressNodeConnectorRef +// .getValue() +// .firstIdentifierOf(Node.class) +// .firstKeyOf(Node.class) +// .getId() +// .getValue(); +// String strPortId = ingressNodeConnectorRef +// .getValue() +// .firstIdentifierOf(NodeConnector.class) +// .firstKeyOf(NodeConnector.class) +// .getId() +// .getValue(); + log.debug("Receive one arp packet in message:\r\n {}.", packetReceived); + ofFlowUtils.handleArp(packetReceived,ingressNodeConnectorRef); + } + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoader.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoader.java new file mode 100644 index 0000000..1f365fd --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhyConfigLoader.java @@ -0,0 +1 @@ +/* * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.nemo.renderer.openflow.physicalnetwork; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class PhyConfigLoader { private static final Logger log = LoggerFactory.getLogger(PhyConfigLoader.class); public final static String NODE_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-node-resource.json"; public final static String LINK_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-link-resource.json"; public final static String EXTERNAL_NETWORK_MAC_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-external-resource.json"; public final static String HOST_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-host-resource.json"; private final static String NODES = "node"; private final static String NODE_ID = "node-id"; private final static String NODE_TYPE = "node-type"; private final static String PORTS = "port"; private final static String PORT_ID = "port-id"; private final static String PORT_TYPE = "port-type"; private final static String PORT_IP = "port-ip-address"; private final static String PORT_MAC = "port-mac-address"; private final static String LINKS = "link"; private final static String LINK_ID = "link-id"; private final static String SRC_NODE_ID = "left-node-id"; private final static String SRC_PORT_ID = "left-port-id"; private final static String DST_NODE_ID = "right-node-id"; private final static String DST_PORT_ID = "right-port-id"; private final static String BANDWIDTH = "link-bandwidth"; private final static String METRIC = "metric"; private final static String HOSTS = "host"; private final static String HOST_NAME = "name"; private final static String HOST_ID = "id"; private final static String HOST_IPS = "ip-addresses"; private final static String CONNECTOR_ID = "connector-id"; private final static String EXTERNAL_NETWORK_MAC = "external-network-mac"; private final static String IP_ADDRESS = "ip-address"; private final static String MAC_ADDRESS = "mac-address"; private final static String ATTRIBUTES = "attribute"; private final static String ATTRIBUTE_NAME = "name"; private final static String ATTRIBUTE_VALUE = "value"; protected final static long DEFAULT_LINK_BANDWIDTH = 10240; protected final static long DEFAULT_LINK_DELAY = 1; protected final static short DEFAULT_LINK_LOSS_RATE = 1; private HashMap physicalNodeHashMap; private HashMap physicalPortHashMap; private HashMap physicalLinkHashMap; private Table externalNetworkMac; // final private DataBroker dataProvider; private ObjectMapper objectMapper = null; private DataBrokerAdapter dataBrokerAdapter = null; public PhyConfigLoader(DataBroker dataBroker) { physicalNodeHashMap = new HashMap(); physicalPortHashMap = new HashMap(); physicalLinkHashMap = new HashMap(); externalNetworkMac = HashBasedTable.create(); this.objectMapper = new ObjectMapper(); this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker); loadNodesPorts(); loadLinks(); loadHosts(); loadExternals(); } public Table getExternalNetworkMac() { return externalNetworkMac; } protected PhysicalNode getPhysicalNode(PhysicalNodeId physicalNodeId){ return physicalNodeHashMap.get(physicalNodeId); } protected PhysicalPort getPhysicalPort(PhysicalPortId physicalPortId){ return physicalPortHashMap.get(physicalPortId); } protected PhysicalLink getPhysicalLink(PhysicalLinkId physicalLinkId){ return physicalLinkHashMap.get(physicalLinkId); } private void loadNodesPorts() { String nodesStr = Utils.readFile(NODE_PROPERTY); try { JsonNode nodeRoot = objectMapper.readTree(nodesStr); List physicalNodes = buildNodes(nodeRoot); for (PhysicalNode physicalNode : physicalNodes) { physicalNodeHashMap.put(physicalNode.getNodeId(), physicalNode); for (PhysicalPort physicalPort : physicalNode.getPhysicalPort()) { physicalPortHashMap.put(physicalPort.getPortId(), physicalPort); } } } catch (IOException e) { e.printStackTrace(); } } private void loadLinks() { String linkStr = Utils.readFile(LINK_PROPERTY); try { JsonNode linkRoot = objectMapper.readTree(linkStr); List physicalLinks = buildLinks(linkRoot); for (PhysicalLink physicalLink : physicalLinks) { physicalLinkHashMap.put(physicalLink.getLinkId(), physicalLink); } } catch (IOException e) { e.printStackTrace(); } } private void loadExternals() { String externalStr = Utils.readFile(EXTERNAL_NETWORK_MAC_PROPERTY); try { JsonNode externalRoot = objectMapper.readTree(externalStr); buildExternals(externalRoot); } catch (IOException e) { e.printStackTrace(); } } private void loadHosts() { String hostStr = Utils.readFile(HOST_PROPERTY); try { JsonNode hostRoot = objectMapper.readTree(hostStr); List physicalHosts = buildHosts(hostRoot); for (PhysicalHost physicalHost : physicalHosts) { dataBrokerAdapter.addPhysicalHost(physicalHost); } } catch (IOException e) { e.printStackTrace(); } } private void buildExternals(JsonNode externalRoot) { JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC); log.debug("Build external network mac : {} .", exNetworkNodes); for (int i = 0; i < exNetworkNodes.size(); i++) { log.debug("Build external network execution body"); JsonNode exNetworkNode = exNetworkNodes.get(i); buildExNetwork(exNetworkNode); } } private void buildExNetwork(JsonNode exNetwork){ String nodeId = exNetwork.get(NODE_ID).asText(); String portId = exNetwork.get(PORT_ID).asText(); String peerMac = exNetwork.get(MAC_ADDRESS).asText(); PhysicalNodeId accessNodeId = new PhysicalNodeId(nodeId); PhysicalPortId accessPortId = new PhysicalPortId(portId); MacAddress macAddress = new MacAddress(peerMac); externalNetworkMac.put(accessNodeId,accessPortId,macAddress); } private List buildNodes(JsonNode nodesRoot) { List physicalNodes = new ArrayList(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; } private PhysicalNode buildNode(JsonNode node) { PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder(); String node_id = node.get(NODE_ID).asText(); if (node_id.equals("")) return null; nodeBuilder.setNodeId(new PhysicalNodeId(node_id)); PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId()); nodeBuilder.setKey(key); String strType = node.get(NODE_TYPE).asText(); PhysicalNodeInstance.NodeType nodeType = Utils.getNodeType(strType); nodeBuilder.setNodeType(nodeType); JsonNode ports = node.path(PORTS); List phyPortList = buildPorts(ports); nodeBuilder.setPhysicalPort(phyPortList); JsonNode attributes = node.path(ATTRIBUTES); nodeBuilder.setAttribute(buildNodeAttributes(attributes)); return nodeBuilder.build(); } private List buildPorts(JsonNode ports) { List phyPortList = new ArrayList(); for (int j = 0; j < ports.size(); j++) { //JsonNode port = portIt.next(); JsonNode port = ports.get(j); PhysicalPort physicalPort = buildPort(port); if (physicalPort != null) { phyPortList.add(physicalPort); } } return phyPortList; } private PhysicalPort buildPort(JsonNode port) { PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder(); String strPortId = port.get(PORT_ID).asText(); physicalPortBuilder.setPortId(new PhysicalPortId(strPortId)); String strType = port.get(PORT_TYPE).asText(); PhysicalPortInstance.PortType portType = Utils.getPortType(strType); physicalPortBuilder.setPortType(portType); // String strMac = port.get(PORT_MAC).asText(); // MacAddress macAddress = new MacAddress(strMac); // physicalPortBuilder.setMacAddress(macAddress); // // long bandWidth = port.get(BANDWIDTH).asLong(); // physicalPortBuilder.setBandwidth(bandWidth); JsonNode portAttributes = port.path(ATTRIBUTES); List attributes = buildPortAttributes(portAttributes); physicalPortBuilder.setAttribute(attributes); return physicalPortBuilder.build(); } private List buildPortAttributes(JsonNode attributes) { List attributeList = new ArrayList(); for (int i = 0; i < attributes.size(); i++) { log.debug("build physical port attribute execution body."); JsonNode portAttribute = attributes.get(i); Attribute attribute = buildPortAttribute(portAttribute); if (attribute != null) { attributeList.add(attribute); } } return attributeList; } private Attribute buildPortAttribute(JsonNode attribute) { AttributeBuilder attributeBuilder = new AttributeBuilder(); String strName = attribute.path(ATTRIBUTE_NAME).asText(); if (strName.equals("")) { return null; } attributeBuilder.setAttributeName(new AttributeName(strName)); AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder(); String strValue = attribute.path(ATTRIBUTE_VALUE).asText(); attributeValueBuilder.setStringValue(strValue); attributeBuilder.setKey(new AttributeKey(attributeBuilder.getAttributeName())); attributeBuilder.setAttributeValue(attributeValueBuilder.build()); return attributeBuilder.build(); } private List buildNodeAttributes(JsonNode attributes) { List attributeList = new ArrayList(); for (int i = 0; i < attributes.size(); i++) { log.debug("build physical port attribute execution body."); JsonNode portAttribute = attributes.get(i); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute attribute = buildNodeAttribute(portAttribute); if (attribute != null) { attributeList.add(attribute); } } return attributeList; } private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute buildNodeAttribute(JsonNode attribute) { org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attributeBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder(); String strName = attribute.path(ATTRIBUTE_NAME).asText(); if (strName.equals("")) { return null; } attributeBuilder.setAttributeName(new AttributeName(strName)); AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder(); String strValue = attribute.path(ATTRIBUTE_VALUE).asText(); attributeValueBuilder.setStringValue(strValue); attributeBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attributeBuilder.getAttributeName())); attributeBuilder.setAttributeValue(attributeValueBuilder.build()); return attributeBuilder.build(); } private List buildLinks(JsonNode linksRoot) { List physicalLinks = new ArrayList(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; } private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); } private List buildHosts(JsonNode hostsNode) { List physicalHosts = new ArrayList(); JsonNode hosts = hostsNode.path(HOSTS); log.debug("Build hosts: {} .", hosts); for (int i = 0; i < hosts.size(); i++) { JsonNode host = hosts.get(i); PhysicalHost physicalHost = buildHost(host); if (physicalHost != null) { physicalHosts.add(physicalHost); } } return physicalHosts; } private PhysicalHost buildHost(JsonNode hostNode) { PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder(); hostBuilder.setHostId(new PhysicalHostId(hostNode.get(HOST_ID).asText())); hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId())); hostBuilder.setHostName(new PhysicalHostName(hostNode.get(HOST_NAME).asText())); IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder(); List ipList = new ArrayList(); JsonNode ipaddrs = hostNode.path(HOST_IPS); for (int p = 0; p < ipaddrs.size(); p++) { JsonNode ipaddr = ipaddrs.get(p); IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get(IP_ADDRESS).asText())); ipList.add(ip); } IpAddrBuilder.setIpAddress(ipList); hostBuilder.setIpAddresses(IpAddrBuilder.build()); MacAddress mac = new MacAddress(hostNode.get(MAC_ADDRESS).asText()); hostBuilder.setMacAddress(mac); hostBuilder.setNodeId(new PhysicalNodeId(hostNode.get(NODE_ID).asText())); hostBuilder.setPortId(new PhysicalPortId(hostNode.get(CONNECTOR_ID).asText())); return hostBuilder.build(); } public void close() { physicalLinkHashMap.clear(); physicalPortHashMap.clear(); physicalNodeHashMap.clear(); externalNetworkMac.clear(); } } \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalFlowUtils.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalFlowUtils.java new file mode 100644 index 0000000..501de01 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalFlowUtils.java @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +public class PhysicalFlowUtils { + private static final Logger LOG = LoggerFactory.getLogger(PhysicalFlowUtils.class); + private static final short CONFIG_TABLE_ID = 0; + private static final int CONFIG_FLOW_PRIORITY = 0; + private static final int ETH_TYPE_ARP = 0x0806; + private static final int ETH_TYPE_LLDP = 0x88cc; + private final DataBroker dataBroker; + + public PhysicalFlowUtils(DataBroker dataBroker) { + this.dataBroker = dataBroker; + } + /** + * Config the lldp flow entry while find one of switch. + * @param strNodeId string id of the target node. + */ + public void configLLDPEntry(String strNodeId) { + + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + + EthernetType ethernetTypeLLDP = new EthernetTypeBuilder().setType(new EtherType((long) ETH_TYPE_LLDP)).build(); + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(ethernetTypeLLDP); + EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); + + Match match = new MatchBuilder().setEthernetMatch(ethernetMatch).build(); + + List instructionList = new LinkedList(); + List actionList = new LinkedList(); + Uri uri = controllerConnectorId(); + OutputAction outputAction = new OutputActionBuilder().setOutputNodeConnector(uri).build(); + OutputActionCase outputActionCase = new OutputActionCaseBuilder().setOutputAction(outputAction).build(); + Action actionOutput = new ActionBuilder().setOrder(actionList.size()).setAction(outputActionCase).build(); + actionList.add(actionOutput); + + ApplyActions applyActions = new ApplyActionsBuilder().setAction(actionList).build(); + ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build(); + Instruction instructionApply = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(applyActionsCase).build(); + instructionList.add(instructionApply); + + Instructions instructions = new InstructionsBuilder().setInstruction(instructionList).build(); + + FlowId flowId = new FlowId(UUID.randomUUID().toString()); + FlowBuilder flowBuilder = baseFlowBuilder().setId(flowId).setTableId(CONFIG_TABLE_ID).setPriority(CONFIG_FLOW_PRIORITY); + Flow flow = flowBuilder.setMatch(match).setInstructions(instructions).build(); + + NodeId nodeId = new NodeId(strNodeId); + InstanceIdentifier flowInsId = createFlowPath(nodeId, flow.getTableId(), flow.getId()); + + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInsId, flow, true); + writeTransaction.submit(); + + return; + } + /** + * Config the arp flow entry while find one of switch. + * @param strNodeId string id of the target node. + */ + public void configArpPEntry(String strNodeId) { + + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + + EthernetType ethernetTypeLLDP = new EthernetTypeBuilder().setType(new EtherType((long) ETH_TYPE_ARP)).build(); + EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder().setEthernetType(ethernetTypeLLDP); + EthernetMatch ethernetMatch = ethernetMatchBuilder.build(); + + Match match = new MatchBuilder().setEthernetMatch(ethernetMatch).build(); + + List instructionList = new LinkedList(); + List actionList = new LinkedList(); + Uri uri = controllerConnectorId(); + OutputAction outputAction = new OutputActionBuilder().setOutputNodeConnector(uri).build(); + OutputActionCase outputActionCase = new OutputActionCaseBuilder().setOutputAction(outputAction).build(); + Action actionOutput = new ActionBuilder().setOrder(actionList.size()).setAction(outputActionCase).build(); + actionList.add(actionOutput); + + ApplyActions applyActions = new ApplyActionsBuilder().setAction(actionList).build(); + ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build(); + Instruction instructionApply = new InstructionBuilder().setOrder(instructionList.size()).setInstruction(applyActionsCase).build(); + instructionList.add(instructionApply); + + Instructions instructions = new InstructionsBuilder().setInstruction(instructionList).build(); + + FlowId flowId = new FlowId(UUID.randomUUID().toString()); + FlowBuilder flowBuilder = baseFlowBuilder().setId(flowId).setTableId(CONFIG_TABLE_ID).setPriority(CONFIG_FLOW_PRIORITY); + Flow flow = flowBuilder.setMatch(match).setInstructions(instructions).build(); + + NodeId nodeId = new NodeId(strNodeId); + InstanceIdentifier flowInsId = createFlowPath(nodeId, flow.getTableId(), flow.getId()); + + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowInsId, flow, true); + writeTransaction.submit(); + + return; + } + private Uri controllerConnectorId(){ + return new Uri(OutputPortValues.CONTROLLER.toString()); + } + /** + * TODO + * + * @author Zhigang Ji + * @return TODO + */ + private FlowBuilder baseFlowBuilder() { + return new FlowBuilder().setBarrier(false).setHardTimeout(0).setIdleTimeout(0); + } + /** + * TODO + * + * @author Zhigang Ji + * @param nodeId TODO + * @param tableId TODO + * @param flowId TODO + * @return TODO + */ + private InstanceIdentifier createFlowPath(NodeId nodeId, Short tableId, FlowId flowId) { + return createTablePath(nodeId, tableId).child(Flow.class, new FlowKey(flowId)); + } + /** + * TODO + * + * @author Zhigang Ji + * @param nodeId TODO + * @param tableId TODO + * @return TODO + */ + private InstanceIdentifier createTablePath(NodeId nodeId, Short tableId) { + return createNodePath(nodeId).builder().augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).build(); + } + /** + * TODO + * + * @author Zhigang Ji + * @param nodeId TODO + * @return TODO + */ + private InstanceIdentifier createNodePath(NodeId nodeId) { + return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId)).build(); + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalNetworkAdapter.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalNetworkAdapter.java new file mode 100644 index 0000000..61c3c93 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/PhysicalNetworkAdapter.java @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.nemo.renderer.openflow.FlowUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalLinkId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalPortId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.CountDownLatch; + +public class PhysicalNetworkAdapter { + private static final Logger log = LoggerFactory.getLogger(PhysicalNetworkAdapter.class); + private static final String DEFAULT_TOPOLOGY_ID = "flow:1"; + + final private DataBroker dataBroker; + private PhyConfigLoader phyConfigLoader; + private DataBrokerAdapter dataBrokerAdapter; + private PhysicalFlowUtils physicalFlowUtils; + private FlowUtils ofFlowUtils; + private NotificationProviderService notificationProviderService; + + private CopyOnWriteArraySet nodeIdSet; + private CopyOnWriteArraySet physicalLinkSet; + private Timer phyTimer; + private boolean running = false; + private Integer mutex = 0; + private ListenerRegistration ofPacketInListenerReg; + private ListenerRegistration ofNodesListenerReg; + private ListenerRegistration ofLinksListenerReg; + + public PhysicalNetworkAdapter(DataBroker dataBroker + , NotificationProviderService notificationProviderService + , PhyConfigLoader phyConfigLoader + , FlowUtils ofFlowUtils) { + this.dataBroker = dataBroker; + this.notificationProviderService = notificationProviderService; + this.ofFlowUtils = ofFlowUtils; + this.phyConfigLoader = phyConfigLoader; + this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker); + physicalFlowUtils = new PhysicalFlowUtils(dataBroker); + nodeIdSet = new CopyOnWriteArraySet(); + physicalLinkSet = new CopyOnWriteArraySet(); + + phyTimer = new Timer(); + + + registerListeners(); + initOFNodes(); + initOFLinks(); + } + + public void close() { + if (ofPacketInListenerReg != null) + ofPacketInListenerReg.close(); + if (ofLinksListenerReg != null) + ofLinksListenerReg.close(); + if (ofNodesListenerReg != null) + ofNodesListenerReg.close(); + if (phyConfigLoader != null) + phyConfigLoader.close(); + log.debug("Clear....\r\n{}", nodeIdSet); + nodeIdSet.clear(); + physicalLinkSet.clear(); + } + + public PhyConfigLoader getPhyConfigLoader() { + return phyConfigLoader; + } + + /** + * OFNode instance identifier + * + * @return + */ + private InstanceIdentifier getOFNodeInstanceIdentifier() { + return InstanceIdentifier.builder(Nodes.class).child(Node.class).build(); + } + + private InstanceIdentifier getOFLinkInstanceIdentifier() { + return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId(DEFAULT_TOPOLOGY_ID))).child(Link.class).build(); + } + + private InstanceIdentifier getOFTopologyInstanceIdentifier() { + return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(new TopologyId(DEFAULT_TOPOLOGY_ID))).build(); + } + + private InstanceIdentifier getOFNodesInstanceIdentifier() { + return InstanceIdentifier.builder(Nodes.class).build(); + } + + private InstanceIdentifier getOFPortInstanceIdentifier(NodeKey nodeKey, NodeConnectorKey connectorKey) { + return InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey).child(NodeConnector.class, connectorKey).build(); + } + + private void registerListeners() { + InstanceIdentifier nodeInsId = getOFNodeInstanceIdentifier(); + InstanceIdentifier linkInsId = getOFLinkInstanceIdentifier(); + ofNodesListenerReg = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, nodeInsId, new OFNodeListener(this), DataChangeScope.BASE); + ofLinksListenerReg = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, linkInsId, new OFLinkListener(this), DataChangeScope.BASE); + ofPacketInListenerReg = notificationProviderService.registerNotificationListener(new OFPacketInListener(ofFlowUtils)); + } + + private void initOFLinks() { + InstanceIdentifier topologyInsId = getOFTopologyInstanceIdentifier(); + ListenableFuture> topologyFuture = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, topologyInsId); + Futures.addCallback(topologyFuture, new FutureCallback>() { + @Override + public void onSuccess(Optional result) { + if (result.isPresent() && result.get() instanceof Topology) { + Topology topology = result.get(); + if (topology != null && topology.getLink() != null) + for (Link link : topology.getLink()) { + ofLinkAdded(link); + } + } + + return; + } + + @Override + public void onFailure(Throwable t) { + log.error("Can not read the link info of topology {}: {}", DEFAULT_TOPOLOGY_ID, t); + return; + } + }); + } + + private void initOFNodes() { + InstanceIdentifier nodesInsId = getOFNodesInstanceIdentifier(); + ListenableFuture> nodesFuture = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, nodesInsId); + Futures.addCallback(nodesFuture, new FutureCallback>() { + @Override + public void onSuccess(Optional result) { + if (result.isPresent() && result.get() instanceof Nodes) { + Nodes nodes = result.get(); + if (nodes != null && nodes.getNode() != null) + for (Node node : nodes.getNode()) { + ofNodeAdded(node); + } + } + return; + } + + @Override + public void onFailure(Throwable t) { + log.error("Can not read node information: {}", t); + return; + } + }); + + } + + protected void ofNodeAdded(Node node) { + log.debug("OF node added: {}.", node.getKey()); + String strNodeId = node.getId().getValue(); + //add default flow entry. + physicalFlowUtils.configArpPEntry(strNodeId); + physicalFlowUtils.configLLDPEntry(strNodeId); + + PhysicalNodeId nodeId = new PhysicalNodeId(strNodeId); + PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder(); + nodeBuilder.setNodeId(nodeId); + nodeBuilder.setKey(new PhysicalNodeKey(nodeId)); + List physicalPortList = new ArrayList(); + List nodeConnectors = node.getNodeConnector(); + if (nodeConnectors != null) { + for (NodeConnector nodeConnector : nodeConnectors) { + PhysicalPort physicalPort = getPhysicalPort(node.getKey(), nodeConnector); + if (physicalPort != null) { + physicalPortList.add(physicalPort); + } + } + } + nodeBuilder.setPhysicalPort(physicalPortList); + + PhysicalNode confPhyNode = phyConfigLoader.getPhysicalNode(nodeId); + if (confPhyNode != null) { + nodeBuilder.setNodeType(confPhyNode.getNodeType()); + nodeBuilder.setAttribute(confPhyNode.getAttribute()); + } else { + log.warn("Find one OF Node {},does not have info in config file.", node.getKey()); + } + boolean result = dataBrokerAdapter.addPhysicalNode(nodeBuilder.build()); +// if (result) { + nodeIdSet.add(strNodeId); + log.debug("Add....{}\r\n{}", strNodeId, nodeIdSet); +// } + } + + protected void ofNodeRemoved(Node node) { + log.debug("OF node removed: {}.", node.getKey()); + String strNodeId = node.getId().getValue(); + PhysicalNodeId nodeId = new PhysicalNodeId(strNodeId); + PhysicalNode confPhyNode = phyConfigLoader.getPhysicalNode(nodeId); + if (confPhyNode == null) { + log.warn("Find one OF Node removed {},does not have info in config file.", node.getKey()); + } + boolean result = dataBrokerAdapter.removePhysicalNode(new PhysicalNodeKey(nodeId)); +// if (result) { + nodeIdSet.remove(strNodeId); + log.debug("Remove....{}\r\n{}", strNodeId, nodeIdSet); +// } + } + + private PhysicalPort getPhysicalPort(NodeKey nodeKey, NodeConnector nodeConnector) { + String strConnectorId = nodeConnector.getId().getValue(); + if (strConnectorId.contains("LOCAL")) + return null; + PhysicalPortId physicalPortId = new PhysicalPortId(strConnectorId); + log.debug("Get port {} : {}.", nodeKey, nodeConnector.getId().getValue()); + FlowCapableNodeConnector flowCapableNodeConnector = getOFPort(nodeKey, nodeConnector.getKey()); + if (flowCapableNodeConnector != null) { + PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder(); + physicalPortBuilder.setPortId(physicalPortId); + physicalPortBuilder.setKey(new PhysicalPortKey(physicalPortId)); + physicalPortBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); + MacAddress macAddress = flowCapableNodeConnector.getHardwareAddress(); + physicalPortBuilder.setMacAddress(macAddress); + + PhysicalPort confPhyPort = phyConfigLoader.getPhysicalPort(physicalPortId); + if (confPhyPort != null) { + log.debug("Set port {} : {}.\r\n {} \r\n{}", nodeKey, nodeConnector.getId().getValue(), confPhyPort.getPortType().toString(), confPhyPort.getAttribute()); +// long bandwidth = flowCapableNodeConnector.getMaximumSpeed() > 0 ? flowCapableNodeConnector.getMaximumSpeed() : confPhyPort.getBandwidth(); + physicalPortBuilder.setPortType(confPhyPort.getPortType()); + physicalPortBuilder.setAttribute(confPhyPort.getAttribute()); + } else { + log.warn("Can not get config info of {}-{} form data broker.", nodeKey.getId(), strConnectorId); + } + return physicalPortBuilder.build(); + } else { + log.warn("Can not read OF port info of {}-{} form .", nodeKey.getId(), strConnectorId); + } + return null; + } + + private FlowCapableNodeConnector getOFPort(final NodeKey nodeKey, final NodeConnectorKey nodeConnectorKey) { + final FlowCapableNodeConnector[] flowCapableNodeConnector = {null}; + + InstanceIdentifier nodeConnectorInsId = getOFPortInstanceIdentifier(nodeKey, nodeConnectorKey); + final CountDownLatch downLatch = new CountDownLatch(1); + ListenableFuture> nodeConnectorFuture = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, nodeConnectorInsId); + Futures.addCallback(nodeConnectorFuture, new FutureCallback>() { + @Override + public void onSuccess(Optional result) { + if (result.isPresent() && result.get() instanceof NodeConnector) { + flowCapableNodeConnector[0] = result.get().getAugmentation(FlowCapableNodeConnector.class); + downLatch.countDown(); + } + + return; + } + + @Override + public void onFailure(Throwable t) { + log.error("Can not read the information of node connector {}-{} : {}", nodeKey, nodeConnectorKey, t); + downLatch.countDown(); + return; + } + }); + + try { + downLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return flowCapableNodeConnector[0]; + } + + protected void ofLinkAdded(Link link) { + log.debug("OF link added:{}.", link.getKey()); + + String srcNode = link.getSource().getSourceNode().getValue(); + String srcTp = link.getSource().getSourceTp().getValue(); + String dstNode = link.getDestination().getDestNode().getValue(); + String dstTp = link.getDestination().getDestTp().getValue(); + + String strLinkId = link.getLinkId().getValue(); + PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); + linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); + linkBuilder.setSrcNodeId(new PhysicalNodeId(srcNode)); + linkBuilder.setSrcPortId(new PhysicalPortId(srcTp)); + linkBuilder.setDestNodeId(new PhysicalNodeId(dstNode)); + linkBuilder.setDestPortId(new PhysicalPortId(dstTp)); + + linkBuilder.setBandwidth(PhyConfigLoader.DEFAULT_LINK_BANDWIDTH); + linkBuilder.setDelay(PhyConfigLoader.DEFAULT_LINK_DELAY); + linkBuilder.setLossRate(PhyConfigLoader.DEFAULT_LINK_LOSS_RATE); + + PhysicalLinkId physicalLinkId = new PhysicalLinkId(strLinkId); + PhysicalLink physicalLink = phyConfigLoader.getPhysicalLink(physicalLinkId); + if (physicalLink != null) { + linkBuilder.setMetric(physicalLink.getMetric()); + } else { + log.warn("Can not find conf info of {}.", link.getKey()); + } + synchronized (mutex) { + physicalLinkSet.add(linkBuilder.build()); + if (!running) { + phyTimer.schedule(new PhyTransmit(), 10, 100); + running = true; + } + } + } + + protected void ofLinkRemoved(Link link) { + log.debug("OF link removed:{}.", link.getKey()); + String strLinkId = link.getLinkId().getValue(); + PhysicalLinkId linkId = new PhysicalLinkId(strLinkId); + PhysicalLink confPhyLink = phyConfigLoader.getPhysicalLink(linkId); + if (confPhyLink == null) { + log.warn("Can not find conf info of {} while remove.", link); + } + + dataBrokerAdapter.removePhysicalLink(new PhysicalLinkKey(linkId)); + } + + class PhyTransmit extends TimerTask { + + @Override + public void run() { + synchronized (mutex) { + for (PhysicalLink physicalLink : physicalLinkSet) { + handleLink(physicalLink); + } + if (physicalLinkSet.size() == 0) { + phyTimer.cancel(); + running = false; + } + } + } + + private void handleLink(PhysicalLink physicalLink) { + String srcNodeId = physicalLink.getSrcNodeId().getValue(); + String dsrNodeId = physicalLink.getDestNodeId().getValue(); + if (nodeIdSet.contains(srcNodeId) && nodeIdSet.contains(dsrNodeId)) { + physicalLinkSet.remove(physicalLink); + log.debug("Put [{}]-[{}] to data broker.", srcNodeId, dsrNodeId); + dataBrokerAdapter.addPhysicalLink(physicalLink); + } + } + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/Utils.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/Utils.java new file mode 100644 index 0000000..ea7760d --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/physicalnetwork/Utils.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.physicalnetwork; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Created by hj on 11/5/15. + */ +public class Utils { + + protected static PhysicalNodeInstance.NodeType getNodeType(String strType){ + switch (strType){ + case "switch": + return PhysicalNodeInstance.NodeType.Switch; + case "router": + return PhysicalNodeInstance.NodeType.Router; + case "firewall": + return PhysicalNodeInstance.NodeType.Firewall; + case "loadbalancer": + return PhysicalNodeInstance.NodeType.Loadbalancer; + } + return null; + } + protected static PhysicalPortInstance.PortType getPortType(String strType){ + switch (strType){ + case "external": + return PhysicalPortInstance.PortType.External; + } + return PhysicalPortInstance.PortType.Internal; + } + protected static String readFile(String Path){ + BufferedReader reader = null; + String laststr = ""; + try{ + FileInputStream fileInputStream = new FileInputStream(Path); + InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); + reader = new BufferedReader(inputStreamReader); + String tempString = null; + while((tempString = reader.readLine()) != null){ + laststr += tempString; + } + reader.close(); + }catch(IOException e){ + e.printStackTrace(); + }finally{ + if(reader != null){ + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return laststr; + } + +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/utils/ARP.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/utils/ARP.java new file mode 100644 index 0000000..3150d0c --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/nemo/renderer/openflow/utils/ARP.java @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.nemo.renderer.openflow.utils; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.opendaylight.controller.liblldp.BitBufferHelper; +import org.opendaylight.controller.liblldp.Packet; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Class that represents the ARP packet objects + */ +public class ARP extends Packet { + private static final String HWTYPE = "HardwareType"; + private static final String PTYPE = "ProtocolType"; + private static final String HWADDRLENGTH = "HardwareAddressLength"; + private static final String PADDRLENGTH = "ProtocolAddressLength"; + private static final String OPCODE = "OpCode"; + private static final String SENDERHWADDR = "SenderHardwareAddress"; + private static final String SENDERPADDR = "SenderProtocolAddress"; + private static final String TARGETHWADDR = "TargetHardwareAddress"; + private static final String TARGETPADDR = "TargetProtocolAddress"; + + public static short HW_TYPE_ETHERNET = (short) 0x1; + public static short REQUEST = (short) 0x1; + public static short REPLY = (short) 0x2; + + public static short PROTO_TYPE_IP = 0x800; + + private static Map> fieldCoordinates = new LinkedHashMap>() { + private static final long serialVersionUID = 1L; + { + put(HWTYPE, new ImmutablePair(0, 16)); + put(PTYPE, new ImmutablePair(16, 16)); + put(HWADDRLENGTH, new ImmutablePair(32, 8)); + put(PADDRLENGTH, new ImmutablePair(40, 8)); + put(OPCODE, new ImmutablePair(48, 16)); + put(SENDERHWADDR, new ImmutablePair(64, 48)); + put(SENDERPADDR, new ImmutablePair(112, 32)); + put(TARGETHWADDR, new ImmutablePair(144, 48)); + put(TARGETPADDR, new ImmutablePair(192, 32)); + + } + }; + private Map fieldValues; + + /** + * Default constructor that creates and sets the HashMap + */ + public ARP() { + super(); + fieldValues = new HashMap(); + hdrFieldCoordMap = fieldCoordinates; + hdrFieldsMap = fieldValues; + } + + /** + * Constructor that sets the access level for the packet and + * creates and sets the HashMap + */ + public ARP(boolean writeAccess) { + super(writeAccess); + fieldValues = new HashMap(); + hdrFieldCoordMap = fieldCoordinates; + hdrFieldsMap = fieldValues; + } + + /** + * Gets the hardware type from the stored ARP header + * @return short - the hardwareType + */ + public short getHardwareType() { + return (BitBufferHelper.getShort(fieldValues.get(HWTYPE))); + + } + + /** + * Gets the protocol type from the stored ARP header + * @return short - the protocolType + */ + public short getProtocolType() { + return (BitBufferHelper.getShort(fieldValues.get(PTYPE))); + } + + /** + * Gets the hardware address length from the stored ARP header + * @return byte - the protocolAddressLength + */ + public byte getHardwareAddressLength() { + return (BitBufferHelper.getByte(fieldValues.get(HWADDRLENGTH))); + } + + /** + * Get the protocol address length from Protocol header + * @return byte - the protocolAddressLength + */ + public byte getProtocolAddressLength() { + return (BitBufferHelper.getByte(fieldValues.get(PADDRLENGTH))); + } + + /** + * Gets the opCode from stored ARP header + * @return short - the opCode + */ + public short getOpCode() { + return (BitBufferHelper.getShort(fieldValues.get(OPCODE))); + } + + /** + * Gets the sender hardware address from the stored ARP header + * @return byte[] - the senderHardwareAddress + */ + public byte[] getSenderHardwareAddress() { + return (fieldValues.get(SENDERHWADDR)); + } + + /** + * Gets the IP address from the stored ARP header + * @return byte[] - the senderProtocolAddress + */ + public byte[] getSenderProtocolAddress() { + return (fieldValues.get(SENDERPADDR)); + } + + /** + * Gets the hardware address from the stored ARP header + * @return byte[] - the targetHardwareAddress + */ + public byte[] getTargetHardwareAddress() { + return (fieldValues.get(TARGETHWADDR)); + } + + /** + * Sets the hardware Type for the current ARP object instance + * @param hardwareType - the hardwareType to set + * @return ARP + */ + public ARP setHardwareType(short hardwareType) { + byte[] hwType = BitBufferHelper.toByteArray(hardwareType); + fieldValues.put(HWTYPE, hwType); + return this; + } + + /** + * Sets the protocol Type for the current ARP object instance + * @param protocolType - the protocolType to set + * @return ARP + */ + public ARP setProtocolType(short protocolType) { + byte[] protType = BitBufferHelper.toByteArray(protocolType); + fieldValues.put(PTYPE, protType); + return this; + } + + /** + * Sets the hardware address length for the current ARP object instance + * @param hardwareAddressLength - the hardwareAddressLength to set + * @return ARP + */ + public ARP setHardwareAddressLength(byte hardwareAddressLength) { + byte[] hwAddressLength = BitBufferHelper + .toByteArray(hardwareAddressLength); + fieldValues.put(HWADDRLENGTH, hwAddressLength); + return this; + } + + /** + * Sets the Protocol address for the current ARP object instance + * @param protocolAddressLength - the protocolAddressLength to set + * @return ARP + */ + public ARP setProtocolAddressLength(byte protocolAddressLength) { + byte[] protocolAddrLength = BitBufferHelper + .toByteArray(protocolAddressLength); + fieldValues.put(PADDRLENGTH, protocolAddrLength); + return this; + } + + /** + * Sets the opCode for the current ARP object instance + * @param opCode - the opCode to set + * @return ARP + */ + public ARP setOpCode(short opCode) { + byte[] operationCode = BitBufferHelper.toByteArray(opCode); + fieldValues.put(OPCODE, operationCode); + return this; + } + + /** + * Sets the sender hardware address for the current ARP object instance + * @param senderHardwareAddress - the senderHardwareAddress to set + * @return ARP + */ + public ARP setSenderHardwareAddress(byte[] senderHardwareAddress) { + fieldValues.put(SENDERHWADDR, senderHardwareAddress); + return this; + } + + /** + * Sets the target hardware address for the current ARP object instance + * @param targetHardwareAddress - the targetHardwareAddress to set + * @return ARP + */ + public ARP setTargetHardwareAddress(byte[] targetHardwareAddress) { + fieldValues.put(TARGETHWADDR, targetHardwareAddress); + return this; + } + + /** + * Sets the target protocol address for the current ARP object instance + * @param targetProtocolAddress - the targetProtocolAddress to set + * @return ARP + */ + public ARP setTargetProtocolAddress(byte[] targetProtocolAddress) { + fieldValues.put(TARGETPADDR, targetProtocolAddress); + return this; + } + + /** + * Sets the sender protocol address for the current ARP object instance + * @param senderIP - senderIP + * @return ARP + */ + public ARP setSenderProtocolAddress(byte[] senderIP) { + fieldValues.put(SENDERPADDR, senderIP); + return this; + } + + /** + * Gets the target protocol address + * @return - byte[] targetProtocolAddress + */ + public byte[] getTargetProtocolAddress() { + return fieldValues.get(TARGETPADDR); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + + ((fieldValues == null) ? 0 : fieldValues.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ARP other = (ARP) obj; + if (fieldValues == null) { + if (other.fieldValues != null) { + return false; + } + } else if (!fieldValues.equals(other.fieldValues)) { + return false; + } + return true; + } +} diff --git a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/nemo/openflow/renderer/impl/rev151010/OpenflowRendererModule.java b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/nemo/openflow/renderer/impl/rev151010/OpenflowRendererModule.java index 13a67ac..1fad7d8 100644 --- a/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/nemo/openflow/renderer/impl/rev151010/OpenflowRendererModule.java +++ b/nemo-renderers/openflow-renderer/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/nemo/openflow/renderer/impl/rev151010/OpenflowRendererModule.java @@ -9,10 +9,10 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.openflow.renderer.impl.rev151010; import org.opendaylight.nemo.renderer.openflow.OpenflowRenderer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class OpenflowRendererModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.openflow.renderer.impl.rev151010.AbstractOpenflowRendererModule { private static final Logger LOG = LoggerFactory.getLogger(OpenflowRenderer.class); @@ -32,8 +32,10 @@ public class OpenflowRendererModule extends org.opendaylight.yang.gen.v1.urn.ope @Override public java.lang.AutoCloseable createInstance() { - LOG.info("Openflow Renderer createInstance()"); - final OpenflowRenderer renderer = new OpenflowRenderer(getDataBrokerDependency()); + LOG.debug("Openflow Renderer createInstance()"); + final OpenflowRenderer renderer = new OpenflowRenderer( + getDataBrokerDependency(), getNotificationServiceDependency(), + getRpcRegistryDependency().getRpcService(PacketProcessingService.class)); final class CloseResources implements AutoCloseable { @Override @@ -41,9 +43,10 @@ public class OpenflowRendererModule extends org.opendaylight.yang.gen.v1.urn.ope if (renderer != null) { renderer.close(); } - LOG.info("Openflow Renderer (instance {}) tear down.", this); + LOG.debug("Openflow Renderer (instance {}) tear down.", this); } } + return new CloseResources(); } diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-bod.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-bod.json deleted file mode 100644 index 8af843a..0000000 --- a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-bod.json +++ /dev/null @@ -1,435 +0,0 @@ -{ - "physicalnetwork":{ - "node": [ - { - "node-id": "openflow:1", - "node-type": "switch", - "attribute":[ - { - "name":"location", - "value":"openflow:1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:1" - } - ] - }, - { - "port-id": "openflow:1:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:2" - } - ] - }, - { - "port-id": "openflow:1:3", - "port-type":"internal", - "port-ip-address":"", - "port-mac-address":"00:00:00:00:01:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:3" - } - ] - } - ] - }, - { - "node-id": "openflow:2", - "node-type": "switch", - "attribute":[ - { - "name":"location", - "value":"openflow:2" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:1" - } - ] - }, - { - "port-id": "openflow:2:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:bb:8b:cf", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:2" - } - ] - }, - { - "port-id": "openflow:2:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:3" - } - ] - } - ] - }, - { - "node-id": "openflow:3", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:3" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:3:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:1" - } - ] - }, - { - "port-id": "openflow:3:2", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:2" - } - ] - }, - { - "port-id": "openflow:3:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:3" - } - ] - }, - { - "port-id": "openflow:3:4", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:fb:d1:76", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:4" - } - ] - } - ] - }, - { - "node-id": "openflow:4", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:4" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:4:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:04:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:1" - } - ] - }, - { - "port-id": "openflow:4:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:0a:09:0b", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:2" - } - ] - } - ] - }, - { - "node-id": "external:internet-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:internet-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:40:9c:10", - "protocol":"static" - }, - { - "node-id": "external:enterprise-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:enterprise-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:0d:ef:79", - "protocol":"static" - } - ], - - - "link": [ - { - "link-id":"link_1", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_2", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_3", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:2", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_4", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:2", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_5", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:3", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_6", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:1", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_7", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:4", - "right-node-id":"external:internet-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_8", - "left-node-id":"external:internet-1", - "left-port-id":"", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:4", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_9", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:2", - "right-node-id":"external:enterprise-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_10", - "left-node-id":"external:enterprise-1", - "left-port-id":"", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - } - ], - - "host":[ - { - "name":"video-server1", - "id":"7b796915-adf4-4356-b5ca-de005ac410c1", - "ip-addresses":[ - {"ip-address":"192.168.11.2"} - ], - "mac-address":"00:00:00:00:00:03", - "node-id":"openflow:1", - "connector-id":"openflow:1:1" - }, - { - "name":"vm1", - "id":"1eaf9a67-a171-42a8-9282-71cf702f61dd", - "ip-addresses":[ - {"ip-address":"192.168.12.2"} - ], - "mac-address":"00:00:00:00:00:01", - "node-id":"openflow:1", - "connector-id":"openflow:1:2" - }, - { - "name":"vm2", - "id":"6c787caa-156a-49ed-8546-547bdccf283c", - "ip-addresses":[ - {"ip-address":"192.168.12.3"} - ], - "mac-address":"00:00:00:00:00:02", - "node-id":"openflow:2", - "connector-id":"openflow:2:1" - }, - { - "name":"video-server2", - "id":"22282cca-9a13-4d0c-a67e-a933ebb0b0ae", - "ip-addresses":[ - {"ip-address":"192.168.12.4"} - ], - "mac-address":"08:00:27:a0:a9:b3", - "node-id":"openflow:2", - "connector-id":"openflow:2:2" - } - ] - } - -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-servicechain.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-servicechain.json deleted file mode 100644 index d7ca7a8..0000000 --- a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource-servicechain.json +++ /dev/null @@ -1,612 +0,0 @@ -{ - "physicalnetwork":{ - "node": [ - { - "node-id": "openflow:1", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:1" - } - ] - }, - { - "port-id": "openflow:1:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:2" - } - ] - }, - { - "port-id": "openflow:1:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:3" - } - ] - } - ] - }, - { - "node-id": "openflow:2", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:2" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:1" - } - ] - }, - { - "port-id": "openflow:2:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:2" - } - ] - }, - { - "port-id": "openflow:2:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:3" - } - ] - } - ] - }, - { - "node-id": "openflow:3", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:3" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:3:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:1" - } - ] - }, - { - "port-id": "openflow:3:2", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:2" - } - ] - }, - { - "port-id": "openflow:3:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:3" - } - ] - }, - { - "port-id": "openflow:3:4", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:04", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:4" - } - ] - } - ] - }, - { - "node-id": "openflow:4", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:4" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:4:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:04:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:1" - } - ] - }, - { - "port-id": "openflow:4:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:04:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:2" - } - ] - } - ] - }, - { - "node-id": "external:branch-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:branch-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:6e:f2:07", - "protocol":"static" - }, - { - "node-id": "external:headquarters-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:headquarters-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:cb:43:ca", - "protocol":"static" - }, - { - "node-id": "external:fw1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:fw1" - }, - { - "name":"capacity", - "value":"1" - } - ], - "port": [ - { - "port-id": "fw1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:65:4c:f6", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"fw1:1" - } - ] - } - ], - "mac-address":"08:00:27:65:4c:f6", - "protocol":"static" - }, - { - "node-id": "external:fw2", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:fw2" - }, - { - "name":"capacity", - "value":"1" - } - ], - "port": [ - { - "port-id": "fw2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:00:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"fw2:1" - } - ] - } - ], - "mac-address":"00:00:00:00:00:01", - "protocol":"static" - }, - { - "node-id": "external:cache1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:cache1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "cache1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:00:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"cache1:1" - } - ] - } - ], - "mac-address":"00:00:00:00:00:02", - "protocol":"static" - }, - { - "node-id": "external:cache2", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:cache2" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "cache2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:90:0f:a5", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"cache2:1" - } - ] - } - ], - "mac-address":"08:00:27:90:0f:a5", - "protocol":"static" - } - ], - - "link": [ - { - "link-id":"link_1", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_2", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_3", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:2", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_4", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:2", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_5", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:3", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_6", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:1", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_7", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:4", - "right-node-id":"external:branch-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_8", - "left-node-id":"external:branch-1", - "left-port-id":"", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:4", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_9", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:2", - "right-node-id":"external:headquarters-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_10", - "left-node-id":"external:headquarters-1", - "left-port-id":"", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_11", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:1", - "right-node-id":"external:fw1", - "right-port-id":"fw1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_12", - "left-node-id":"external:fw1", - "left-port-id":"fw1:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_13", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:2", - "right-node-id":"external:fw2", - "right-port-id":"fw2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_14", - "left-node-id":"external:fw2", - "left-port-id":"fw2:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_15", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:1", - "right-node-id":"external:cache1", - "right-port-id":"cache1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_16", - "left-node-id":"external:cache1", - "left-port-id":"cache1:1", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_17", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:2", - "right-node-id":"external:cache2", - "right-port-id":"cache2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_18", - "left-node-id":"external:cache2", - "left-port-id":"cache2:1", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - } - ], - - "host":[] - } - -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource.json deleted file mode 100644 index d7ca7a8..0000000 --- a/nemo-renderers/openflow-renderer/src/main/resources/etc/nemo/resource.json +++ /dev/null @@ -1,612 +0,0 @@ -{ - "physicalnetwork":{ - "node": [ - { - "node-id": "openflow:1", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:1" - } - ] - }, - { - "port-id": "openflow:1:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:2" - } - ] - }, - { - "port-id": "openflow:1:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:01:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:1:3" - } - ] - } - ] - }, - { - "node-id": "openflow:2", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:2" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:1" - } - ] - }, - { - "port-id": "openflow:2:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:2" - } - ] - }, - { - "port-id": "openflow:2:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:02:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:2:3" - } - ] - } - ] - }, - { - "node-id": "openflow:3", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:3" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:3:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:1" - } - ] - }, - { - "port-id": "openflow:3:2", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:2" - } - ] - }, - { - "port-id": "openflow:3:3", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:03", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:3" - } - ] - }, - { - "port-id": "openflow:3:4", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:03:04", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:3:4" - } - ] - } - ] - }, - { - "node-id": "openflow:4", - "node-type": "router", - "attribute":[ - { - "name":"location", - "value":"openflow:4" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "openflow:4:1", - "port-type":"internal", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:04:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:1" - } - ] - }, - { - "port-id": "openflow:4:2", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:04:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"openflow:4:2" - } - ] - } - ] - }, - { - "node-id": "external:branch-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:branch-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:6e:f2:07", - "protocol":"static" - }, - { - "node-id": "external:headquarters-1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:headquarters-1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [], - "mac-address":"08:00:27:cb:43:ca", - "protocol":"static" - }, - { - "node-id": "external:fw1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:fw1" - }, - { - "name":"capacity", - "value":"1" - } - ], - "port": [ - { - "port-id": "fw1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:65:4c:f6", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"fw1:1" - } - ] - } - ], - "mac-address":"08:00:27:65:4c:f6", - "protocol":"static" - }, - { - "node-id": "external:fw2", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:fw2" - }, - { - "name":"capacity", - "value":"1" - } - ], - "port": [ - { - "port-id": "fw2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:00:01", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"fw2:1" - } - ] - } - ], - "mac-address":"00:00:00:00:00:01", - "protocol":"static" - }, - { - "node-id": "external:cache1", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:cache1" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "cache1:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"00:00:00:00:00:02", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"cache1:1" - } - ] - } - ], - "mac-address":"00:00:00:00:00:02", - "protocol":"static" - }, - { - "node-id": "external:cache2", - "node-type": "ext-router", - "attribute":[ - { - "name":"location", - "value":"external:cache2" - }, - { - "name":"capacity", - "value":"" - } - ], - "port": [ - { - "port-id": "cache2:1", - "port-type":"external", - "port-ip-address": "", - "port-mac-address":"08:00:27:90:0f:a5", - "mask": "", - "bandwidth":"", - "attribute":[ - { - "name":"location", - "value":"cache2:1" - } - ] - } - ], - "mac-address":"08:00:27:90:0f:a5", - "protocol":"static" - } - ], - - "link": [ - { - "link-id":"link_1", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_2", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_3", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:2", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_4", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:3", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:2", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_5", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:3", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:1", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_6", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:1", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:3", - "link-bandwidth":"10240", - "metric":"1", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_7", - "left-node-id":"openflow:3", - "left-port-id":"openflow:3:4", - "right-node-id":"external:branch-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_8", - "left-node-id":"external:branch-1", - "left-port-id":"", - "right-node-id":"openflow:3", - "right-port-id":"openflow:3:4", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_9", - "left-node-id":"openflow:4", - "left-port-id":"openflow:4:2", - "right-node-id":"external:headquarters-1", - "right-port-id":"", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_10", - "left-node-id":"external:headquarters-1", - "left-port-id":"", - "right-node-id":"openflow:4", - "right-port-id":"openflow:4:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_11", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:1", - "right-node-id":"external:fw1", - "right-port-id":"fw1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_12", - "left-node-id":"external:fw1", - "left-port-id":"fw1:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_13", - "left-node-id":"openflow:1", - "left-port-id":"openflow:1:2", - "right-node-id":"external:fw2", - "right-port-id":"fw2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_14", - "left-node-id":"external:fw2", - "left-port-id":"fw2:1", - "right-node-id":"openflow:1", - "right-port-id":"openflow:1:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_15", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:1", - "right-node-id":"external:cache1", - "right-port-id":"cache1:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_16", - "left-node-id":"external:cache1", - "left-port-id":"cache1:1", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - - { - "link-id":"link_17", - "left-node-id":"openflow:2", - "left-port-id":"openflow:2:2", - "right-node-id":"external:cache2", - "right-port-id":"cache2:1", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - }, - { - "link-id":"link_18", - "left-node-id":"external:cache2", - "left-port-id":"cache2:1", - "right-node-id":"openflow:2", - "right-port-id":"openflow:2:2", - "link-bandwidth":"10240", - "metric":"", - "delay":"", - "loss-rate":"" - } - ], - - "host":[] - } - -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-bod.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-bod.json new file mode 100644 index 0000000..1ded4ed --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-bod.json @@ -0,0 +1,14 @@ +{ + "external-network-mac": [ + { + "node-id":"openflow:3", + "port-id":"openflow:3:4", + "mac-address":"08:00:27:40:9c:10" + }, + { + "node-id":"openflow:4", + "port-id":"openflow:4:2", + "mac-address":"08:00:27:0d:ef:79" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-servicechain.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-servicechain.json new file mode 100644 index 0000000..15f6845 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource-servicechain.json @@ -0,0 +1,34 @@ +{ + "external-network-mac": [ + { + "node-id":"openflow:3", + "port-id":"openflow:3:4", + "mac-address":"08:00:27:6e:f2:07" + }, + { + "node-id":"openflow:4", + "port-id":"openflow:4:2", + "mac-address":"00:00:00:00:00:03" + }, + { + "node-id":"openflow:1", + "port-id":"openflow:1:1", + "mac-address":"08:00:27:65:4c:f6" + }, + { + "node-id":"openflow:1", + "port-id":"openflow:1:2", + "mac-address":"00:00:00:00:00:01" + }, + { + "node-id":"openflow:2", + "port-id":"openflow:2:1", + "mac-address":"00:00:00:00:00:02" + }, + { + "node-id":"openflow:2", + "port-id":"openflow:2:2", + "mac-address":"08:00:27:90:0f:a5" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource.json new file mode 100644 index 0000000..1ded4ed --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/external-resource.json @@ -0,0 +1,14 @@ +{ + "external-network-mac": [ + { + "node-id":"openflow:3", + "port-id":"openflow:3:4", + "mac-address":"08:00:27:40:9c:10" + }, + { + "node-id":"openflow:4", + "port-id":"openflow:4:2", + "mac-address":"08:00:27:0d:ef:79" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-bod.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-bod.json new file mode 100644 index 0000000..9a4c407 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-bod.json @@ -0,0 +1,44 @@ +{ + "host":[ + { + "name":"video-server1", + "id":"7b796915-adf4-4356-b5ca-de005ac410c1", + "ip-addresses":[ + {"ip-address":"192.168.11.2"} + ], + "mac-address":"00:00:00:00:00:03", + "node-id":"openflow:1", + "connector-id":"openflow:1:1" + }, + { + "name":"vm1", + "id":"1eaf9a67-a171-42a8-9282-71cf702f61dd", + "ip-addresses":[ + {"ip-address":"192.168.12.2"} + ], + "mac-address":"00:00:00:00:00:01", + "node-id":"openflow:1", + "connector-id":"openflow:1:2" + }, + { + "name":"vm2", + "id":"6c787caa-156a-49ed-8546-547bdccf283c", + "ip-addresses":[ + {"ip-address":"192.168.12.3"} + ], + "mac-address":"00:00:00:00:00:02", + "node-id":"openflow:2", + "connector-id":"openflow:2:1" + }, + { + "name":"video-server2", + "id":"22282cca-9a13-4d0c-a67e-a933ebb0b0ae", + "ip-addresses":[ + {"ip-address":"192.168.12.4"} + ], + "mac-address":"08:00:27:a0:a9:b3", + "node-id":"openflow:2", + "connector-id":"openflow:2:2" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-servicechain.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-servicechain.json new file mode 100644 index 0000000..5e3a9a9 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource-servicechain.json @@ -0,0 +1,5 @@ +{ + "host":[ + + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource.json new file mode 100644 index 0000000..9a4c407 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/host-resource.json @@ -0,0 +1,44 @@ +{ + "host":[ + { + "name":"video-server1", + "id":"7b796915-adf4-4356-b5ca-de005ac410c1", + "ip-addresses":[ + {"ip-address":"192.168.11.2"} + ], + "mac-address":"00:00:00:00:00:03", + "node-id":"openflow:1", + "connector-id":"openflow:1:1" + }, + { + "name":"vm1", + "id":"1eaf9a67-a171-42a8-9282-71cf702f61dd", + "ip-addresses":[ + {"ip-address":"192.168.12.2"} + ], + "mac-address":"00:00:00:00:00:01", + "node-id":"openflow:1", + "connector-id":"openflow:1:2" + }, + { + "name":"vm2", + "id":"6c787caa-156a-49ed-8546-547bdccf283c", + "ip-addresses":[ + {"ip-address":"192.168.12.3"} + ], + "mac-address":"00:00:00:00:00:02", + "node-id":"openflow:2", + "connector-id":"openflow:2:1" + }, + { + "name":"video-server2", + "id":"22282cca-9a13-4d0c-a67e-a933ebb0b0ae", + "ip-addresses":[ + {"ip-address":"192.168.12.4"} + ], + "mac-address":"08:00:27:a0:a9:b3", + "node-id":"openflow:2", + "connector-id":"openflow:2:2" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-bod.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-bod.json new file mode 100644 index 0000000..ac508b4 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-bod.json @@ -0,0 +1,42 @@ +{ + "link": [ + { + "link-id":"openflow:1:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:3:1", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:2", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:2:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:4:1", + "metric":"1", + "delay":"", + "loss-rate":"" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-servicechain.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-servicechain.json new file mode 100644 index 0000000..ac508b4 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource-servicechain.json @@ -0,0 +1,42 @@ +{ + "link": [ + { + "link-id":"openflow:1:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:3:1", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:2", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:2:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:4:1", + "metric":"1", + "delay":"", + "loss-rate":"" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource.json new file mode 100644 index 0000000..ac508b4 --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/link-resource.json @@ -0,0 +1,42 @@ +{ + "link": [ + { + "link-id":"openflow:1:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:3:1", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:2", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:2:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + + { + "link-id":"openflow:3:3", + "metric":"1", + "delay":"", + "loss-rate":"" + }, + { + "link-id":"openflow:4:1", + "metric":"1", + "delay":"", + "loss-rate":"" + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-bod.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-bod.json new file mode 100644 index 0000000..420940e --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-bod.json @@ -0,0 +1,172 @@ +{ + "node": [ + { + "node-id": "openflow:1", + "node-type": "switch", + "attribute": [ + { + "name": "location", + "value": "openflow:1" + } + ], + "port": [ + { + "port-id": "openflow:1:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:1" + } + ] + }, + { + "port-id": "openflow:1:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:2" + } + ] + }, + { + "port-id": "openflow:1:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:1:3" + } + ] + } + ] + }, + { + "node-id": "openflow:2", + "node-type": "switch", + "attribute": [ + { + "name": "location", + "value": "openflow:2" + } + ], + "port": [ + { + "port-id": "openflow:2:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:1" + } + ] + }, + { + "port-id": "openflow:2:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:2" + } + ] + }, + { + "port-id": "openflow:2:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:2:3" + } + ] + } + ] + }, + { + "node-id": "openflow:3", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:3" + } + ], + "port": [ + { + "port-id": "openflow:3:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:1" + } + ] + }, + { + "port-id": "openflow:3:2", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:2" + } + ] + }, + { + "port-id": "openflow:3:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:3" + } + ] + }, + { + "port-id": "openflow:3:4", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:3:4" + } + ] + } + ] + }, + { + "node-id": "openflow:4", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:4" + } + ], + "port": [ + { + "port-id": "openflow:4:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:4:1" + } + ] + }, + { + "port-id": "openflow:4:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:4:2" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-servicechain.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-servicechain.json new file mode 100644 index 0000000..b883baf --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource-servicechain.json @@ -0,0 +1,172 @@ +{ + "node": [ + { + "node-id": "openflow:1", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:1" + } + ], + "port": [ + { + "port-id": "openflow:1:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:1" + } + ] + }, + { + "port-id": "openflow:1:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:2" + } + ] + }, + { + "port-id": "openflow:1:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:1:3" + } + ] + } + ] + }, + { + "node-id": "openflow:2", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:2" + } + ], + "port": [ + { + "port-id": "openflow:2:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:1" + } + ] + }, + { + "port-id": "openflow:2:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:2" + } + ] + }, + { + "port-id": "openflow:2:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:2:3" + } + ] + } + ] + }, + { + "node-id": "openflow:3", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:3" + } + ], + "port": [ + { + "port-id": "openflow:3:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:1" + } + ] + }, + { + "port-id": "openflow:3:2", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:2" + } + ] + }, + { + "port-id": "openflow:3:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:3" + } + ] + }, + { + "port-id": "openflow:3:4", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:3:4" + } + ] + } + ] + }, + { + "node-id": "openflow:4", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:4" + } + ], + "port": [ + { + "port-id": "openflow:4:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:4:1" + } + ] + }, + { + "port-id": "openflow:4:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:4:2" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource.json b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource.json new file mode 100644 index 0000000..420940e --- /dev/null +++ b/nemo-renderers/openflow-renderer/src/main/resources/etc/opendaylight/karaf/node-resource.json @@ -0,0 +1,172 @@ +{ + "node": [ + { + "node-id": "openflow:1", + "node-type": "switch", + "attribute": [ + { + "name": "location", + "value": "openflow:1" + } + ], + "port": [ + { + "port-id": "openflow:1:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:1" + } + ] + }, + { + "port-id": "openflow:1:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:1:2" + } + ] + }, + { + "port-id": "openflow:1:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:1:3" + } + ] + } + ] + }, + { + "node-id": "openflow:2", + "node-type": "switch", + "attribute": [ + { + "name": "location", + "value": "openflow:2" + } + ], + "port": [ + { + "port-id": "openflow:2:1", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:1" + } + ] + }, + { + "port-id": "openflow:2:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:2:2" + } + ] + }, + { + "port-id": "openflow:2:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:2:3" + } + ] + } + ] + }, + { + "node-id": "openflow:3", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:3" + } + ], + "port": [ + { + "port-id": "openflow:3:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:1" + } + ] + }, + { + "port-id": "openflow:3:2", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:2" + } + ] + }, + { + "port-id": "openflow:3:3", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:3:3" + } + ] + }, + { + "port-id": "openflow:3:4", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:3:4" + } + ] + } + ] + }, + { + "node-id": "openflow:4", + "node-type": "router", + "attribute": [ + { + "name": "location", + "value": "openflow:4" + } + ], + "port": [ + { + "port-id": "openflow:4:1", + "port-type": "internal", + "attribute": [ + { + "name": "location", + "value": "openflow:4:1" + } + ] + }, + { + "port-id": "openflow:4:2", + "port-type": "external", + "attribute": [ + { + "name": "location", + "value": "openflow:4:2" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java deleted file mode 100644 index 5f15e47..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowTableManagerTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.opendaylight.nemo.renderer.openflow.FlowTableManager; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.nemo.renderer.openflow.ResourceManager; -import org.opendaylight.nemo.renderer.openflow.entity.ResourceBean; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -/** - * Created by zhangmeng on 2015/11/11. - */ -public class FlowTableManagerTest extends TestCase { - private FlowTableManager flowTableManager; - private ResourceManager resourceManager; - private DataBroker dataProvider; - @Before - public void setUp() throws Exception { - resourceManager = mock(ResourceManager.class); - dataProvider = mock(DataBroker.class); - - flowTableManager = new FlowTableManager(dataProvider,resourceManager); - } - - @Test - public void testClose() throws Exception { - flowTableManager.close(); - Assert.assertNotNull(flowTableManager); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowUtilsTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowUtilsTest.java deleted file mode 100644 index 86e3168..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/FlowUtilsTest.java +++ /dev/null @@ -1,177 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow; - -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.nemo.renderer.openflow.FlowUtils; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalPaths; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPath; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPathBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArpKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.nodes.VirtualNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.paths.VirtualPath; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.VirtualPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.IntentVnMappingResult; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.intent.vn.mapping.result.VirtualResource; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.user.vn.pn.mapping.VnPnMappingResult; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.IntentId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.MatchItemName; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.MatchItem; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -/** - * Created by zhangmeng on 2015/11/11. - */ -public class FlowUtilsTest extends TestCase { - private FlowUtils flowUtils; - @Before - public void setUp() throws Exception { - flowUtils = mock(FlowUtils.class); - - } - - @Test - public void testInit() throws Exception { - List physicalNodes = new ArrayList(); - - flowUtils.init(physicalNodes); - verify(flowUtils).init(any(List.class)); - Assert.assertNotNull(flowUtils); - } - - @Test - public void testUpdateFlowTable() throws Exception { - User user = mock(User.class); - VirtualNetwork virtualNetwork = mock(VirtualNetwork.class); - UserIntentVnMapping userIntentVnMapping = mock(UserIntentVnMapping.class); - UserVnPnMapping userVnPnMapping = mock(UserVnPnMapping.class); - PhysicalNetwork physicalNetwor = mock(PhysicalNetwork.class); - - flowUtils.updateFlowTable(user,virtualNetwork,userIntentVnMapping,userVnPnMapping,physicalNetwor); - verify(flowUtils).updateFlowTable( - any(User.class), - any(VirtualNetwork.class), - any(UserIntentVnMapping.class), - any(UserVnPnMapping.class), - any(PhysicalNetwork.class)); - Assert.assertNotNull(flowUtils); - } - - @Test - public void testDeleteFlowEntries() throws Exception { - UserId userId = mock(UserId.class); - - flowUtils.deleteFlowEntries(userId); - verify(flowUtils).deleteFlowEntries(any(UserId.class)); - Assert.assertNotNull(flowUtils); - } - - @Test - public void testClose() throws Exception { - flowUtils.close(); - verify(flowUtils).close(); - Assert.assertNotNull(flowUtils); - } - - @Test - public void testAssignMPLSLabelForPPath() throws Exception { - PhysicalPath physicalPath = mock(PhysicalPath.class); - List physicalLinksList - = new ArrayList(); - - flowUtils.assignMPLSLabelForPPath(physicalPath, physicalLinksList); - verify(flowUtils).assignMPLSLabelForPPath( - any(PhysicalPath.class), - any(List.class)); - Assert.assertNotNull(flowUtils); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/OpenflowRendererTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/OpenflowRendererTest.java deleted file mode 100644 index 4293818..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/OpenflowRendererTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import static org.junit.Assert.*; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.nemo.renderer.openflow.FlowTableManager; -import org.opendaylight.nemo.renderer.openflow.OpenflowRenderer; -import org.opendaylight.nemo.renderer.openflow.ResourceManager; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import static org.mockito.Mockito.*; -/** - * Created by zhangmeng on 2015/11/11. - */ -public class OpenflowRendererTest extends TestCase { - private OpenflowRenderer openflowRenderer; - private DataBroker dataBroker; - private ResourceManager resourceManager; - private FlowTableManager flowTableMng; - @Before - public void setUp() throws Exception { - dataBroker = mock(DataBroker.class); - openflowRenderer = new OpenflowRenderer(dataBroker); - } - - @Test - public void testClose() throws Exception { - openflowRenderer.close(); - Assert.assertNotNull(openflowRenderer); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/ResourceManagerTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/ResourceManagerTest.java deleted file mode 100644 index d1b2d7c..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/ResourceManagerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.nemo.renderer.openflow.ResourceManager; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetworkBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValue; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.AttributeName; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalPortId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalLinkId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostName; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddresses; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalHosts; -/** - * Created by zhangmeng on 2015/11/11. - */ -public class ResourceManagerTest extends TestCase { - private ResourceManager resourceManager; - private Table externalNetworkMacTable; - @Before - public void setUp() throws Exception { - resourceManager = mock(ResourceManager.class); - externalNetworkMacTable = HashBasedTable.create(); - } - - @Test - public void testGetExternalNetworkMacTable() throws Exception { - resourceManager.getExternalNetworkMacTable(); - when(resourceManager.getExternalNetworkMacTable()).thenReturn(externalNetworkMacTable); - Assert.assertEquals(HashBasedTable.create(),resourceManager.getExternalNetworkMacTable()); - } - - @Test - public void testClose() throws Exception { - resourceManager.close(); - verify(resourceManager).close(); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/HostBeanTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/HostBeanTest.java deleted file mode 100644 index 3a2422f..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/HostBeanTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow.entity; - -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.nemo.renderer.openflow.entity.HostBean; -import java.util.LinkedList; -import static org.mockito.Mockito.*; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * Created by zhangmeng on 2015/11/8. - */ -public class HostBeanTest extends TestCase { - - private HostBean hostBean; - private String hostName; - private List IPAddressList; - private String macAddress; - private String nodeID; - private String connectorID; - @Before - public void setUp() throws Exception { - hostBean = new HostBean(); - hostName = null; - IPAddressList = new LinkedList(); - macAddress = null; - nodeID = null; - connectorID = null; - } - - @Test - public void testGetHostName() throws Exception { - Assert.assertNull(hostBean.getHostName()); - hostName = "test"; - hostBean.setHostName(hostName); - Assert.assertEquals("test",hostBean.getHostName()); - hostName = null; - } - - @Test - public void testSetHostName() throws Exception { - Assert.assertNull(hostBean.getHostName()); - hostName = "test"; - hostBean.setHostName(hostName); - Assert.assertEquals("test",hostBean.getHostName()); - } - - @Test - public void testGetIPAddressList() throws Exception { - Assert.assertNull(hostBean.getIPAddressList()); - IPAddressList.add("test"); - hostBean.setStringList(IPAddressList); - Assert.assertNotNull(hostBean.getIPAddressList()); - IPAddressList.clear(); - } - - @Test - public void testSetStringList() throws Exception { - Assert.assertNull(hostBean.getIPAddressList()); - IPAddressList.add("test"); - hostBean.setStringList(IPAddressList); - Assert.assertNotNull(hostBean.getIPAddressList()); - } - - @Test - public void testGetMacAddress() throws Exception { - Assert.assertNull(hostBean.getMacAddress()); - macAddress = "test"; - hostBean.setMacAddress(macAddress); - Assert.assertEquals("test",hostBean.getMacAddress()); - macAddress = null; - } - - @Test - public void testSetMacAddress() throws Exception { - Assert.assertNull(hostBean.getMacAddress()); - macAddress = "test"; - hostBean.setMacAddress(macAddress); - Assert.assertEquals("test",hostBean.getMacAddress()); - } - - @Test - public void testGetNodeID() throws Exception { - Assert.assertNull(hostBean.getNodeID()); - nodeID = "test"; - hostBean.setNodeID(nodeID); - Assert.assertEquals("test",hostBean.getNodeID()); - nodeID = null; - } - - @Test - public void testSetNodeID() throws Exception { - Assert.assertNull(hostBean.getNodeID()); - nodeID = "test"; - hostBean.setNodeID(nodeID); - Assert.assertEquals("test",hostBean.getNodeID()); - } - - @Test - public void testGetConnectorID() throws Exception { - Assert.assertNull(hostBean.getConnectorID()); - connectorID = "test"; - hostBean.setConnectorID(connectorID); - Assert.assertEquals("test",hostBean.getConnectorID()); - connectorID = null; - } - - @Test - public void testSetConnectorID() throws Exception { - Assert.assertNull(hostBean.getConnectorID()); - connectorID = "test"; - hostBean.setConnectorID(connectorID); - Assert.assertEquals("test",hostBean.getConnectorID()); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBeanTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBeanTest.java deleted file mode 100644 index 29cf918..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/LinkBeanTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow.entity; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.*; -import java.util.LinkedList; -import org.opendaylight.nemo.renderer.openflow.entity.LinkBean; -import static org.mockito.Mockito.*; - -import static org.junit.Assert.*; - -/** - * Created by zhangmeng on 2015/11/8. - */ -public class LinkBeanTest extends TestCase { - private LinkBean linkBean; - - private String linkID; - private String leftNodeID; - private String leftPortID; - private String rightPortID; - private String rightNodeID; - private String linkBandwidth; - - @Before - public void setUp() throws Exception { - linkBean = new LinkBean(); - linkID = leftNodeID = leftPortID = rightPortID = rightNodeID = linkBandwidth = null; - } - - @Test - public void testGetLinkID() throws Exception { - Assert.assertNull(linkBean.getLinkID()); - linkID = "test"; - linkBean.setLinkID(linkID); - Assert.assertEquals(linkID,linkBean.getLinkID()); - linkID = null; - } - - @Test - public void testSetLinkID() throws Exception { - Assert.assertNull(linkBean.getLinkID()); - linkID = "test"; - linkBean.setLinkID(linkID); - Assert.assertEquals(linkID,linkBean.getLinkID()); - } - - @Test - public void testGetLeftNodeID() throws Exception { - Assert.assertNull(linkBean.getLeftNodeID()); - leftNodeID = "test"; - linkBean.setLeftNodeID(leftNodeID); - Assert.assertEquals(leftNodeID,linkBean.getLeftNodeID()); - leftNodeID = null; - } - - @Test - public void testSetLeftNodeID() throws Exception { - Assert.assertNull(linkBean.getLeftNodeID()); - leftNodeID = "test"; - linkBean.setLeftNodeID(leftNodeID); - Assert.assertEquals(leftNodeID,linkBean.getLeftNodeID()); - } - - @Test - public void testGetLeftPortID() throws Exception { - Assert.assertNull(linkBean.getLeftPortID()); - leftPortID = "test"; - linkBean.setLeftPortID(leftPortID); - Assert.assertEquals(leftPortID,linkBean.getLeftPortID()); - leftPortID = null; - } - - @Test - public void testSetLeftPortID() throws Exception { - Assert.assertNull(linkBean.getLeftPortID()); - leftPortID = "test"; - linkBean.setLeftPortID(leftPortID); - Assert.assertEquals(leftPortID,linkBean.getLeftPortID()); - } - - @Test - public void testGetRightNodeID() throws Exception { - Assert.assertNull(linkBean.getRightNodeID()); - rightNodeID = "test"; - linkBean.setRightNodeID(rightNodeID); - Assert.assertEquals(rightNodeID,linkBean.getRightNodeID()); - rightNodeID = null; - } - - @Test - public void testSetRightNodeID() throws Exception { - Assert.assertNull(linkBean.getRightNodeID()); - rightNodeID = "test"; - linkBean.setRightNodeID(rightNodeID); - Assert.assertEquals(rightNodeID,linkBean.getRightNodeID()); - } - - @Test - public void testGetRightPortID() throws Exception { - Assert.assertNull(linkBean.getRightPortID()); - rightPortID = "test"; - linkBean.setRightPortID(rightPortID); - Assert.assertEquals(rightPortID,linkBean.getRightPortID()); - rightPortID = null; - } - - @Test - public void testSetRightPortID() throws Exception { - Assert.assertNull(linkBean.getRightPortID()); - rightPortID = "test"; - linkBean.setRightPortID(rightPortID); - Assert.assertEquals(rightPortID,linkBean.getRightPortID()); - } - - @Test - public void testGetLinkBandwidth() throws Exception { - Assert.assertNull(linkBean.getLinkBandwidth()); - linkBandwidth = "test"; - linkBean.setLinkBandwidth(linkBandwidth); - Assert.assertEquals(linkBandwidth,linkBean.getLinkBandwidth()); - linkBandwidth = null; - } - - @Test - public void testSetLinkBandwidth() throws Exception { - Assert.assertNull(linkBean.getLinkBandwidth()); - linkBandwidth = "test"; - linkBean.setLinkBandwidth(linkBandwidth); - Assert.assertEquals(linkBandwidth,linkBean.getLinkBandwidth()); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBeanTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBeanTest.java deleted file mode 100644 index 38a39db..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/NodeBeanTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow.entity; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.nemo.renderer.openflow.entity.NodeBean; -import org.opendaylight.nemo.renderer.openflow.entity.PortBean; -import org.junit.*; -import java.util.LinkedList; -import java.util.List; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -/** - * Created by zhangmeng on 2015/11/8. - */ -public class NodeBeanTest extends TestCase { - - private NodeBean nodeBean; - private String nodeID; - private String nodeType; - private String nodeCapacity; - private List portList; - @Before - public void setUp() throws Exception { - nodeBean = new NodeBean(); - nodeID = nodeType = nodeCapacity = null; - portList = new LinkedList(); - } - - @Test - public void testGetNodeID() throws Exception { - Assert.assertNull(nodeBean.getNodeID()); - nodeID = "test"; - nodeBean.setNodeID(nodeID); - Assert.assertEquals(nodeID,nodeBean.getNodeID()); - nodeID = null; - } - - @Test - public void testSetNodeID() throws Exception { - Assert.assertNull(nodeBean.getNodeID()); - nodeID = "test"; - nodeBean.setNodeID(nodeID); - Assert.assertEquals(nodeID,nodeBean.getNodeID()); - } - - @Test - public void testGetNodeType() throws Exception { - Assert.assertNull(nodeBean.getNodeType()); - nodeType = "test"; - nodeBean.setNodeType(nodeType); - Assert.assertEquals(nodeType,nodeBean.getNodeType()); - nodeType = null; - } - - @Test - public void testSetNodeType() throws Exception { - Assert.assertNull(nodeBean.getNodeType()); - nodeType = "test"; - nodeBean.setNodeType(nodeType); - Assert.assertEquals(nodeType,nodeBean.getNodeType()); - } - - @Test - public void testGetNodeCapacity() throws Exception { - Assert.assertNull(nodeBean.getNodeCapacity()); - nodeCapacity = "test"; - nodeBean.setNodeCapacity(nodeCapacity); - Assert.assertEquals(nodeCapacity,nodeBean.getNodeCapacity()); - nodeCapacity = null; - } - - @Test - public void testSetNodeCapacity() throws Exception { - Assert.assertNull(nodeBean.getNodeCapacity()); - nodeCapacity = "test"; - nodeBean.setNodeCapacity(nodeCapacity); - Assert.assertEquals(nodeCapacity,nodeBean.getNodeCapacity()); - } - - @Test - public void testGetPortList() throws Exception { - Assert.assertNull(nodeBean.getPortList()); - portList.add(new PortBean()); - nodeBean.setPortList(portList); - Assert.assertNotNull(nodeBean.getPortList()); - portList.clear(); - } - - @Test - public void testSetPortList() throws Exception { - Assert.assertNull(nodeBean.getPortList()); - portList.add(new PortBean()); - nodeBean.setPortList(portList); - Assert.assertNotNull(nodeBean.getPortList()); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/PortBeanTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/PortBeanTest.java deleted file mode 100644 index 63167fc..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/PortBeanTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow.entity; - -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.*; -import org.opendaylight.nemo.renderer.openflow.entity.PortBean; -import java.util.LinkedList; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -/** - * Created by zhangmeng on 2015/11/8. - */ -public class PortBeanTest extends TestCase { - private PortBean portBean; - private String portID; - private String portIPAddress; - private String mask; - private String location; - private String bandwidth; - @Before - public void setUp() throws Exception { - portBean = new PortBean(); - portID = portIPAddress = mask = location = bandwidth = null; - } - - @Test - public void testGetPortID() throws Exception { - Assert.assertNull(portBean.getPortID()); - portID = "test"; - portBean.setPortID(portID); - Assert.assertEquals(portID,portBean.getPortID()); - portID = null; - } - - @Test - public void testSetPortID() throws Exception { - Assert.assertNull(portBean.getPortID()); - portID = "test"; - portBean.setPortID(portID); - Assert.assertEquals(portID,portBean.getPortID()); - } - - @Test - public void testGetPortIPAddress() throws Exception { - Assert.assertNull(portBean.getPortIPAddress()); - portIPAddress = "test"; - portBean.setPortIPAddress(portIPAddress); - Assert.assertEquals(portIPAddress,portBean.getPortIPAddress()); - portIPAddress = null; - } - - @Test - public void testSetPortIPAddress() throws Exception { - Assert.assertNull(portBean.getPortIPAddress()); - portIPAddress = "test"; - portBean.setPortIPAddress(portIPAddress); - Assert.assertEquals(portIPAddress,portBean.getPortIPAddress()); - } - - @Test - public void testGetMask() throws Exception { - Assert.assertNull(portBean.getMask()); - mask = "test"; - portBean.setMask(mask); - Assert.assertEquals(mask,portBean.getMask()); - mask = null; - } - - @Test - public void testSetMask() throws Exception { - Assert.assertNull(portBean.getMask()); - mask = "test"; - portBean.setMask(mask); - Assert.assertEquals(mask,portBean.getMask()); - } - - @Test - public void testGetLocation() throws Exception { - Assert.assertNull(portBean.getLocation()); - location = "test"; - portBean.setLocation(location); - Assert.assertEquals(location,portBean.getLocation()); - location = null; - } - - @Test - public void testSetLocation() throws Exception { - Assert.assertNull(portBean.getLocation()); - location = "test"; - portBean.setLocation(location); - Assert.assertEquals(location,portBean.getLocation()); - } - - @Test - public void testGetBandwidth() throws Exception { - Assert.assertNull(portBean.getBandwidth()); - bandwidth = "test"; - portBean.setBandwidth(bandwidth); - Assert.assertEquals(bandwidth,portBean.getBandwidth()); - bandwidth = null; - } - - @Test - public void testSetBandwidth() throws Exception { - Assert.assertNull(portBean.getBandwidth()); - bandwidth = "test"; - portBean.setBandwidth(bandwidth); - Assert.assertEquals(bandwidth,portBean.getBandwidth()); - } -} \ No newline at end of file diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBeanTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBeanTest.java deleted file mode 100644 index d147976..0000000 --- a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/entity/ResourceBeanTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.opendaylight.nemo.renderer.openflow.entity; - -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.nemo.renderer.openflow.entity.HostBean; -import org.opendaylight.nemo.renderer.openflow.entity.LinkBean; -import org.opendaylight.nemo.renderer.openflow.entity.NodeBean; -import org.opendaylight.nemo.renderer.openflow.entity.ResourceBean; -import java.util.LinkedList; - -import java.util.List; - -import static org.junit.Assert.*; - -import static org.mockito.Mockito.*; -import static org.junit.Assert.*; -/** - * Created by zhangmeng on 2015/11/8. - */ -public class ResourceBeanTest extends TestCase { - - private ResourceBean resourceBean; - private List nodelist; - private List linklist; - private List hostlist; - - @Before - public void setUp() throws Exception { - resourceBean = new ResourceBean(); - nodelist = new LinkedList(); - linklist = new LinkedList(); - hostlist = new LinkedList(); - } - - @Test - public void testGetNodelist() throws Exception { - Assert.assertNull(resourceBean.getNodelist()); - nodelist.add(new NodeBean()); - resourceBean.setNodelist(nodelist); - Assert.assertNotNull(resourceBean.getNodelist()); - nodelist.clear(); - } - - @Test - public void testSetNodelist() throws Exception { - Assert.assertNull(resourceBean.getNodelist()); - nodelist.add(new NodeBean()); - resourceBean.setNodelist(nodelist); - Assert.assertNotNull(resourceBean.getNodelist()); - } - - @Test - public void testGetLinklist() throws Exception { - Assert.assertNull(resourceBean.getLinklist()); - linklist.add(new LinkBean()); - resourceBean.setLinklist(linklist); - Assert.assertNotNull(resourceBean.getLinklist()); - linklist.clear(); - } - - @Test - public void testSetLinklist() throws Exception { - Assert.assertNull(resourceBean.getLinklist()); - linklist.add(new LinkBean()); - resourceBean.setLinklist(linklist); - Assert.assertNotNull(resourceBean.getLinklist()); - } - - @Test - public void testGetHostlist() throws Exception { - Assert.assertNull(resourceBean.getHostlist()); - hostlist.add(new HostBean()); - resourceBean.setHostlist(hostlist); - Assert.assertNotNull(resourceBean.getHostlist()); - hostlist.clear(); - } - - @Test - public void testSetHostlist() throws Exception { - Assert.assertNull(resourceBean.getHostlist()); - hostlist.add(new HostBean()); - resourceBean.setHostlist(hostlist); - Assert.assertNotNull(resourceBean.getHostlist()); - } -} \ No newline at end of file -- 2.36.6