From: Giovanni Meo Date: Mon, 12 Aug 2013 12:11:22 +0000 (+0200) Subject: protocol.openflow_netty cleanup X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=refs%2Fchanges%2F52%2F852%2F1 protocol.openflow_netty cleanup - Avoid code duplication between protocol.openflow and protocol.openflow_netty. The bundle protocol.openflow_netty can largely be equated to a bundle that is sub-classing (or well sub-bundling) protocol.openflow, hence lets embed in protocol.openflow_netty protocol.openflow and lets override in the class path what we need. For instance protocol.openflow embeds openflowJ while we need openflow_netty, so making sure that openflow_netty appears first in the classpath of the bundle ensure the proper picking of the resources. - In protocol.openflow_netty the portions that need to be reimplemented are: # The activator, which largely is like the one of the protocol.openflow bundle with the enhancements of EnhacedController instantiation. # The logic netty specific, provide by Colin/Muthu So the protocol.openflow_netty is just containing that logic and the rest comes mint from protocol.openflow. - The EnhancedActivator of protocol.openflow_netty extends the base class being the protocol.openflow activator, and just override the instantiation of EnhancedController when Controller.class was being invoked. - Remove openflowj_netty from distribution, is not needed because is embedded in the protocol.openflow_netty - Remove embedding in openflowj_netty of the netty dependency given it's being used as a standalone bundle. Change-Id: I27d7f6bb45ede88c077bead640cc69c74e49a9d3 Signed-off-by: Giovanni Meo --- diff --git a/opendaylight/distribution/opendaylight/src/assemble/bin.xml b/opendaylight/distribution/opendaylight/src/assemble/bin.xml index a85c3f8860..9e45294645 100644 --- a/opendaylight/distribution/opendaylight/src/assemble/bin.xml +++ b/opendaylight/distribution/opendaylight/src/assemble/bin.xml @@ -11,9 +11,11 @@ org.opendaylight.controller.thirdparty:org.openflow.openflowj + org.opendaylight.controller.thirdparty:org.openflow.openflowj_netty org.opendaylight.controller:clustering.stub org.opendaylight.controller:logging.bridge org.opendaylight.controller:protocol_plugins.stub + org.opendaylight.controller:protocol_plugins.openflow org.opendaylight.controller:*.integrationtest org.opendaylight.controller:hosttracker_new org.opendaylight.controller:hosttracker_new.implementation diff --git a/opendaylight/protocol_plugins/openflow_netty/pom.xml b/opendaylight/protocol_plugins/openflow_netty/pom.xml index 25849addfb..970e1504a6 100644 --- a/opendaylight/protocol_plugins/openflow_netty/pom.xml +++ b/opendaylight/protocol_plugins/openflow_netty/pom.xml @@ -8,41 +8,9 @@ ../../commons/opendaylight protocol_plugins.openflow_netty - 0.4.0-SNAPSHOT + 0.1.0-SNAPSHOT bundle - - - jenkins - - - env.BUILD_NUMBER - - - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.5.1 - - - xml - - - - - package - - cobertura - - - - - - - - @@ -55,6 +23,7 @@ org.opendaylight.controller.sal.packet, org.opendaylight.controller.sal.action, + org.opendaylight.controller.sal.connection, org.opendaylight.controller.sal.discovery, org.opendaylight.controller.sal.topology, org.opendaylight.controller.sal.core, @@ -63,7 +32,6 @@ org.opendaylight.controller.sal.inventory, org.opendaylight.controller.sal.match, org.opendaylight.controller.sal.utils, - org.opendaylight.controller.protocol_plugin.openflow.core, org.apache.commons.lang3.builder, org.apache.commons.lang3.tuple, org.apache.felix.dm, @@ -74,18 +42,17 @@ org.jboss.netty.* - org.opendaylight.controller.protocol_plugin.openflow.core.internal, - org.opendaylight.controller.protocol_plugin.openflow.core + org.opendaylight.controller.protocol_plugin.openflow.core.internal;-split-package:=merge-first, + org.opendaylight.controller.protocol_plugin.openflow.core;-split-package:=merge-first, - org.openflow.openflowj_netty,org.jboss.netty;type=!pom;inline=false + org.openflow.openflowj_netty,org.jboss.netty;protocol_plugins.openflow;type=!pom;inline=false false - - org.opendaylight.controller.protocol_plugin.openflow.internal.Activator + org.opendaylight.controller.protocol_plugin.openflow.internal.EnhancedActivator @@ -96,13 +63,27 @@ org.opendaylight.controller sal - 0.4.0-SNAPSHOT + 0.5.0-SNAPSHOT + + org.opendaylight.controller + sal.connection + 0.1.0-SNAPSHOT + + org.opendaylight.controller.thirdparty org.openflow.openflowj_netty 1.0.2-SNAPSHOT + + org.opendaylight.controller + protocol_plugins.openflow + 0.4.0-SNAPSHOT + junit junit @@ -114,6 +95,5 @@ netty 3.2.6.Final - diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketListen.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketListen.java deleted file mode 100644 index 300967e87c..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketListen.java +++ /dev/null @@ -1,39 +0,0 @@ - -/* - * Copyright (c) 2013 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 - */ - -/** - * @file IDataPacketListen.java - * - * @brief Interface to dispatch locally in the protocol plugin the - * data packets, intended especially for Discovery, main difference - * here with the analogous of SAL is that this is Global - * inherently - * - */ -package org.opendaylight.controller.protocol_plugin.openflow; - -import org.opendaylight.controller.sal.packet.RawPacket; -import org.opendaylight.controller.sal.packet.PacketResult; - -/** - * Interface to dispatch locally in the protocol plugin the - * data packets, intended especially for Discovery, main difference - * here with the analogous of SAL is that this is Global - * inherently. - */ -public interface IDataPacketListen { - /** - * Dispatch received data packet - * - * @param inPkt - * The incoming raw packet - * @return Possible results for Data packet processing handler - */ - public PacketResult receiveDataPacket(RawPacket inPkt); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketMux.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketMux.java deleted file mode 100644 index 747a8fbec5..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IDataPacketMux.java +++ /dev/null @@ -1,31 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -/** - * @file IDataPacketMux.java - * - * @brief Simple wrapped interface for the IPluginInDataPacketService - * which will be only exported by DataPacketServices mux/demux - * component and will be only accessible by the openflow protocol - * plugin - */ - -import org.opendaylight.controller.sal.packet.IPluginInDataPacketService; - -/** - * Simple wrapped interface for the IPluginInDataPacketService - * which will be only exported by DataPacketServices mux/demux - * component and will be only accessible by the openflow protocol - * plugin - */ -public interface IDataPacketMux extends IPluginInDataPacketService { - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IFlowProgrammerNotifier.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IFlowProgrammerNotifier.java deleted file mode 100644 index 307176590f..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IFlowProgrammerNotifier.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService; - -/** - * Interface which defines the methods exposed by the Flow Programmer Notifier. - * Their implementation relays the asynchronous messages received from the - * network nodes to the the SAL Flow Programmer Notifier Service on the proper - * container. - */ -public interface IFlowProgrammerNotifier extends - IPluginOutFlowProgrammerService { - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimExternalListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimExternalListener.java deleted file mode 100644 index df03a04384..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimExternalListener.java +++ /dev/null @@ -1,18 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -/** - * Wrapper of Interface that provides inventory updates locally in the protocol - * plugin. - */ -public interface IInventoryShimExternalListener extends - IInventoryShimInternalListener { -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java deleted file mode 100644 index cabc36bcb9..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IInventoryShimInternalListener.java +++ /dev/null @@ -1,47 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; - -/** - * The Interface provides inventory updates to inventory listeners within the - * protocol plugin - */ -public interface IInventoryShimInternalListener { - /** - * Updates node and its properties - * - * @param node {@link org.opendaylight.controller.sal.core.Node} being updated - * @param type {@link org.opendaylight.controller.sal.core.UpdateType} - * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Description} and/or - * {@link org.opendaylight.controller.sal.core.Tier} etc. - */ - public void updateNode(Node node, UpdateType type, Set props); - - /** - * Updates node connector and its properties - * - * @param nodeConnector {@link org.opendaylight.controller.sal.core.NodeConnector} being updated - * @param type {@link org.opendaylight.controller.sal.core.UpdateType} - * @param props set of {@link org.opendaylight.controller.sal.core.Property} such as - * {@link org.opendaylight.controller.sal.core.Description} and/or - * {@link org.opendaylight.controller.sal.core.State} etc. - */ - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props); - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java deleted file mode 100644 index 6638fcffba..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IOFStatisticsManager.java +++ /dev/null @@ -1,108 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -import java.util.List; - -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.statistics.OFStatistics; -import org.openflow.protocol.statistics.OFStatisticsType; - -/** - * Interface to expose the openflow statistics collected on the switches - */ -public interface IOFStatisticsManager { - /** - * Return all the statistics for all the flows present on the specified switch - * - * @param switchId the openflow datapath id - * @return the list of openflow statistics - */ - List getOFFlowStatistics(Long switchId); - - /** - * Return all the statistics for all the flows present on the specified switch - * - * @param switchId the openflow datapath id - * @param ofMatch the openflow match to query. If null, the query is intended for all the flows - * @return the list of openflow statistics - */ - List getOFFlowStatistics(Long switchId, OFMatch ofMatch); - - /** - * Return the description statistics for the specified switch. - * - * @param switchId the openflow datapath id - * @return the list of openflow statistics - */ - List getOFDescStatistics(Long switchId); - - /** - * Return the flow table statistics for the specified switch. - * - * @param switchId the openflow datapath id - * @return the list of openflow statistics - */ - List getOFTableStatistics(Long switchId); - - /** - * Returns the statistics for all the ports on the specified switch - * - * @param switchId the openflow datapath id - * @return the list of openflow statistics - */ - List getOFPortStatistics(Long switchId); - - /** - * Returns the statistics for the specified switch port - * - * @param switchId the openflow datapath id - * @param portId the openflow switch port id - * @return the list of openflow statistics - */ - List getOFPortStatistics(Long switchId, short portId); - - /** - * Returns the number of flows installed on the switch - * - * @param switchId the openflow datapath id - * @return the number of flows installed on the switch - */ - int getFlowsNumber(long switchId); - - /** - * Send a statistics request message to the specified switch and returns - * the switch response. It blocks the caller until the response has arrived - * from the switch or the request has timed out - * - * @param switchId the openflow datapath id of the target switch - * @param statType the openflow statistics type - * @param target the target object. For flow statistics it is the OFMatch. - * For port statistics, it is the port id. If null the query - * will be performed for all the targets for the specified - * statistics type. - * - * @param timeout the timeout in milliseconds the system will wait for a response - * from the switch, before declaring failure - * @return the list of openflow statistics - */ - List queryStatistics(Long switchId, - OFStatisticsType statType, Object target); - - /** - * Returns the averaged transmit rate for the passed switch port - * - * @param switchId the openflow datapath id of the target switch - * @param portId the openflow switch port id - * @return the median transmit rate in bits per second - */ - long getTransmitRate(Long switchId, Short port); - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IPluginReadServiceFilter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IPluginReadServiceFilter.java deleted file mode 100644 index a000024e9e..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IPluginReadServiceFilter.java +++ /dev/null @@ -1,90 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -import java.util.List; - -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.reader.FlowOnNode; -import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; -import org.opendaylight.controller.sal.reader.NodeDescription; - -/** - * Interface to serve the hardware information requests coming from SAL - * It is implemented by the respective OF1.0 plugin component - * - */ -public interface IPluginReadServiceFilter { - /** - * Returns the hardware image for the specified flow - * on the specified network node for the passed container - * - * @param container - * @param node - * @param flow - * @param cached - * @return - */ - public FlowOnNode readFlow(String container, Node node, Flow flow, - boolean cached); - - /** - * Returns the hardware view of all the flow installed - * on the specified network node for the passed container - * - * @param container - * @param node - * @param cached - * @return - */ - public List readAllFlow(String container, Node node, - boolean cached); - - /** - * Returns the description of the network node as provided by the node itself - * - * @param node - * @param cached - * @return - */ - public NodeDescription readDescription(Node node, boolean cached); - - /** - * Returns the hardware view of the specified network node connector - * for the given container - * @param node - * @return - */ - public NodeConnectorStatistics readNodeConnector(String container, - NodeConnector nodeConnector, boolean cached); - - /** - * Returns the hardware info for all the node connectors on the - * specified network node for the given container - * - * @param node - * @return - */ - public List readAllNodeConnector(String container, - Node node, boolean cached); - - /** - * Returns the average transmit rate for the specified node conenctor on - * the given container. If the node connector does not belong to the passed - * container a zero value is returned - * - * @param container - * @param nodeConnector - * @return tx rate [bps] - */ - public long getTransmitRate(String container, NodeConnector nodeConnector); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IRefreshInternalProvider.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IRefreshInternalProvider.java deleted file mode 100644 index 21efae3659..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IRefreshInternalProvider.java +++ /dev/null @@ -1,34 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -/** - * @file IRefreshInternalProvider.java - * - * @brief Topology refresh notifications requested by application - * to be fetched from the plugin - * - * For example, an application that has been started late, will want to - * be up to date with the latest topology. Hence, it requests for a - * topology refresh from the plugin. - */ - -/** - * Topology refresh requested by the application from the plugin - * - */ - -public interface IRefreshInternalProvider { - - /** - * @param containerName - */ - public void requestRefresh(String containerName); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java deleted file mode 100644 index b93d8d5e41..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.opendaylight.controller.protocol_plugin.openflow; - -import org.openflow.protocol.statistics.OFDescriptionStatistics; - -/** - * Interface which defines the api which gets called when the information - * contained in the OF description statistics reply message from a network - * is updated with new one. - */ -public interface IStatisticsListener { - public void descriptionRefreshed(Long switchId, - OFDescriptionStatistics description); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsServiceShimListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsServiceShimListener.java deleted file mode 100644 index 110523977c..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/IStatisticsServiceShimListener.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.opendaylight.controller.protocol_plugin.openflow; - -import java.util.List; - -import org.openflow.protocol.statistics.OFStatistics; - -/** - * @file IStatisticsShimListener.java - * - * @brief Statistics notifications provided by SAL toward the application - * - * For example an application that wants to keep up to date with the - * updates coming from SAL it will register in the OSGi service - * registry this interface (on a per-container base) and SAL will call it - * providing the update - */ - -/** - * Statistics notifications provided by SAL toward the application - * - */ -public interface IStatisticsServiceShimListener { - - /** - * Called to update statistics - * - * @param - * @param - * @param - */ - public void flowStatisticsUpdate(Long switchId, - List value, String containerName); - - public void descStatisticsUpdate(Long switchId, - List value, String containerName); - - public void portStatisticsUpdate(Long switchId, - List value, String containerName); - - public void flowTableStatisticsUpdate(Long switchId, - List value, String containerName); - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/ITopologyServiceShimListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/ITopologyServiceShimListener.java deleted file mode 100644 index eaff585f68..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/ITopologyServiceShimListener.java +++ /dev/null @@ -1,47 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow; - -import java.util.Set; - -import org.opendaylight.controller.sal.core.Edge; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; - -/** - * The Interface provides Edge updates to the topology listeners - */ -public interface ITopologyServiceShimListener { - /** - * Called to update on Edge in the topology graph - * - * @param edge {@link org.opendaylight.controller.sal.core.Edge} being updated - * @param type {@link org.opendaylight.controller.sal.core.UpdateType} - * @param props set of {@link org.opendaylight.controller.sal.core.Property} like - * {@link org.opendaylight.controller.sal.core.Bandwidth} and/or - * {@link org.opendaylight.controller.sal.core.Latency} etc. - */ - public void edgeUpdate(Edge edge, UpdateType type, Set props); - - /** - * Called when an Edge utilization is above the safe threshold configured - * on the controller - * @param {@link org.opendaylight.controller.sal.core.Edge} - */ - public void edgeOverUtilized(Edge edge); - - /** - * Called when the Edge utilization is back to normal, below the safety - * threshold level configured on the controller - * - * @param {@link org.opendaylight.controller.sal.core.Edge} - */ - public void edgeUtilBackToNormal(Edge edge); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IController.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IController.java deleted file mode 100644 index 4920bb491b..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IController.java +++ /dev/null @@ -1,66 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; - -import java.net.InetAddress; -import java.util.Map; - -import org.openflow.protocol.OFType; - -/** - * This interface defines an abstraction of the Open Flow Controller that allows applications to control and manage the Open Flow switches. - * - */ -public interface IController { - - /** - * Allows application to start receiving OF messages received from switches. - * @param type the type of OF message that applications want to receive - * @param listener: Object that implements the IMessageListener - */ - public void addMessageListener(OFType type, IMessageListener listener); - - /** - * Allows application to stop receiving OF message received from switches. - * @param type The type of OF message that applications want to stop receiving - * @param listener The object that implements the IMessageListener - */ - public void removeMessageListener(OFType type, IMessageListener listener); - - /** - * Allows application to start receiving switch state change events. - * @param listener The object that implements the ISwitchStateListener - */ - public void addSwitchStateListener(ISwitchStateListener listener); - - /** - * Allows application to stop receiving switch state change events. - * @param listener The object that implements the ISwitchStateListener - */ - public void removeSwitchStateListener(ISwitchStateListener listener); - - /** - * Returns a map containing all the OF switches that are currently connected to the Controller. - * @return Map of ISwitch - */ - public Map getSwitches(); - - /** - * Returns the ISwitch of the given switchId. - * - * @param switchId The switch ID - * @return ISwitch if present, null otherwise - */ - public ISwitch getSwitch(Long switchId); - - public InetAddress getControllerIdForSwitch(Long id); - - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IEnhancedSwitch.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IEnhancedSwitch.java new file mode 100644 index 0000000000..954f92aa40 --- /dev/null +++ b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IEnhancedSwitch.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; + +import java.net.SocketAddress; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.openflow.protocol.OFMessage; +import org.openflow.protocol.OFPhysicalPort; +import org.openflow.protocol.OFStatisticsRequest; + +/** + * This interface defines an abstraction of an Open Flow Switch. + * + */ +public interface IEnhancedSwitch extends ISwitch { + public void startHandler(); + + public void shutDownHandler(); + + public void handleMessage(OFMessage ofMessage); + + public void flushBufferedMessages(); + + public SocketAddress getRemoteAddress(); + + public SocketAddress getLocalAddress(); +} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageListener.java deleted file mode 100644 index aed19db04c..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageListener.java +++ /dev/null @@ -1,26 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; - -import org.openflow.protocol.OFMessage; - -/** - * Interface to be implemented by applications that want to receive OF messages. - * - */ -public interface IMessageListener { - /** - * This method is called by the Controller when a message is received from a switch. - * Application who is interested in receiving OF Messages needs to implement this method. - * @param sw The ISwitch which sent the OF message - * @param msg The OF message - */ - public void receive(ISwitch sw, OFMessage msg); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageReadWrite.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageReadWrite.java deleted file mode 100644 index 8cfad483fb..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/IMessageReadWrite.java +++ /dev/null @@ -1,53 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; - -import java.util.List; - -import org.openflow.protocol.OFMessage; - -/** - * This interface defines low level routines to read/write messages on an open - * socket channel. If secure communication is desired, these methods also perform - * encryption and decryption of the network data. - */ -public interface IMessageReadWrite { - /** - * Sends the OF message out over the socket channel. For secure - * communication, the data will be encrypted. - * - * @param msg OF message to be sent - * @throws Exception - */ - public void asyncSend(OFMessage msg) throws Exception; - - /** - * Resumes sending the remaining messages in the outgoing buffer - * @throws Exception - */ - public void resumeSend() throws Exception; - - /** - * Reads the incoming network data from the socket and retrieves the OF - * messages. For secure communication, the data will be decrypted first. - * - * @return list of OF messages - * @throws Exception - */ - public List readMessages() throws Exception; - - /** - * Proper clean up when the switch connection is closed - * - * @return - * @throws Exception - */ - public void stop() throws Exception; -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitch.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitch.java deleted file mode 100644 index 5f804ecebe..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitch.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; - -import java.net.SocketAddress; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPhysicalPort; -import org.openflow.protocol.OFStatisticsRequest; - -/** - * This interface defines an abstraction of an Open Flow Switch. - * - */ -public interface ISwitch { - /** - * Gets a unique XID. - * - * @return XID - */ - public int getNextXid(); - - /** - * Returns the Switch's ID. - * - * @return the Switch's ID - */ - public Long getId(); - - /** - * Returns the Switch's table numbers supported by datapath - * - * @return the tables - */ - public Byte getTables(); - - /** - * Returns the Switch's bitmap of supported ofp_action_type - * - * @return the actions - */ - public Integer getActions(); - - /** - * Returns the Switch's bitmap of supported ofp_capabilities - * - * @return the capabilities - */ - public Integer getCapabilities(); - - /** - * Returns the Switch's buffering capacity in Number of Pkts - * - * @return the buffers - */ - public Integer getBuffers(); - - /** - * Returns the Date when the switch was connected. - * - * @return Date The date when the switch was connected - */ - public Date getConnectedDate(); - - /** - * This method puts the message in an outgoing priority queue with normal - * priority. It will be served after high priority messages. The method - * should be used for non-critical messages such as statistics request, - * discovery packets, etc. An unique XID is generated automatically and - * inserted into the message. - * - * @param msg - * The OF message to be sent - * @return The XID used - */ - public Integer asyncSend(OFMessage msg); - - /** - * This method puts the message in an outgoing priority queue with normal - * priority. It will be served after high priority messages. The method - * should be used for non-critical messages such as statistics request, - * discovery packets, etc. The specified XID is inserted into the message. - * - * @param msg - * The OF message to be Sent - * @param xid - * The XID to be used in the message - * @return The XID used - */ - public Integer asyncSend(OFMessage msg, int xid); - - /** - * This method puts the message in an outgoing priority queue with high - * priority. It will be served first before normal priority messages. The - * method should be used for critical messages such as hello, echo reply - * etc. An unique XID is generated automatically and inserted into the - * message. - * - * @param msg - * The OF message to be sent - * @return The XID used - */ - public Integer asyncFastSend(OFMessage msg); - - /** - * This method puts the message in an outgoing priority queue with high - * priority. It will be served first before normal priority messages. The - * method should be used for critical messages such as hello, echo reply - * etc. The specified XID is inserted into the message. - * - * @param msg - * The OF message to be sent - * @return The XID used - */ - public Integer asyncFastSend(OFMessage msg, int xid); - - /** - * Sends the OF message followed by a Barrier Request with a unique XID - * which is automatically generated, and waits for a result from the switch. - * - * @param msg - * The message to be sent - * @return An Object which has one of the followings instances/values: - * Boolean with value true to indicate the message has been - * successfully processed and acknowledged by the switch; Boolean - * with value false to indicate the message has failed to be - * processed by the switch within a period of time or OFError to - * indicate that the message has been denied by the switch which - * responded with OFError. - */ - public Object syncSend(OFMessage msg); - - /** - * Returns a map containing all OFPhysicalPorts of this switch. - * - * @return The Map of OFPhysicalPort - */ - public Map getPhysicalPorts(); - - /** - * Returns a Set containing all port IDs of this switch. - * - * @return The Set of port ID - */ - public Set getPorts(); - - /** - * Returns OFPhysicalPort of the specified portNumber of this switch. - * - * @param portNumber - * The port ID - * @return OFPhysicalPort for the specified PortNumber - */ - public OFPhysicalPort getPhysicalPort(Short portNumber); - - /** - * Returns the bandwidth of the specified portNumber of this switch. - * - * @param portNumber - * the port ID - * @return bandwidth - */ - public Integer getPortBandwidth(Short portNumber); - - /** - * Returns True if the port is enabled, - * - * @param portNumber - * @return True if the port is enabled - */ - public boolean isPortEnabled(short portNumber); - - /** - * Returns True if the port is enabled. - * - * @param port - * @return True if the port is enabled - */ - public boolean isPortEnabled(OFPhysicalPort port); - - /** - * Returns a list containing all enabled ports of this switch. - * - * @return: List containing all enabled ports of this switch - */ - public List getEnabledPorts(); - - /** - * Sends OFStatisticsRequest with a unique XID generated automatically and - * waits for a result from the switch. - * - * @param req - * the OF Statistic Request to be sent - * @return Object has one of the following instances/values:: - * List, a list of statistics records received from - * the switch as response from the request; OFError if the switch - * failed handle the request or NULL if timeout has occurred while - * waiting for the response. - */ - public Object getStatistics(OFStatisticsRequest req); - - /** - * Returns true if the switch has reached the operational state (has sent - * FEATURE_REPLY to the controller). - * - * @return true if the switch is operational - */ - public boolean isOperational(); - - /** - * Send Barrier message synchronously. The caller will be blocked until the - * Barrier reply arrives. - */ - Object syncSendBarrierMessage(); - - /** - * Send Barrier message asynchronously. The caller is not blocked. The - * Barrier message will be sent in a transmit thread which will be blocked - * until the Barrier reply arrives. - */ - Object asyncSendBarrierMessage(); - - - public void startHandler(); - - public void shutDownHandler(); - - public void handleMessage(OFMessage ofMessage); - - public void flushBufferedMessages(); - - public SocketAddress getRemoteAddress(); - - public SocketAddress getLocalAddress(); -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitchStateListener.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitchStateListener.java deleted file mode 100644 index 608b6f583b..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitchStateListener.java +++ /dev/null @@ -1,31 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core; - -/** - * Interface to be implemented by applications that want to receive switch state event changes. - * - */ -public interface ISwitchStateListener { - /** - * This method is invoked by Controller when a switch has been connected to the Controller. - * Application who wants to receive this event needs to implement this method. - * @param sw The switch that has just connected. - */ - public void switchAdded(ISwitch sw); - - /** - * This method is invoked by Controller when a switch has been disconnected from the Controller. - * Application who wants to receive this event needs to implement this method. - * @param sw The switch that has just disconnected. - */ - public void switchDeleted(ISwitch sw); - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedController.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedController.java index eb497684ae..53f2d9f4de 100644 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedController.java +++ b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedController.java @@ -48,12 +48,16 @@ import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFType; import org.openflow.protocol.factory.BasicFactory; import org.openflow.protocol.factory.MessageParseException; - - import org.opendaylight.controller.protocol_plugin.openflow.core.IController; +import org.opendaylight.controller.protocol_plugin.openflow.core.IEnhancedSwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener; +import org.opendaylight.controller.sal.connection.ConnectionConstants; +import org.opendaylight.controller.sal.connection.IPluginInConnectionService; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.utils.Status; +import org.opendaylight.controller.sal.utils.StatusCode; //import org.opendaylight.controller.protocol_plugin.openflow.core.internal.OFChannelState.HandshakeState; //import org.openflow.protocol.OFType; import org.slf4j.Logger; @@ -62,7 +66,7 @@ import org.slf4j.LoggerFactory; -public class EnhancedController implements IController { +public class EnhancedController implements IController, IPluginInConnectionService { protected BasicFactory factory; @@ -76,7 +80,7 @@ public class EnhancedController implements IController { private ConcurrentHashMap connectedSwitches; // Track connected switches via ChannelID. Whenever the message - private ConcurrentHashMap channelIDToSwitchMap; + private ConcurrentHashMap channelIDToSwitchMap; // only 1 message listener per OFType private ConcurrentMap messageListeners; @@ -216,7 +220,7 @@ public class EnhancedController implements IController { public void init() { logger.debug("Initializing!"); this.connectedSwitches = new ConcurrentHashMap(); - this.channelIDToSwitchMap = new ConcurrentHashMap(); + this.channelIDToSwitchMap = new ConcurrentHashMap(); this.messageListeners = new ConcurrentHashMap(); this.switchStateListener = null; this.hashedWheelTimer = new HashedWheelTimer(); @@ -252,9 +256,9 @@ public class EnhancedController implements IController { * */ public void stop() { - for (Iterator> it = channelIDToSwitchMap.entrySet().iterator(); it + for (Iterator> it = channelIDToSwitchMap.entrySet().iterator(); it .hasNext();) { - Entry entry = it.next(); + Entry entry = it.next(); ((EnhancedSwitchHandler) entry.getValue()).stop(); } @@ -310,7 +314,7 @@ public class EnhancedController implements IController { Integer channelID = e.getChannel().getId(); - ISwitch switchHandler = new EnhancedSwitchHandler(controller, + IEnhancedSwitch switchHandler = new EnhancedSwitchHandler(controller, channelID, channel, hashedWheelTimer, executorService, statsHandler); switchHandler.startHandler(); channelIDToSwitchMap.put(channelID, switchHandler); @@ -326,7 +330,7 @@ public class EnhancedController implements IController { // controller both release resources of the switch concerned Integer channelID = e.getChannel().getId(); - ISwitch switchHandler = channelIDToSwitchMap.get(channelID); + IEnhancedSwitch switchHandler = channelIDToSwitchMap.get(channelID); if (switchHandler != null){ switchHandler.shutDownHandler(); } @@ -400,7 +404,7 @@ public class EnhancedController implements IController { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Integer messageChannelId = e.getChannel().getId(); - ISwitch swHan = (EnhancedSwitchHandler)channelIDToSwitchMap.get(messageChannelId); + IEnhancedSwitch swHan = (EnhancedSwitchHandler)channelIDToSwitchMap.get(messageChannelId); if (e.getMessage() instanceof List) { //@SuppressWarnings("unchecked") @@ -432,7 +436,7 @@ public class EnhancedController implements IController { public void processOFMessage(OFMessage ofm, Integer channelID){ - ISwitch switchHandler = channelIDToSwitchMap.get(channelID); + IEnhancedSwitch switchHandler = (IEnhancedSwitch) channelIDToSwitchMap.get(channelID); statsHandler.countForEntitySimpleMeasurement(channelID, TrafficStatisticsHandler.ENTITY_COUNTER_RCV_MSG); if (switchHandler != null){ switchHandler.handleMessage(ofm); @@ -634,26 +638,37 @@ public class EnhancedController implements IController { } @Override - public InetAddress getControllerIdForSwitch(Long id) { - //Added to enable Cluster handling. - - if(id==null) - { - logger.debug("id is null"); - return null; + public Status disconnect(Node node) { + ISwitch sw = getSwitch((Long)node.getID()); + if (sw != null) { + if (sw instanceof EnhancedSwitchHandler) { + EnhancedSwitchHandler eSw = (EnhancedSwitchHandler)sw; + disconnectSwitch(sw, eSw.getSwitchChannelID()); + } } + return new Status(StatusCode.SUCCESS); + } - ISwitch sw = (ISwitch) connectedSwitches.get(id); - - SocketAddress sockAddr = sw.getLocalAddress(); + @Override + public Node connect(String connectionIdentifier, Map params) { + return null; + } - if( sockAddr != null && InetSocketAddress.class.isAssignableFrom(sockAddr.getClass())) { - InetAddress localAddress = ((InetSocketAddress) sockAddr).getAddress(); - this.logger.debug("socketchannel local address is " + localAddress); - return localAddress; + /** + * View Change notification + */ + public void notifyClusterViewChanged() { + for (ISwitch sw : connectedSwitches.values()) { + notifySwitchAdded(sw); } - - return null; } + /** + * Node Disconnected from the node's master controller. + */ + @Override + public void notifyNodeDisconnectFromMaster(Node node) { + ISwitch sw = connectedSwitches.get((Long)node.getID()); + if (sw != null) notifySwitchAdded(sw); + } } diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedSwitchHandler.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedSwitchHandler.java index b84b3ac8e1..91a2806d40 100644 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedSwitchHandler.java +++ b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/EnhancedSwitchHandler.java @@ -22,6 +22,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.util.HashedWheelTimer; import org.jboss.netty.util.Timeout; import org.jboss.netty.util.TimerTask; +import org.opendaylight.controller.protocol_plugin.openflow.core.IEnhancedSwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.internal.SwitchEvent.SwitchEventType; import org.openflow.protocol.OFBarrierReply; @@ -49,7 +50,7 @@ import org.openflow.protocol.factory.MessageParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class EnhancedSwitchHandler implements ISwitch { +public class EnhancedSwitchHandler implements IEnhancedSwitch { private static final Logger logger = LoggerFactory @@ -142,6 +143,9 @@ public class EnhancedSwitchHandler implements ISwitch { } + Integer getSwitchChannelID() { + return this.switchChannelID; + } public void startHandler(){ this.factory = new BasicFactory(); diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/PriorityMessage.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/PriorityMessage.java deleted file mode 100644 index c9d17243f1..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/PriorityMessage.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core.internal; - -import java.util.concurrent.atomic.AtomicLong; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.OFMessage; - -/** - * This class describes an OpenFlow message with priority - */ -class PriorityMessage { - OFMessage msg; - int priority; - final static AtomicLong seq = new AtomicLong(); - final long seqNum; - boolean syncReply; // set to true if we want to be blocked until the response arrives - - public PriorityMessage(OFMessage msg, int priority) { - this.msg = msg; - this.priority = priority; - this.seqNum = seq.getAndIncrement(); - this.syncReply = false; - } - - public PriorityMessage(OFMessage msg, int priority, boolean syncReply) { - this(msg, priority); - this.syncReply = syncReply; - } - - public OFMessage getMsg() { - return msg; - } - - public void setMsg(OFMessage msg) { - this.msg = msg; - } - - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - } - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - - @Override - public String toString() { - return "PriorityMessage[" + ReflectionToStringBuilder.toString(this) - + "]"; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/StatisticsCollector.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/StatisticsCollector.java deleted file mode 100644 index 98fb803bd8..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/StatisticsCollector.java +++ /dev/null @@ -1,81 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core.internal; - -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CountDownLatch; - -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFError; -import org.openflow.protocol.OFStatisticsReply; -import org.openflow.protocol.OFStatisticsRequest; -import org.openflow.protocol.statistics.OFStatistics; - -public class StatisticsCollector implements Callable { - - private ISwitch sw; - private Integer xid; - private OFStatisticsRequest request; - private CountDownLatch latch; - private Object result; - private List stats; - - public StatisticsCollector(ISwitch sw, int xid, OFStatisticsRequest request) { - this.sw = sw; - this.xid = xid; - this.request = request; - latch = new CountDownLatch(1); - result = new Object(); - stats = new CopyOnWriteArrayList(); - } - - /* - * accumulate the stats records in result - * Returns: true: if this is the last record - * false: more to come - */ - public boolean collect(OFStatisticsReply reply) { - synchronized (result) { - stats.addAll(reply.getStatistics()); - if ((reply.getFlags() & 0x01) == 0) { - // all stats are collected, done - result = stats; - return true; - } else { - // still waiting for more to come - return false; - } - } - } - - @Override - public Object call() throws Exception { - sw.asyncSend(request, xid); - // free up the request as it is no longer needed - request = null; - // wait until all stats replies are received or timeout - latch.await(); - return result; - } - - public Integer getXid() { - return this.xid; - } - - public void wakeup() { - this.latch.countDown(); - } - - public void wakeup(OFError errorMsg) { - - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchEvent.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchEvent.java deleted file mode 100644 index 87e30d70c6..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchEvent.java +++ /dev/null @@ -1,64 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core.internal; - -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFMessage; - -public class SwitchEvent { - - public static enum SwitchEventType { - SWITCH_ADD, SWITCH_DELETE, SWITCH_ERROR, SWITCH_MESSAGE, - } - - private SwitchEventType eventType; - private ISwitch sw; - private OFMessage msg; - - public SwitchEvent(SwitchEventType type, ISwitch sw, OFMessage msg) { - this.eventType = type; - this.sw = sw; - this.msg = msg; - } - - public SwitchEventType getEventType() { - return this.eventType; - } - - public ISwitch getSwitch() { - return this.sw; - } - - public OFMessage getMsg() { - return this.msg; - } - - @Override - public String toString() { - String s; - switch (this.eventType) { - case SWITCH_ADD: - s = "SWITCH_ADD"; - break; - case SWITCH_DELETE: - s = "SWITCH_DELETE"; - break; - case SWITCH_ERROR: - s = "SWITCH_ERROR"; - break; - case SWITCH_MESSAGE: - s = "SWITCH_MESSAGE"; - break; - default: - s = "?" + this.eventType.ordinal() + "?"; - } - return "Switch Event: " + s; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java deleted file mode 100644 index 04c8dd4d80..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SynchronousMessage.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.core.internal; - -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; - -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFBarrierRequest; -import org.openflow.protocol.OFError; -import org.openflow.protocol.OFMessage; - -/** - * This class implements synchronous operations on message send to a switch. If - * syncRequest is set to true, it sends the requested message to the switch - * followed by a Barrier request message. It returns the result once it gets the - * reply from the switch or after a timeout. If the protocol does not dictate - * the switch to reply the processing status for a particular message, the - * Barrier request forces the switch to reply saying whether or not the message - * processing was successful for messages sent to the switch up to this point. - * If syncRequest is false, it simply skips the message send and just waits for - * the response back. - */ -public class SynchronousMessage implements Callable { - - - - - private ISwitch sw; - private Integer xid; - private OFMessage syncMsg; - protected CountDownLatch latch; - private Object result; - private boolean syncRequest; - - public SynchronousMessage(ISwitch sw, Integer xid, OFMessage msg, - boolean syncRequest) { - this.sw = sw; - this.xid = xid; - syncMsg = msg; - latch = new CountDownLatch(1); - result = null; - this.syncRequest = syncRequest; - } - - @Override - public Object call() throws Exception { - /* - * Send out message only if syncRequest is set to true. Otherwise, just - * wait for the Barrier response back. - */ - - if (syncRequest) { - sw.asyncSend(syncMsg, xid); - if (!(syncMsg instanceof OFBarrierRequest)) { - OFBarrierRequest barrierMsg = new OFBarrierRequest(); - sw.asyncSend(barrierMsg, xid); - } - } - latch.await(); - return result; - } - - public Integer getXid() { - return this.xid; - } - - public void wakeup() { - this.latch.countDown(); - } - - public void wakeup(OFError e) { - result = e; - wakeup(); - } - - -} \ No newline at end of file diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java deleted file mode 100644 index 0f6c6302e7..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Activator.java +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen; -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux; -import org.opendaylight.controller.protocol_plugin.openflow.IFlowProgrammerNotifier; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; -import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter; -import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsServiceShimListener; -import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.internal.EnhancedController; -import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.discovery.IDiscoveryService; -import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; -import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService; -import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; -import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; -import org.opendaylight.controller.sal.packet.IPluginInDataPacketService; -import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService; -import org.opendaylight.controller.sal.reader.IPluginInReadService; -import org.opendaylight.controller.sal.topology.IPluginInTopologyService; -import org.opendaylight.controller.sal.topology.IPluginOutTopologyService; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Openflow protocol plugin Activator - * - * - */ -public class Activator extends ComponentActivatorAbstractBase { - protected static final Logger logger = LoggerFactory - .getLogger(Activator.class); - - /** - * Function called when the activator starts just after some initializations - * are done by the ComponentActivatorAbstractBase. - * - */ - public void init() { - } - - /** - * Function called when the activator stops just before the cleanup done by - * ComponentActivatorAbstractBase - * - */ - public void destroy() { - } - - /** - * Function that is used to communicate to dependency manager the list of - * known implementations for services inside a container - * - * - * @return An array containing all the CLASS objects that will be - * instantiated in order to get an fully working implementation - * Object - */ - public Object[] getImplementations() { - Object[] res = { TopologyServices.class, DataPacketServices.class, - InventoryService.class, ReadService.class, - FlowProgrammerNotifier.class }; - return res; - } - - /** - * Function that is called when configuration of the dependencies is - * required. - * - * @param c - * dependency manager Component object, used for configuring the - * dependencies exported and imported - * @param imp - * Implementation class that is being configured, needed as long - * as the same routine can configure multiple implementations - * @param containerName - * The containerName being configured, this allow also optional - * per-container different behavior if needed, usually should not - * be the case though. - */ - public void configureInstance(Component c, Object imp, String containerName) { - if (imp.equals(TopologyServices.class)) { - // export the service to be used by SAL - c.setInterface( - new String[] { IPluginInTopologyService.class.getName(), - ITopologyServiceShimListener.class.getName() }, - null); - // Hook the services coming in from SAL, as optional in - // case SAL is not yet there, could happen - c.add(createContainerServiceDependency(containerName) - .setService(IPluginOutTopologyService.class) - .setCallbacks("setPluginOutTopologyService", - "unsetPluginOutTopologyService").setRequired(false)); - c.add(createServiceDependency() - .setService(IRefreshInternalProvider.class) - .setCallbacks("setRefreshInternalProvider", - "unsetRefreshInternalProvider").setRequired(false)); - } - - if (imp.equals(InventoryService.class)) { - // export the service - c.setInterface( - new String[] { IPluginInInventoryService.class.getName(), - IStatisticsListener.class.getName(), - IInventoryShimInternalListener.class.getName() }, - null); - - // Now lets add a service dependency to make sure the - // provider of service exists - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createContainerServiceDependency(containerName) - .setService(IPluginOutInventoryService.class) - .setCallbacks("setPluginOutInventoryServices", - "unsetPluginOutInventoryServices") - .setRequired(false)); - } - - if (imp.equals(DataPacketServices.class)) { - // export the service to be used by SAL - Dictionary props = new Hashtable(); - // Set the protocolPluginType property which will be used - // by SAL - props.put("protocolPluginType", Node.NodeIDType.OPENFLOW); - c.setInterface(IPluginInDataPacketService.class.getName(), props); - // Hook the services coming in from SAL, as optional in - // case SAL is not yet there, could happen - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - // This is required for the transmission to happen properly - c.add(createServiceDependency().setService(IDataPacketMux.class) - .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux") - .setRequired(true)); - c.add(createContainerServiceDependency(containerName) - .setService(IPluginOutDataPacketService.class) - .setCallbacks("setPluginOutDataPacketService", - "unsetPluginOutDataPacketService") - .setRequired(false)); - } - - if (imp.equals(ReadService.class)) { - // export the service to be used by SAL - Dictionary props = new Hashtable(); - // Set the protocolPluginType property which will be used - // by SAL - props.put("protocolPluginType", Node.NodeIDType.OPENFLOW); - c.setInterface(IPluginInReadService.class.getName(), props); - c.add(createServiceDependency() - .setService(IPluginReadServiceFilter.class) - .setCallbacks("setService", "unsetService") - .setRequired(true)); - } - - if (imp.equals(FlowProgrammerNotifier.class)) { - // export the service to be used by SAL - Dictionary props = new Hashtable(); - // Set the protocolPluginType property which will be used - // by SAL - props.put("protocolPluginType", Node.NodeIDType.OPENFLOW); - c.setInterface(IFlowProgrammerNotifier.class.getName(), props); - - c.add(createContainerServiceDependency(containerName) - .setService(IPluginOutFlowProgrammerService.class) - .setCallbacks("setPluginOutFlowProgrammerService", - "unsetPluginOutFlowProgrammerService") - .setRequired(true)); - } - } - - /** - * Function that is used to communicate to dependency manager the list of - * known implementations for services that are container independent. - * - * - * @return An array containing all the CLASS objects that will be - * instantiated in order to get an fully working implementation - * Object - */ - public Object[] getGlobalImplementations() { - Object[] res = { EnhancedController.class, OFStatisticsManager.class, - FlowProgrammerService.class, ReadServiceFilter.class, - DiscoveryService.class, DataPacketMuxDemux.class, - InventoryServiceShim.class, TopologyServiceShim.class }; - return res; - } - - /** - * Function that is called when configuration of the dependencies is - * required. - * - * @param c - * dependency manager Component object, used for configuring the - * dependencies exported and imported - * @param imp - * Implementation class that is being configured, needed as long - * as the same routine can configure multiple implementations - */ - public void configureGlobalInstance(Component c, Object imp) { - - if (imp.equals(EnhancedController.class)) { - logger.debug("Activator configureGlobalInstance( ) is called"); - Dictionary props = new Hashtable(); - props.put("name", "Controller"); - c.setInterface(IController.class.getName(), props); - } - - if (imp.equals(FlowProgrammerService.class)) { - // export the service to be used by SAL - Dictionary props = new Hashtable(); - // Set the protocolPluginType property which will be used - // by SAL - props.put("protocolPluginType", Node.NodeIDType.OPENFLOW); - c.setInterface( - new String[] { - IPluginInFlowProgrammerService.class.getName(), - IMessageListener.class.getName(), - IContainerListener.class.getName(), - IInventoryShimExternalListener.class.getName() }, - props); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - - c.add(createServiceDependency() - .setService(IFlowProgrammerNotifier.class) - .setCallbacks("setFlowProgrammerNotifier", - "unsetsetFlowProgrammerNotifier") - .setRequired(false)); - - } - - if (imp.equals(ReadServiceFilter.class)) { - - c.setInterface( - new String[] { IPluginReadServiceFilter.class.getName(), - IContainerListener.class.getName() }, null); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IOFStatisticsManager.class) - .setCallbacks("setService", "unsetService") - .setRequired(true)); - } - - if (imp.equals(OFStatisticsManager.class)) { - - c.setInterface(new String[] { IOFStatisticsManager.class.getName(), - IInventoryShimExternalListener.class.getName() }, null); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IStatisticsListener.class) - .setCallbacks("setStatisticsListener", - "unsetStatisticsListener").setRequired(false)); - } - - if (imp.equals(DiscoveryService.class)) { - // export the service - c.setInterface( - new String[] { - IInventoryShimExternalListener.class.getName(), - IDataPacketListen.class.getName(), - IContainerListener.class.getName() }, null); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createContainerServiceDependency( - GlobalConstants.DEFAULT.toString()) - .setService(IPluginInInventoryService.class) - .setCallbacks("setPluginInInventoryService", - "unsetPluginInInventoryService").setRequired(true)); - c.add(createServiceDependency().setService(IDataPacketMux.class) - .setCallbacks("setIDataPacketMux", "unsetIDataPacketMux") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IDiscoveryService.class) - .setCallbacks("setDiscoveryService", - "unsetDiscoveryService").setRequired(true)); - } - - // DataPacket mux/demux services, which is teh actual engine - // doing the packet switching - if (imp.equals(DataPacketMuxDemux.class)) { - c.setInterface(new String[] { IDataPacketMux.class.getName(), - IContainerListener.class.getName(), - IInventoryShimExternalListener.class.getName() }, null); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IPluginOutDataPacketService.class) - .setCallbacks("setPluginOutDataPacketService", - "unsetPluginOutDataPacketService") - .setRequired(false)); - // See if there is any local packet dispatcher - c.add(createServiceDependency() - .setService(IDataPacketListen.class) - .setCallbacks("setIDataPacketListen", - "unsetIDataPacketListen").setRequired(false)); - } - - if (imp.equals(InventoryServiceShim.class)) { - c.setInterface(new String[] { IContainerListener.class.getName() }, - null); - - c.add(createServiceDependency() - .setService(IController.class, "(name=Controller)") - .setCallbacks("setController", "unsetController") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IInventoryShimInternalListener.class) - .setCallbacks("setInventoryShimInternalListener", - "unsetInventoryShimInternalListener") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IInventoryShimExternalListener.class) - .setCallbacks("setInventoryShimExternalListener", - "unsetInventoryShimExternalListener") - .setRequired(false)); - } - - if (imp.equals(TopologyServiceShim.class)) { - c.setInterface(new String[] { IDiscoveryService.class.getName(), - IContainerListener.class.getName(), - IRefreshInternalProvider.class.getName(), - IInventoryShimExternalListener.class.getName() }, null); - c.add(createServiceDependency() - .setService(ITopologyServiceShimListener.class) - .setCallbacks("setTopologyServiceShimListener", - "unsetTopologyServiceShimListener") - .setRequired(true)); - c.add(createServiceDependency() - .setService(IOFStatisticsManager.class) - .setCallbacks("setStatisticsManager", - "unsetStatisticsManager").setRequired(false)); - } - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java deleted file mode 100644 index 280e925b41..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java +++ /dev/null @@ -1,410 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen; -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPacketIn; -import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFType; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.action.OFActionOutput; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService; -import org.opendaylight.controller.sal.packet.PacketResult; -import org.opendaylight.controller.sal.packet.RawPacket; -import org.opendaylight.controller.sal.utils.GlobalConstants; - -public class DataPacketMuxDemux implements IContainerListener, - IMessageListener, IDataPacketMux, IInventoryShimExternalListener { - protected static final Logger logger = LoggerFactory - .getLogger(DataPacketMuxDemux.class); - private IController controller = null; - private ConcurrentMap swID2ISwitch = new ConcurrentHashMap(); - // Gives a map between a Container and all the DataPacket listeners on SAL - private ConcurrentMap pluginOutDataPacketServices = new ConcurrentHashMap(); - // Gives a map between a NodeConnector and the containers to which it belongs - private ConcurrentMap> nc2Container = new ConcurrentHashMap>(); - // Gives a map between a Container and the FlowSpecs on it - private ConcurrentMap> container2FlowSpecs = new ConcurrentHashMap>(); - // Track local data packet listener - private List iDataPacketListen = new CopyOnWriteArrayList(); - - void setIDataPacketListen(IDataPacketListen s) { - if (this.iDataPacketListen != null) { - if (!this.iDataPacketListen.contains(s)) { - logger.debug("Added new IDataPacketListen"); - this.iDataPacketListen.add(s); - } - } - } - - void unsetIDataPacketListen(IDataPacketListen s) { - if (this.iDataPacketListen != null) { - if (this.iDataPacketListen.contains(s)) { - logger.debug("Removed IDataPacketListen"); - this.iDataPacketListen.remove(s); - } - } - } - - void setPluginOutDataPacketService(Map props, - IPluginOutDataPacketService s) { - if (props == null) { - logger.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("containerName not supplied"); - return; - } - if (this.pluginOutDataPacketServices != null) { - // It's expected only one SAL per container as long as the - // replication is done in the SAL implementation toward - // the different APPS - this.pluginOutDataPacketServices.put(containerName, s); - logger.debug("New outService for container: {}", containerName); - } - } - - void unsetPluginOutDataPacketService(Map props, - IPluginOutDataPacketService s) { - if (props == null) { - logger.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("containerName not supplied"); - return; - } - if (this.pluginOutDataPacketServices != null) { - this.pluginOutDataPacketServices.remove(containerName); - logger.debug("Removed outService for container: {}", containerName); - } - } - - void setController(IController s) { - logger.debug("Controller provider set in DATAPACKET SERVICES"); - this.controller = s; - } - - void unsetController(IController s) { - if (this.controller == s) { - logger.debug("Controller provider UNset in DATAPACKET SERVICES"); - this.controller = null; - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - this.controller.addMessageListener(OFType.PACKET_IN, this); - } - - /** - * Function called by the dependency manager when at least one - * dependency become unsatisfied or when the component is shutting - * down because for example bundle is being stopped. - * - */ - void destroy() { - this.controller.removeMessageListener(OFType.PACKET_IN, this); - - // Clear state that may need to be reused on component restart - this.pluginOutDataPacketServices.clear(); - this.nc2Container.clear(); - this.container2FlowSpecs.clear(); - this.controller = null; - this.swID2ISwitch.clear(); - } - - @Override - public void receive(ISwitch sw, OFMessage msg) { - if (sw == null || msg == null - || this.pluginOutDataPacketServices == null) { - // Something fishy, we cannot do anything - logger.debug("sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!", - new Object[]{sw, msg, this.pluginOutDataPacketServices}); - return; - } - if (msg instanceof OFPacketIn) { - OFPacketIn ofPacket = (OFPacketIn) msg; - Long ofSwitchID = Long.valueOf(sw.getId()); - Short ofPortID = Short.valueOf(ofPacket.getInPort()); - - try { - Node n = new Node(Node.NodeIDType.OPENFLOW, ofSwitchID); - NodeConnector p = PortConverter.toNodeConnector(ofPortID, n); - RawPacket dataPacket = new RawPacket(ofPacket.getPacketData()); - dataPacket.setIncomingNodeConnector(p); - - // Try to dispatch the packet locally, in here we will - // pass the parsed packet simply because once the - // packet infra is settled all the packets will passed - // around as parsed and read-only - for (int i = 0; i < this.iDataPacketListen.size(); i++) { - IDataPacketListen s = this.iDataPacketListen.get(i); - if (s.receiveDataPacket(dataPacket).equals( - PacketResult.CONSUME)) { - logger.trace("Consumed locally data packet"); - return; - } - } - - // Now dispatch the packet toward SAL at least for - // default container, we need to revisit this in a general - // slicing architecture refresh - IPluginOutDataPacketService defaultOutService = this.pluginOutDataPacketServices - .get(GlobalConstants.DEFAULT.toString()); - if (defaultOutService != null) { - defaultOutService.receiveDataPacket(dataPacket); - logger.trace("Dispatched to apps a frame of size: {} on container: {}", - ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString()); - } - // Now check the mapping between nodeConnector and - // Container and later on optinally filter based on - // flowSpec - /* - List containersRX = this.nc2Container.get(p); - if (containersRX != null) { - for (int i = 0; i < containersRX.size(); i++) { - String container = containersRX.get(i); - IPluginOutDataPacketService s = this.pluginOutDataPacketServices - .get(container); - if (s != null) { - // TODO add filtering on a per-flowSpec base - s.receiveDataPacket(dataPacket); - logger.trace("Dispatched to apps a frame of size: {} on container: {}", - ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString()); - - } - } - } - */ - - // This is supposed to be the catch all for all the - // DataPacket hence we will assume it has been handled - return; - } catch (ConstructionException cex) { - } - - // If we reach this point something went wrong. - return; - } else { - // We don't care about non-data packets - return; - } - } - - @Override - public void transmitDataPacket(RawPacket outPkt) { - // Sanity check area - if (outPkt == null) { - logger.debug("outPkt is null!"); - return; - } - - NodeConnector outPort = outPkt.getOutgoingNodeConnector(); - if (outPort == null) { - logger.debug("outPort is null! outPkt: {}", outPkt); - return; - } - - if (!outPort.getType().equals( - NodeConnector.NodeConnectorIDType.OPENFLOW)) { - // The output Port is not of type OpenFlow - logger.debug("outPort is not OF Type! outPort: {}", outPort); - return; - } - - Short port = (Short) outPort.getID(); - Long swID = (Long) outPort.getNode().getID(); - ISwitch sw = this.swID2ISwitch.get(swID); - - if (sw == null) { - // If we cannot get the controller descriptor we cannot even - // send out the frame - logger.debug("swID: {} - sw is null!", swID); - return; - } - - byte[] data = outPkt.getPacketData(); - // build action - OFActionOutput action = new OFActionOutput().setPort(port); - // build packet out - OFPacketOut po = new OFPacketOut().setBufferId( - OFPacketOut.BUFFER_ID_NONE).setInPort(OFPort.OFPP_NONE) - .setActions(Collections.singletonList((OFAction) action)) - .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH); - - po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLength() - + data.length); - po.setPacketData(data); - - sw.asyncSend(po); - logger.trace("Transmitted a frame of size: {}", data.length); - } - - public void addNode(Node node, Set props) { - if (node == null) { - logger.debug("node is null!"); - return; - } - - long sid = (Long) node.getID(); - ISwitch sw = controller.getSwitches().get(sid); - if (sw == null) { - logger.debug("sid: {} - sw is null!", sid); - return; - } - this.swID2ISwitch.put(sw.getId(), sw); - } - - public void removeNode(Node node) { - if (node == null) { - logger.debug("node is null!"); - return; - } - - long sid = (Long) node.getID(); - ISwitch sw = controller.getSwitches().get(sid); - if (sw == null) { - logger.debug("sid: {} - sw is null!", sid); - return; - } - this.swID2ISwitch.remove(sw.getId()); - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - // Do nothing - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - if (this.container2FlowSpecs == null) { - logger.error("container2FlowSpecs is NULL"); - return; - } - List fSpecs = this.container2FlowSpecs - .get(containerName); - if (fSpecs == null) { - fSpecs = new CopyOnWriteArrayList(); - } - switch (t) { - case ADDED: - if (!fSpecs.contains(previousFlow)) { - fSpecs.add(previousFlow); - } - break; - case REMOVED: - if (fSpecs.contains(previousFlow)) { - fSpecs.remove(previousFlow); - } - break; - case CHANGED: - break; - } - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType t) { - if (this.nc2Container == null) { - logger.error("nc2Container is NULL"); - return; - } - List containers = this.nc2Container.get(p); - if (containers == null) { - containers = new CopyOnWriteArrayList(); - } - boolean updateMap = false; - switch (t) { - case ADDED: - if (!containers.contains(containerName)) { - containers.add(containerName); - updateMap = true; - } - break; - case REMOVED: - if (containers.contains(containerName)) { - containers.remove(containerName); - updateMap = true; - } - break; - case CHANGED: - break; - } - if (updateMap) { - if (containers.isEmpty()) { - // Do cleanup to reduce memory footprint if no - // elements to be tracked - this.nc2Container.remove(p); - } else { - this.nc2Container.put(p, containers); - } - } - } - - @Override - public void containerModeUpdated(UpdateType t) { - // do nothing - } - - @Override - public void updateNode(Node node, UpdateType type, Set props) { - switch (type) { - case ADDED: - addNode(node, props); - break; - case REMOVED: - removeNode(node); - break; - default: - break; - } - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - // do nothing - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketServices.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketServices.java deleted file mode 100644 index adb9d20ef7..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketServices.java +++ /dev/null @@ -1,37 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.opendaylight.controller.sal.packet.IPluginInDataPacketService; -import org.opendaylight.controller.sal.packet.RawPacket; - -public class DataPacketServices implements IPluginInDataPacketService { - protected static final Logger logger = LoggerFactory - .getLogger(DataPacketServices.class); - private IDataPacketMux iDataPacketMux = null; - - void setIDataPacketMux(IDataPacketMux s) { - this.iDataPacketMux = s; - } - - void unsetIDataPacketMux(IDataPacketMux s) { - if (this.iDataPacketMux == s) { - this.iDataPacketMux = null; - } - } - - @Override - public void transmitDataPacket(RawPacket outPkt) { - this.iDataPacketMux.transmitDataPacket(outPkt); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java deleted file mode 100644 index 01221e1e5c..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DescStatisticsConverter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.List; - -import org.opendaylight.controller.sal.reader.NodeDescription; -import org.openflow.protocol.statistics.OFDescriptionStatistics; -import org.openflow.protocol.statistics.OFStatistics; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class for converting openflow description statistics into SAL - * NodeDescription object - * - * - * - */ -public class DescStatisticsConverter { - private static final Logger log = LoggerFactory - .getLogger(DescStatisticsConverter.class); - NodeDescription hwDesc; - OFDescriptionStatistics ofDesc; - - public DescStatisticsConverter(List statsList) { - this.hwDesc = null; - if( statsList != null && !statsList.isEmpty() ) { - this.ofDesc = (OFDescriptionStatistics) statsList.get(0); - } - } - - public NodeDescription getHwDescription() { - if (hwDesc == null && ofDesc != null) { - hwDesc = new NodeDescription(); - hwDesc.setManufacturer(ofDesc.getManufacturerDescription()); - hwDesc.setHardware(ofDesc.getHardwareDescription()); - hwDesc.setSoftware(ofDesc.getSoftwareDescription()); - hwDesc.setDescription(ofDesc.getDatapathDescription()); - hwDesc.setSerialNumber(ofDesc.getSerialNumber()); - } - log.trace("OFDescriptionStatistics: {}", ofDesc); - log.trace("NodeDescription: {}", hwDesc); - return hwDesc; - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java deleted file mode 100644 index 972d1c0f43..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java +++ /dev/null @@ -1,1518 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.LinkedBlockingQueue; - -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketListen; -import org.opendaylight.controller.protocol_plugin.openflow.IDataPacketMux; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFPhysicalPort; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.Config; -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.core.Edge; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.State; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.discovery.IDiscoveryService; -import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; -import org.opendaylight.controller.sal.packet.Ethernet; -import org.opendaylight.controller.sal.packet.LLDP; -import org.opendaylight.controller.sal.packet.LLDPTLV; -import org.opendaylight.controller.sal.packet.LinkEncap; -import org.opendaylight.controller.sal.packet.PacketResult; -import org.opendaylight.controller.sal.packet.RawPacket; -import org.opendaylight.controller.sal.utils.EtherTypes; -import org.opendaylight.controller.sal.utils.HexEncode; -import org.opendaylight.controller.sal.utils.NetUtils; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.opendaylight.controller.sal.utils.NodeCreator; - -/** - * The class describes neighbor discovery service for an OpenFlow network. - */ -public class DiscoveryService implements IInventoryShimExternalListener, - IDataPacketListen, IContainerListener, CommandProvider { - private static Logger logger = LoggerFactory - .getLogger(DiscoveryService.class); - private IController controller = null; - private IDiscoveryService discoveryService = null; - private IPluginInInventoryService pluginInInventoryService = null; - private IDataPacketMux iDataPacketMux = null; - - private List readyListHi = null; // newly added ports go into this list and will be served first - private List readyListLo = null; // come here after served at least once - private List waitingList = null; // staging area during quiet period - private ConcurrentMap pendingMap = null;// wait for response back - private ConcurrentMap edgeMap = null; // openflow edges keyed by head connector - private ConcurrentMap agingMap = null; // aging entries keyed by edge port - private ConcurrentMap prodMap = null; // production edges keyed by edge port - - private Timer discoveryTimer; // discovery timer - private DiscoveryTimerTask discoveryTimerTask; // timer task - private long discoveryTimerTick = 1L * 1000; // per tick in msec - private int discoveryTimerTickCount = 0; // main tick counter - private int discoveryBatchMaxPorts = 500; // max # of ports handled in one batch - private int discoveryBatchRestartTicks = getDiscoveryInterval(); // periodically restart batching process - private int discoveryBatchPausePeriod = 5; // pause for few secs - private int discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; // pause after this point - private int discoveryRetry = 2; // number of retry after initial timeout - private int discoveryTimeoutTicks = getDiscoveryTimeout(); // timeout in sec - private int discoveryAgeoutTicks = 120; // age out 2 min - private int discoveryConsistencyCheckMultiple = 2; // multiple of discoveryBatchRestartTicks - private int discoveryConsistencyCheckTickCount = discoveryBatchPauseTicks; // CC tick counter - private int discoveryConsistencyCheckCallingTimes = 0; // # of times CC gets called - private int discoveryConsistencyCheckCorrected = 0; // # of cases CC corrected - private boolean discoveryConsistencyCheckEnabled = true;// enable or disable CC - private boolean discoveryAgingEnabled = true; // enable or disable aging - private boolean discoverySpoofingEnabled = true; // enable or disable spoofing neighbor of a production network - - private BlockingQueue transmitQ; - private Thread transmitThread; - private Boolean throttling = false; // if true, no more batching. - private volatile Boolean shuttingDown = false; - - private LLDPTLV chassisIdTlv, portIdTlv, ttlTlv, customTlv; - - class DiscoveryTransmit implements Runnable { - private final BlockingQueue transmitQ; - - DiscoveryTransmit(BlockingQueue transmitQ) { - this.transmitQ = transmitQ; - } - - public void run() { - while (true) { - try { - NodeConnector nodeConnector = transmitQ.take(); - RawPacket outPkt = createDiscoveryPacket(nodeConnector); - sendDiscoveryPacket(nodeConnector, outPkt); - nodeConnector = null; - } catch (InterruptedException e1) { - logger - .warn("DiscoveryTransmit interupted", e1 - .getMessage()); - if (shuttingDown) - return; - } catch (Exception e2) { - logger.error("",e2); - } - } - } - } - - class DiscoveryTimerTask extends TimerTask { - public void run() { - checkTimeout(); - checkAging(); - doConsistencyCheck(); - doDiscovery(); - } - } - - private RawPacket createDiscoveryPacket(NodeConnector nodeConnector) { - String nodeId = HexEncode.longToHexString((Long) nodeConnector - .getNode().getID()); - - // Create LLDP ChassisID TLV - byte[] cidValue = LLDPTLV.createChassisIDTLVValue(nodeId); - chassisIdTlv.setType((byte) LLDPTLV.TLVType.ChassisID.getValue()) - .setLength((short) cidValue.length).setValue(cidValue); - - // Create LLDP PortID TLV - String portId = nodeConnector.getNodeConnectorIDString(); - byte[] pidValue = LLDPTLV.createPortIDTLVValue(portId); - portIdTlv.setType((byte) LLDPTLV.TLVType.PortID.getValue()) - .setLength((short) pidValue.length).setValue(pidValue); - - // Create LLDP Custom TLV - byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnector.toString()); - customTlv.setType((byte) LLDPTLV.TLVType.Custom.getValue()) - .setLength((short) customValue.length).setValue(customValue); - - // Create LLDP Custom Option list - List customList = new ArrayList(); - customList.add(customTlv); - - // Create discovery pkt - LLDP discoveryPkt = new LLDP(); - discoveryPkt.setChassisId(chassisIdTlv).setPortId(portIdTlv).setTtl( - ttlTlv).setOptionalTLVList(customList); - - RawPacket rawPkt = null; - try { - // Create ethernet pkt - byte[] sourceMac = getSouceMACFromNodeID(nodeId); - Ethernet ethPkt = new Ethernet(); - ethPkt.setSourceMACAddress(sourceMac).setDestinationMACAddress( - LLDP.LLDPMulticastMac).setEtherType( - EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt); - - byte[] data = ethPkt.serialize(); - rawPkt = new RawPacket(data); - rawPkt.setOutgoingNodeConnector(nodeConnector); - } catch (ConstructionException cex) { - logger.warn("RawPacket creation caught exception {}", cex - .getMessage()); - } catch (Exception e) { - logger.error("Failed to serialize the LLDP packet: " + e); - } - - return rawPkt; - } - - private void sendDiscoveryPacket(NodeConnector nodeConnector, - RawPacket outPkt) { - if (nodeConnector == null) { - logger.debug("Can not send discovery packet out since nodeConnector is null"); - return; - } - - if (outPkt == null) { - logger.debug("Can not send discovery packet out since outPkt is null"); - return; - } - - long sid = (Long) nodeConnector.getNode().getID(); - ISwitch sw = controller.getSwitches().get(sid); - - if (sw == null) { - logger.debug("Can not send discovery packet out since switch {} is null", sid); - return; - } - - if (!sw.isOperational()) { - logger.debug("Can not send discovery packet out since switch {} is not operational", sw); - return; - } - - if (this.iDataPacketMux == null) { - logger.debug("Can not send discovery packet out since DataPacket service is not available"); - return; - } - - logger.trace("Sending topology discovery pkt thru {}", nodeConnector); - this.iDataPacketMux.transmitDataPacket(outPkt); - } - - @Override - public PacketResult receiveDataPacket(RawPacket inPkt) { - if (inPkt == null) { - logger.debug("Ignoring null packet"); - return PacketResult.IGNORED; - } - - byte[] data = inPkt.getPacketData(); - if (data.length <= 0) { - logger.trace("Ignoring zero length packet"); - return PacketResult.IGNORED; - } - - if (!inPkt.getEncap().equals(LinkEncap.ETHERNET)) { - logger.trace("Ignoring non ethernet packet"); - return PacketResult.IGNORED; - } - - if (((Short) inPkt.getIncomingNodeConnector().getID()) - .equals(NodeConnector.SPECIALNODECONNECTORID)) { - logger.trace("Ignoring ethernet packet received on special port: " - + inPkt.getIncomingNodeConnector().toString()); - return PacketResult.IGNORED; - } - - Ethernet ethPkt = new Ethernet(); - try { - ethPkt.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte); - } catch (Exception e) { - logger.warn("Failed to decode LLDP packet from {}: {}", - inPkt.getIncomingNodeConnector(), e); - return PacketResult.IGNORED; - } - if (ethPkt.getPayload() instanceof LLDP) { - NodeConnector dst = inPkt.getIncomingNodeConnector(); - if (!processDiscoveryPacket(dst, ethPkt)) { - /* Spoof the discovery pkt if not generated from us */ - spoofDiscoveryPacket(dst, ethPkt); - } - return PacketResult.CONSUME; - } - return PacketResult.IGNORED; - } - - /* - * Spoof incoming discovery frames generated by the production network neighbor switch - */ - private void spoofDiscoveryPacket(NodeConnector dstNodeConnector, - Ethernet ethPkt) { - if (!this.discoverySpoofingEnabled) { - return; - } - - if ((dstNodeConnector == null) || (ethPkt == null)) { - logger.trace("Quit spoofing discovery packet: Null node connector or packet"); - return; - } - - LLDP lldp = (LLDP) ethPkt.getPayload(); - - try { - String nodeId = LLDPTLV.getHexStringValue(lldp.getChassisId().getValue(), lldp.getChassisId().getLength()); - String portId = LLDPTLV.getStringValue(lldp.getPortId().getValue(), lldp.getPortId().getLength()); - byte[] systemNameBytes = null; - // get system name if present in the LLDP pkt - for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) { - if (lldptlv.getType() == LLDPTLV.TLVType.SystemName.getValue()) { - systemNameBytes = lldptlv.getValue(); - break; - } - } - String nodeName = (systemNameBytes == null) ? nodeId : new String(systemNameBytes); - Node srcNode = new Node(Node.NodeIDType.PRODUCTION, nodeName); - NodeConnector srcNodeConnector = NodeConnectorCreator - .createNodeConnector(NodeConnector.NodeConnectorIDType.PRODUCTION, - portId, srcNode); - - Edge edge = null; - Set props = null; - edge = new Edge(srcNodeConnector, dstNodeConnector); - props = getProps(dstNodeConnector); - - updateProdEdge(edge, props); - } catch (Exception e) { - logger.warn("Caught exception ", e); - } - } - - /* - * Handle discovery frames generated by our controller - * @return true if it's a success - */ - private boolean processDiscoveryPacket(NodeConnector dstNodeConnector, - Ethernet ethPkt) { - if ((dstNodeConnector == null) || (ethPkt == null)) { - logger - .trace("Ignoring processing of discovery packet: Null node connector or packet"); - return false; - } - - logger.trace("Handle discovery packet {} from {}", ethPkt, - dstNodeConnector); - - LLDP lldp = (LLDP) ethPkt.getPayload(); - - List optionalTLVList = lldp.getOptionalTLVList(); - if (optionalTLVList == null) { - logger.info("The discovery packet with null custom option from {}", - dstNodeConnector); - return false; - } - - Node srcNode = null; - NodeConnector srcNodeConnector = null; - for (LLDPTLV lldptlv : lldp.getOptionalTLVList()) { - if (lldptlv.getType() == LLDPTLV.TLVType.Custom.getValue()) { - String ncString = LLDPTLV.getCustomString(lldptlv.getValue(), lldptlv.getLength()); - srcNodeConnector = NodeConnector.fromString(ncString); - if (srcNodeConnector != null) { - srcNode = srcNodeConnector.getNode(); - /* Check if it's expected */ - if (isTracked(srcNodeConnector)) { - break; - } else { - srcNode = null; - srcNodeConnector = null; - } - } - } - } - - if ((srcNode == null) || (srcNodeConnector == null)) { - logger - .trace( - "Received non-controller generated discovery packet from {}", - dstNodeConnector); - return false; - } - - // push it out to Topology - Edge edge = null; - Set props = null; - try { - edge = new Edge(srcNodeConnector, dstNodeConnector); - props = getProps(dstNodeConnector); - } catch (ConstructionException e) { - logger.error("Caught exception ", e); - } - addEdge(edge, props); - - logger.trace("Received discovery packet for Edge {}", edge); - - return true; - } - - public Map getPropMap(NodeConnector nodeConnector) { - if (nodeConnector == null) { - return null; - } - - if (pluginInInventoryService == null) { - return null; - } - - Map> props = pluginInInventoryService - .getNodeConnectorProps(false); - if (props == null) { - return null; - } - - return props.get(nodeConnector); - } - - public Property getProp(NodeConnector nodeConnector, String propName) { - Map propMap = getPropMap(nodeConnector); - if (propMap == null) { - return null; - } - - Property prop = (Property) propMap.get(propName); - return prop; - } - - public Set getProps(NodeConnector nodeConnector) { - Map propMap = getPropMap(nodeConnector); - if (propMap == null) { - return null; - } - - Set props = new HashSet(propMap.values()); - return props; - } - - private boolean isEnabled(NodeConnector nodeConnector) { - if (nodeConnector == null) { - return false; - } - - Config config = (Config) getProp(nodeConnector, Config.ConfigPropName); - State state = (State) getProp(nodeConnector, State.StatePropName); - return ((config != null) && (config.getValue() == Config.ADMIN_UP) - && (state != null) && (state.getValue() == State.EDGE_UP)); - } - - private boolean isTracked(NodeConnector nodeConnector) { - if (readyListHi.contains(nodeConnector)) { - return true; - } - - if (readyListLo.contains(nodeConnector)) { - return true; - } - - if (pendingMap.keySet().contains(nodeConnector)) { - return true; - } - - if (waitingList.contains(nodeConnector)) { - return true; - } - - return false; - } - - private Set getWorkingSet() { - Set workingSet = new HashSet(); - Set removeSet = new HashSet(); - - for (NodeConnector nodeConnector : readyListHi) { - if (isOverLimit(workingSet.size())) { - break; - } - - workingSet.add(nodeConnector); - removeSet.add(nodeConnector); - } - readyListHi.removeAll(removeSet); - - removeSet.clear(); - for (NodeConnector nodeConnector : readyListLo) { - if (isOverLimit(workingSet.size())) { - break; - } - - workingSet.add(nodeConnector); - removeSet.add(nodeConnector); - } - readyListLo.removeAll(removeSet); - - return workingSet; - } - - private Boolean isOverLimit(int size) { - return ((size >= discoveryBatchMaxPorts) && !throttling); - } - - private void addDiscovery() { - Map switches = controller.getSwitches(); - Set sidSet = switches.keySet(); - if (sidSet == null) { - return; - } - for (Long sid : sidSet) { - Node node = NodeCreator.createOFNode(sid); - addDiscovery(node); - } - } - - private void addDiscovery(Node node) { - Map switches = controller.getSwitches(); - ISwitch sw = switches.get((Long) node.getID()); - List ports = sw.getEnabledPorts(); - if (ports == null) { - return; - } - for (OFPhysicalPort port : ports) { - NodeConnector nodeConnector = NodeConnectorCreator - .createOFNodeConnector(port.getPortNumber(), node); - if (!readyListHi.contains(nodeConnector)) { - readyListHi.add(nodeConnector); - } - } - } - - private void addDiscovery(NodeConnector nodeConnector) { - if (isTracked(nodeConnector)) { - return; - } - - readyListHi.add(nodeConnector); - } - - private Set getRemoveSet(Collection c, - Node node) { - Set removeSet = new HashSet(); - if (c == null) { - return removeSet; - } - for (NodeConnector nodeConnector : c) { - if (node.equals(nodeConnector.getNode())) { - removeSet.add(nodeConnector); - } - } - return removeSet; - } - - private void removeDiscovery(Node node) { - Set removeSet; - - removeSet = getRemoveSet(readyListHi, node); - readyListHi.removeAll(removeSet); - - removeSet = getRemoveSet(readyListLo, node); - readyListLo.removeAll(removeSet); - - removeSet = getRemoveSet(waitingList, node); - waitingList.removeAll(removeSet); - - removeSet = getRemoveSet(pendingMap.keySet(), node); - for (NodeConnector nodeConnector : removeSet) { - pendingMap.remove(nodeConnector); - } - - removeSet = getRemoveSet(edgeMap.keySet(), node); - for (NodeConnector nodeConnector : removeSet) { - removeEdge(nodeConnector, false); - } - - removeSet = getRemoveSet(prodMap.keySet(), node); - for (NodeConnector nodeConnector : removeSet) { - removeProdEdge(nodeConnector); - } - } - - private void removeDiscovery(NodeConnector nodeConnector) { - readyListHi.remove(nodeConnector); - readyListLo.remove(nodeConnector); - waitingList.remove(nodeConnector); - pendingMap.remove(nodeConnector); - removeEdge(nodeConnector, false); - removeProdEdge(nodeConnector); - } - - private void checkTimeout() { - Set removeSet = new HashSet(); - Set retrySet = new HashSet(); - int sentCount; - - Set pendingSet = pendingMap.keySet(); - if (pendingSet != null) { - for (NodeConnector nodeConnector : pendingSet) { - sentCount = pendingMap.get(nodeConnector); - pendingMap.put(nodeConnector, ++sentCount); - if (sentCount > getDiscoveryFinalTimeoutInterval()) { - // timeout the edge - removeSet.add(nodeConnector); - logger.trace("Discovery timeout {}", nodeConnector); - } else if (sentCount % discoveryTimeoutTicks == 0) { - retrySet.add(nodeConnector); - } - } - } - - for (NodeConnector nodeConnector : removeSet) { - removeEdge(nodeConnector); - } - - for (NodeConnector nodeConnector : retrySet) { - transmitQ.add(nodeConnector); - } - } - - private void checkAging() { - if (!discoveryAgingEnabled) { - return; - } - - Set removeSet = new HashSet(); - int sentCount; - - Set agingSet = agingMap.keySet(); - if (agingSet != null) { - for (NodeConnector nodeConnector : agingSet) { - sentCount = agingMap.get(nodeConnector); - agingMap.put(nodeConnector, ++sentCount); - if (sentCount > discoveryAgeoutTicks) { - // age out the edge - removeSet.add(nodeConnector); - logger.trace("Discovery age out {}", nodeConnector); - } - } - } - - for (NodeConnector nodeConnector : removeSet) { - removeProdEdge(nodeConnector); - } - } - - private void doDiscovery() { - if (++discoveryTimerTickCount <= discoveryBatchPauseTicks) { - for (NodeConnector nodeConnector : getWorkingSet()) { - pendingMap.put(nodeConnector, 0); - transmitQ.add(nodeConnector); - } - } else if (discoveryTimerTickCount >= discoveryBatchRestartTicks) { - discoveryTimerTickCount = 0; - for (NodeConnector nodeConnector : waitingList) { - if (!readyListLo.contains(nodeConnector)) - readyListLo.add(nodeConnector); - } - waitingList.removeAll(readyListLo); - } - } - - private void doConsistencyCheck() { - if (!discoveryConsistencyCheckEnabled) { - return; - } - - if (++discoveryConsistencyCheckTickCount - % getDiscoveryConsistencyCheckInterval() != 0) { - return; - } - - discoveryConsistencyCheckCallingTimes++; - - Set removeSet = new HashSet(); - Set ncSet = edgeMap.keySet(); - if (ncSet == null) { - return; - } - for (NodeConnector nodeConnector : ncSet) { - if (!isEnabled(nodeConnector)) { - removeSet.add(nodeConnector); - discoveryConsistencyCheckCorrected++; - logger.debug("ConsistencyChecker: remove disabled {}", - nodeConnector); - continue; - } - - if (!isTracked(nodeConnector)) { - waitingList.add(nodeConnector); - discoveryConsistencyCheckCorrected++; - logger.debug("ConsistencyChecker: add back untracked {}", - nodeConnector); - continue; - } - } - - for (NodeConnector nodeConnector : removeSet) { - removeEdge(nodeConnector, false); - } - - // remove stale entries - removeSet.clear(); - for (NodeConnector nodeConnector : waitingList) { - if (!isEnabled(nodeConnector)) { - removeSet.add(nodeConnector); - discoveryConsistencyCheckCorrected++; - logger.debug("ConsistencyChecker: remove disabled {}", - nodeConnector); - } - } - waitingList.removeAll(removeSet); - - // Get a snapshot of all the existing switches - Map switches = this.controller.getSwitches(); - for (ISwitch sw : switches.values()) { - for (OFPhysicalPort port : sw.getEnabledPorts()) { - Node node = NodeCreator.createOFNode(sw.getId()); - NodeConnector nodeConnector = NodeConnectorCreator - .createOFNodeConnector(port.getPortNumber(), node); - if (!isTracked(nodeConnector)) { - waitingList.add(nodeConnector); - discoveryConsistencyCheckCorrected++; - logger.debug("ConsistencyChecker: add back untracked {}", - nodeConnector); - } - } - } - } - - private void addEdge(Edge edge, Set props) { - if (edge == null) { - return; - } - - NodeConnector src = edge.getTailNodeConnector(); - if (!src.getType().equals( - NodeConnector.NodeConnectorIDType.PRODUCTION)) { - pendingMap.remove(src); - if (!waitingList.contains(src)) { - waitingList.add(src); - } - } else { - NodeConnector dst = edge.getHeadNodeConnector(); - agingMap.put(dst, 0); - } - - // notify routeEngine - updateEdge(edge, UpdateType.ADDED, props); - logger.trace("Add edge {}", edge); - } - - - /** - * Update Production Edge - * - * @param edge The Production Edge - * @param props Properties associated with the edge - */ - private void updateProdEdge(Edge edge, Set props) { - NodeConnector edgePort = edge.getHeadNodeConnector(); - - /* Do not update in case there is an existing OpenFlow link */ - if (edgeMap.get(edgePort) != null) { - logger.trace("Discarded edge {} since there is an existing OF link {}", - edge, edgeMap.get(edgePort)); - return; - } - - /* Look for any existing Production Edge */ - Edge oldEdge = prodMap.get(edgePort); - if (oldEdge == null) { - /* Let's add a new one */ - addEdge(edge, props); - } else if (!edge.equals(oldEdge)) { - /* Remove the old one first */ - removeProdEdge(oldEdge.getHeadNodeConnector()); - /* Then add the new one */ - addEdge(edge, props); - } else { - /* o/w, just reset the aging timer */ - NodeConnector dst = edge.getHeadNodeConnector(); - agingMap.put(dst, 0); - } - } - - /** - * Remove Production Edge for a given edge port - * - * @param edgePort The OF edge port - */ - private void removeProdEdge(NodeConnector edgePort) { - agingMap.remove(edgePort); - - Edge edge = null; - Set prodKeySet = prodMap.keySet(); - if ((prodKeySet != null) && (prodKeySet.contains(edgePort))) { - edge = prodMap.get(edgePort); - prodMap.remove(edgePort); - } - - // notify Topology - if (this.discoveryService != null) { - this.discoveryService.notifyEdge(edge, UpdateType.REMOVED, null); - } - logger.trace("Remove edge {}", edge); - } - - /* - * Remove OpenFlow edge - */ - private void removeEdge(NodeConnector nodeConnector, boolean stillEnabled) { - pendingMap.remove(nodeConnector); - readyListLo.remove(nodeConnector); - readyListHi.remove(nodeConnector); - - if (stillEnabled) { - // keep discovering - if (!waitingList.contains(nodeConnector)) { - waitingList.add(nodeConnector); - } - } else { - // stop it - waitingList.remove(nodeConnector); - } - - Edge edge = null; - Set edgeKeySet = edgeMap.keySet(); - if ((edgeKeySet != null) && (edgeKeySet.contains(nodeConnector))) { - edge = edgeMap.get(nodeConnector); - edgeMap.remove(nodeConnector); - } - - // notify Topology - if (this.discoveryService != null) { - this.discoveryService.notifyEdge(edge, UpdateType.REMOVED, null); - } - logger.trace("Remove {}", nodeConnector); - } - - private void removeEdge(NodeConnector nodeConnector) { - removeEdge(nodeConnector, isEnabled(nodeConnector)); - } - - private void updateEdge(Edge edge, UpdateType type, Set props) { - if (discoveryService == null) { - return; - } - - this.discoveryService.notifyEdge(edge, type, props); - - NodeConnector src = edge.getTailNodeConnector(), dst = edge - .getHeadNodeConnector(); - if (!src.getType().equals( - NodeConnector.NodeConnectorIDType.PRODUCTION)) { - if (type == UpdateType.ADDED) { - edgeMap.put(src, edge); - } else { - edgeMap.remove(src); - } - } else { - /* - * Save Production edge into different DB keyed by the Edge port - */ - if (type == UpdateType.ADDED) { - prodMap.put(dst, edge); - } else { - prodMap.remove(dst); - } - } - } - - private void moreToReadyListHi(NodeConnector nodeConnector) { - if (readyListLo.contains(nodeConnector)) { - readyListLo.remove(nodeConnector); - readyListHi.add(nodeConnector); - } else if (waitingList.contains(nodeConnector)) { - waitingList.remove(nodeConnector); - readyListHi.add(nodeConnector); - } - } - - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, - null); - } - - private int getDiscoveryConsistencyCheckInterval() { - return discoveryConsistencyCheckMultiple * discoveryBatchRestartTicks; - } - - private int getDiscoveryFinalTimeoutInterval() { - return (discoveryRetry + 1) * discoveryTimeoutTicks; - } - - @Override - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("---Topology Discovery---\n"); - help.append("\t prlh - Print readyListHi entries\n"); - help.append("\t prll - Print readyListLo entries\n"); - help.append("\t pwl - Print waitingList entries\n"); - help.append("\t ppl - Print pendingList entries\n"); - help.append("\t ptick - Print tick time in msec\n"); - help.append("\t pcc - Print CC info\n"); - help.append("\t psize - Print sizes of all the lists\n"); - help.append("\t ptm - Print timeout info\n"); - help.append("\t ecc - Enable CC\n"); - help.append("\t dcc - Disable CC\n"); - help.append("\t scc [multiple] - Set/show CC multiple and interval\n"); - help.append("\t sports [ports] - Set/show max ports per batch\n"); - help.append("\t spause [ticks] - Set/show pause period\n"); - help.append("\t sdi [ticks] - Set/show discovery interval in ticks\n"); - help.append("\t stm [ticks] - Set/show per timeout ticks\n"); - help.append("\t sretry [count] - Set/show num of retries\n"); - help.append("\t addsw - Add a switch\n"); - help.append("\t remsw - Remove a switch\n"); - help.append("\t page - Print aging info\n"); - help.append("\t sage - Set/Show aging time limit\n"); - help.append("\t eage - Enable aging\n"); - help.append("\t dage - Disable aging\n"); - help.append("\t pthrot - Print throttling\n"); - help.append("\t ethrot - Enable throttling\n"); - help.append("\t dthrot - Disable throttling\n"); - return help.toString(); - } - - public void _prlh(CommandInterpreter ci) { - ci.println("ReadyListHi\n"); - for (NodeConnector nodeConnector : readyListHi) { - if (nodeConnector == null) { - continue; - } - ci.println(nodeConnector); - } - } - - public void _prll(CommandInterpreter ci) { - ci.println("ReadyListLo\n"); - for (NodeConnector nodeConnector : readyListLo) { - if (nodeConnector == null) { - continue; - } - ci.println(nodeConnector); - } - } - - public void _pwl(CommandInterpreter ci) { - ci.println("WaitingList\n"); - for (NodeConnector nodeConnector : waitingList) { - if (nodeConnector == null) { - continue; - } - ci.println(nodeConnector); - } - } - - public void _ppl(CommandInterpreter ci) { - ci.println("PendingList\n"); - for (NodeConnector nodeConnector : pendingMap.keySet()) { - if (nodeConnector == null) { - continue; - } - ci.println(nodeConnector); - } - } - - public void _ptick(CommandInterpreter ci) { - ci.println("Current timer is " + discoveryTimerTick + " msec per tick"); - } - - public void _pcc(CommandInterpreter ci) { - if (discoveryConsistencyCheckEnabled) { - ci.println("ConsistencyChecker is currently enabled"); - } else { - ci.println("ConsistencyChecker is currently disabled"); - } - ci.println("Interval " + getDiscoveryConsistencyCheckInterval()); - ci.println("Multiple " + discoveryConsistencyCheckMultiple); - ci.println("Number of times called " - + discoveryConsistencyCheckCallingTimes); - ci.println("Corrected count " + discoveryConsistencyCheckCorrected); - } - - public void _ptm(CommandInterpreter ci) { - ci.println("Final timeout ticks " + getDiscoveryFinalTimeoutInterval()); - ci.println("Per timeout ticks " + discoveryTimeoutTicks); - ci.println("Retry after initial timeout " + discoveryRetry); - } - - public void _psize(CommandInterpreter ci) { - ci.println("readyListLo size " + readyListLo.size() + "\n" - + "readyListHi size " + readyListHi.size() + "\n" - + "waitingList size " + waitingList.size() + "\n" - + "pendingMap size " + pendingMap.size() + "\n" - + "edgeMap size " + edgeMap.size() + "\n" + "prodMap size " - + prodMap.size() + "\n" + "agingMap size " + agingMap.size()); - } - - public void _page(CommandInterpreter ci) { - if (this.discoveryAgingEnabled) { - ci.println("Aging is enabled"); - } else { - ci.println("Aging is disabled"); - } - ci.println("Current aging time limit " + this.discoveryAgeoutTicks); - ci.println("\n"); - ci.println(" Edge Aging "); - Collection prodSet = prodMap.values(); - if (prodSet == null) { - return; - } - for (Edge edge : prodSet) { - Integer aging = agingMap.get(edge.getHeadNodeConnector()); - if (aging != null) { - ci.println(edge + " " + aging); - } - } - ci.println("\n"); - ci.println(" NodeConnector Edge "); - Set keySet = prodMap.keySet(); - if (keySet == null) { - return; - } - for (NodeConnector nc : keySet) { - ci.println(nc + " " + prodMap.get(nc)); - } - return; - } - - public void _sage(CommandInterpreter ci) { - String val = ci.nextArgument(); - if (val == null) { - ci.println("Please enter aging time limit. Current value " - + this.discoveryAgeoutTicks); - return; - } - try { - this.discoveryAgeoutTicks = Integer.parseInt(val); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _eage(CommandInterpreter ci) { - this.discoveryAgingEnabled = true; - ci.println("Aging is enabled"); - return; - } - - public void _dage(CommandInterpreter ci) { - this.discoveryAgingEnabled = false; - ci.println("Aging is disabled"); - return; - } - - public void _scc(CommandInterpreter ci) { - String val = ci.nextArgument(); - if (val == null) { - ci.println("Please enter CC multiple. Current multiple " - + discoveryConsistencyCheckMultiple + " (interval " - + getDiscoveryConsistencyCheckInterval() - + ") calling times " - + discoveryConsistencyCheckCallingTimes); - return; - } - try { - discoveryConsistencyCheckMultiple = Integer.parseInt(val); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _ecc(CommandInterpreter ci) { - this.discoveryConsistencyCheckEnabled = true; - ci.println("ConsistencyChecker is enabled"); - return; - } - - public void _dcc(CommandInterpreter ci) { - this.discoveryConsistencyCheckEnabled = false; - ci.println("ConsistencyChecker is disabled"); - return; - } - - public void _pspf(CommandInterpreter ci) { - if (this.discoverySpoofingEnabled) { - ci.println("Discovery spoofing is enabled"); - } else { - ci.println("Discovery spoofing is disabled"); - } - return; - } - - public void _espf(CommandInterpreter ci) { - this.discoverySpoofingEnabled = true; - ci.println("Discovery spoofing is enabled"); - return; - } - - public void _dspf(CommandInterpreter ci) { - this.discoverySpoofingEnabled = false; - ci.println("Discovery spoofing is disabled"); - return; - } - - public void _spause(CommandInterpreter ci) { - String val = ci.nextArgument(); - String out = "Please enter pause period less than " - + discoveryBatchRestartTicks + ". Current pause period is " - + discoveryBatchPausePeriod + " pause tick is " - + discoveryBatchPauseTicks + "."; - - if (val != null) { - try { - int pause = Integer.parseInt(val); - if (pause < discoveryBatchRestartTicks) { - discoveryBatchPausePeriod = pause; - discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; - return; - } - } catch (Exception e) { - } - } - - ci.println(out); - } - - public void _sdi(CommandInterpreter ci) { - String val = ci.nextArgument(); - String out = "Please enter discovery interval greater than " - + discoveryBatchPausePeriod + ". Current value is " - + discoveryBatchRestartTicks + "."; - - if (val != null) { - try { - int restart = Integer.parseInt(val); - if (restart > discoveryBatchPausePeriod) { - discoveryBatchRestartTicks = restart; - discoveryBatchPauseTicks = discoveryBatchRestartTicks - discoveryBatchPausePeriod; - return; - } - } catch (Exception e) { - } - } - ci.println(out); - } - - public void _sports(CommandInterpreter ci) { - String val = ci.nextArgument(); - if (val == null) { - ci.println("Please enter max ports per batch. Current value is " - + discoveryBatchMaxPorts); - return; - } - try { - discoveryBatchMaxPorts = Integer.parseInt(val); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _sretry(CommandInterpreter ci) { - String val = ci.nextArgument(); - if (val == null) { - ci.println("Please enter number of retries. Current value is " - + discoveryRetry); - return; - } - try { - discoveryRetry = Integer.parseInt(val); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _stm(CommandInterpreter ci) { - String val = ci.nextArgument(); - String out = "Please enter timeout tick value less than " - + discoveryBatchRestartTicks + ". Current value is " - + discoveryTimeoutTicks; - if (val != null) { - try { - int timeout = Integer.parseInt(val); - if (timeout < discoveryBatchRestartTicks) { - discoveryTimeoutTicks = timeout; - return; - } - } catch (Exception e) { - } - } - - ci.println(out); - } - - public void _addsw(CommandInterpreter ci) { - String val = ci.nextArgument(); - Long sid; - try { - sid = Long.parseLong(val); - Node node = NodeCreator.createOFNode(sid); - addDiscovery(node); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _remsw(CommandInterpreter ci) { - String val = ci.nextArgument(); - Long sid; - try { - sid = Long.parseLong(val); - Node node = NodeCreator.createOFNode(sid); - removeDiscovery(node); - } catch (Exception e) { - ci.println("Please enter a valid number"); - } - return; - } - - public void _pthrot(CommandInterpreter ci) { - if (this.throttling) { - ci.println("Throttling is enabled"); - } else { - ci.println("Throttling is disabled"); - } - } - - public void _ethrot(CommandInterpreter ci) { - this.throttling = true; - ci.println("Throttling is enabled"); - return; - } - - public void _dthrot(CommandInterpreter ci) { - this.throttling = false; - ci.println("Throttling is disabled"); - return; - } - - @Override - public void updateNode(Node node, UpdateType type, Set props) { - switch (type) { - case ADDED: - addNode(node, props); - break; - case REMOVED: - removeNode(node); - break; - default: - break; - } - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - Config config = null; - State state = null; - boolean enabled = false; - - for (Property prop : props) { - if (prop.getName().equals(Config.ConfigPropName)) { - config = (Config) prop; - } else if (prop.getName().equals(State.StatePropName)) { - state = (State) prop; - } - } - enabled = ((config != null) && (config.getValue() == Config.ADMIN_UP) - && (state != null) && (state.getValue() == State.EDGE_UP)); - - switch (type) { - case ADDED: - if (enabled) { - addDiscovery(nodeConnector); - logger.trace("ADDED enabled {}", nodeConnector); - } else { - logger.trace("ADDED disabled {}", nodeConnector); - } - break; - case CHANGED: - if (enabled) { - addDiscovery(nodeConnector); - logger.trace("CHANGED enabled {}", nodeConnector); - } else { - removeDiscovery(nodeConnector); - logger.trace("CHANGED disabled {}", nodeConnector); - } - break; - case REMOVED: - removeDiscovery(nodeConnector); - logger.trace("REMOVED enabled {}", nodeConnector); - break; - default: - return; - } - } - - public void addNode(Node node, Set props) { - if (node == null) - return; - - addDiscovery(node); - } - - public void removeNode(Node node) { - if (node == null) - return; - - removeDiscovery(node); - } - - public void updateNode(Node node, Set props) { - } - - void setController(IController s) { - this.controller = s; - } - - void unsetController(IController s) { - if (this.controller == s) { - this.controller = null; - } - } - - public void setPluginInInventoryService(IPluginInInventoryService service) { - this.pluginInInventoryService = service; - } - - public void unsetPluginInInventoryService(IPluginInInventoryService service) { - this.pluginInInventoryService = null; - } - - public void setIDataPacketMux(IDataPacketMux service) { - this.iDataPacketMux = service; - } - - public void unsetIDataPacketMux(IDataPacketMux service) { - if (this.iDataPacketMux == service) { - this.iDataPacketMux = null; - } - } - - void setDiscoveryService(IDiscoveryService s) { - this.discoveryService = s; - } - - void unsetDiscoveryService(IDiscoveryService s) { - if (this.discoveryService == s) { - this.discoveryService = null; - } - } - - private void initDiscoveryPacket() { - // Create LLDP ChassisID TLV - chassisIdTlv = new LLDPTLV(); - chassisIdTlv.setType((byte) LLDPTLV.TLVType.ChassisID.getValue()); - - // Create LLDP PortID TLV - portIdTlv = new LLDPTLV(); - portIdTlv.setType((byte) LLDPTLV.TLVType.PortID.getValue()); - - // Create LLDP TTL TLV - byte[] ttl = new byte[] {(byte) 0, (byte) 120 }; - ttlTlv = new LLDPTLV(); - ttlTlv.setType((byte) LLDPTLV.TLVType.TTL.getValue()).setLength( - (short) ttl.length).setValue(ttl); - - customTlv = new LLDPTLV(); - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - logger.trace("Init called"); - - transmitQ = new LinkedBlockingQueue(); - - readyListHi = new CopyOnWriteArrayList(); - readyListLo = new CopyOnWriteArrayList(); - waitingList = new CopyOnWriteArrayList(); - pendingMap = new ConcurrentHashMap(); - edgeMap = new ConcurrentHashMap(); - agingMap = new ConcurrentHashMap(); - prodMap = new ConcurrentHashMap(); - - discoveryTimer = new Timer("DiscoveryService"); - discoveryTimerTask = new DiscoveryTimerTask(); - - transmitThread = new Thread(new DiscoveryTransmit(transmitQ)); - - initDiscoveryPacket(); - - registerWithOSGIConsole(); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - transmitQ = null; - readyListHi = null; - readyListLo = null; - waitingList = null; - pendingMap = null; - edgeMap = null; - agingMap = null; - prodMap = null; - discoveryTimer = null; - discoveryTimerTask = null; - transmitThread = null; - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - discoveryTimer.schedule(discoveryTimerTask, discoveryTimerTick, - discoveryTimerTick); - transmitThread.start(); - } - - /** - * Function called after registering the - * service in OSGi service registry. - */ - void started() { - /* get a snapshot of all the existing switches */ - addDiscovery(); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - shuttingDown = true; - discoveryTimer.cancel(); - transmitThread.interrupt(); - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType t) { - switch (t) { - case ADDED: - moreToReadyListHi(p); - break; - default: - break; - } - } - - @Override - public void containerModeUpdated(UpdateType t) { - // do nothing - } - - private byte[] getSouceMACFromNodeID(String nodeId) { - byte[] cid = HexEncode.bytesFromHexString(nodeId); - byte[] sourceMac = new byte[6]; - int pos = cid.length - sourceMac.length; - - if (pos >= 0) { - System.arraycopy(cid, pos, sourceMac, 0, sourceMac.length); - } - - return sourceMac; - } - - /** - * This method returns the interval which determines how often the discovery - * packets will be sent. Default is 300 seconds. - * - * @return The discovery interval in second - */ - private static int getDiscoveryInterval() { - String elapsedTime = System.getProperty("of.discoveryInterval"); - int rv = 300; - - try { - if (elapsedTime != null) { - rv = Integer.parseInt(elapsedTime); - } - } catch (Exception e) { - } - - return rv; - } - - /** - * This method returns the timeout value in waiting for response of a - * discovery query. Default is 60 seconds. - * - * @return The discovery timeout in second - */ - private static int getDiscoveryTimeout() { - String elapsedTime = System.getProperty("of.discoveryTimeout"); - int rv = 60; - - try { - if (elapsedTime != null) { - rv = Integer.parseInt(elapsedTime); - } - } catch (Exception e) { - } - - return rv; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/EnhancedActivator.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/EnhancedActivator.java new file mode 100644 index 0000000000..b81052212a --- /dev/null +++ b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/EnhancedActivator.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; + +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; + +import org.apache.felix.dm.Component; +import org.opendaylight.controller.protocol_plugin.openflow.core.internal.EnhancedController; +import org.opendaylight.controller.protocol_plugin.openflow.core.internal.Controller; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Openflow protocol plugin Activator + * + * + */ +public class EnhancedActivator extends Activator { + protected static final Logger logger = LoggerFactory + .getLogger(EnhancedActivator.class); + + // Default Constructor for the activator + public EnhancedActivator() { + super(); + logger.debug("Enhanced activator called!"); + } + + /** + * Function that is used to communicate to dependency manager the list of + * known implementations for services that are container independent. + * + * + * @return An array containing all the CLASS objects that will be + * instantiated in order to get an fully working implementation + * Object + */ + @Override + public Object[] getGlobalImplementations() { + Object[] res = super.getGlobalImplementations(); + // Now remove the Controller.class and return the + // EnhancedController + List resList = new ArrayList(Arrays.asList(res)); + resList.remove(Controller.class); + resList.add(EnhancedController.class); + return resList.toArray(); + } + + /** + * Function that is called when configuration of the dependencies is + * required. + * + * @param c + * dependency manager Component object, used for configuring the + * dependencies exported and imported + * @param imp + * Implementation class that is being configured, needed as long + * as the same routine can configure multiple implementations + */ + @Override + public void configureGlobalInstance(Component c, Object imp) { + if (imp.equals(EnhancedController.class)) { + // Configure it like if was the Controller.class + super.configureGlobalInstance(c, Controller.class); + } else { + super.configureGlobalInstance(c, imp); + } + } +} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java deleted file mode 100644 index 7af9ff3dec..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java +++ /dev/null @@ -1,734 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.math.BigInteger; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; - - -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6FlowMod; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; -import org.opendaylight.controller.sal.action.Action; -import org.opendaylight.controller.sal.action.ActionType; -import org.opendaylight.controller.sal.action.Controller; -import org.opendaylight.controller.sal.action.Drop; -import org.opendaylight.controller.sal.action.Flood; -import org.opendaylight.controller.sal.action.FloodAll; -import org.opendaylight.controller.sal.action.HwPath; -import org.opendaylight.controller.sal.action.Loopback; -import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.action.PopVlan; -import org.opendaylight.controller.sal.action.SetDlDst; -import org.opendaylight.controller.sal.action.SetDlSrc; -import org.opendaylight.controller.sal.action.SetNwDst; -import org.opendaylight.controller.sal.action.SetNwSrc; -import org.opendaylight.controller.sal.action.SetNwTos; -import org.opendaylight.controller.sal.action.SetTpDst; -import org.opendaylight.controller.sal.action.SetTpSrc; -import org.opendaylight.controller.sal.action.SetVlanId; -import org.opendaylight.controller.sal.action.SetVlanPcp; -import org.opendaylight.controller.sal.action.SwPath; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.match.Match; -import org.opendaylight.controller.sal.match.MatchField; -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.NetUtils; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.openflow.protocol.OFFlowMod; -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFVendor; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.action.OFActionDataLayerDestination; -import org.openflow.protocol.action.OFActionDataLayerSource; -import org.openflow.protocol.action.OFActionNetworkLayerAddress; -import org.openflow.protocol.action.OFActionNetworkLayerDestination; -import org.openflow.protocol.action.OFActionNetworkLayerSource; -import org.openflow.protocol.action.OFActionNetworkTypeOfService; -import org.openflow.protocol.action.OFActionOutput; -import org.openflow.protocol.action.OFActionStripVirtualLan; -import org.openflow.protocol.action.OFActionTransportLayer; -import org.openflow.protocol.action.OFActionTransportLayerDestination; -import org.openflow.protocol.action.OFActionTransportLayerSource; -import org.openflow.protocol.action.OFActionVirtualLanIdentifier; -import org.openflow.protocol.action.OFActionVirtualLanPriorityCodePoint; -import org.openflow.util.U16; -import org.openflow.util.U32; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class for converting a SAL Flow into the OF flow and vice-versa - */ -public class FlowConverter { - protected static final Logger logger = LoggerFactory - .getLogger(FlowConverter.class); - private Flow flow; // SAL Flow - private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match - private List actionsList; // OF 1.0 actions - private int actionsLength; - private boolean isIPv6; - - public FlowConverter(OFMatch ofMatch, List actionsList) { - this.ofMatch = ofMatch; - this.actionsList = actionsList; - this.actionsLength = 0; - this.flow = null; - this.isIPv6 = ofMatch instanceof V6Match; - } - - public FlowConverter(Flow flow) { - this.ofMatch = null; - this.actionsList = null; - this.actionsLength = 0; - this.flow = flow; - this.isIPv6 = flow.isIPv6(); - } - - /** - * Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions - * form (V6Match) - * - * @return - */ - public OFMatch getOFMatch() { - if (ofMatch == null) { - Match match = flow.getMatch(); - ofMatch = (isIPv6) ? new V6Match() : new OFMatch(); - - int wildcards = OFMatch.OFPFW_ALL; - if (match.isPresent(MatchType.IN_PORT)) { - short port = (Short) ((NodeConnector) match.getField( - MatchType.IN_PORT).getValue()).getID(); - if (!isIPv6) { - ofMatch.setInputPort(port); - wildcards &= ~OFMatch.OFPFW_IN_PORT; - } else { - ((V6Match) ofMatch).setInputPort(port, (short) 0); - } - } - if (match.isPresent(MatchType.DL_SRC)) { - byte[] srcMac = (byte[]) match.getField(MatchType.DL_SRC) - .getValue(); - if (!isIPv6) { - ofMatch.setDataLayerSource(srcMac.clone()); - wildcards &= ~OFMatch.OFPFW_DL_SRC; - } else { - ((V6Match) ofMatch).setDataLayerSource(srcMac, null); - } - } - if (match.isPresent(MatchType.DL_DST)) { - byte[] dstMac = (byte[]) match.getField(MatchType.DL_DST) - .getValue(); - if (!isIPv6) { - ofMatch.setDataLayerDestination(dstMac.clone()); - wildcards &= ~OFMatch.OFPFW_DL_DST; - } else { - ((V6Match) ofMatch).setDataLayerDestination(dstMac, null); - } - } - if (match.isPresent(MatchType.DL_VLAN)) { - short vlan = (Short) match.getField(MatchType.DL_VLAN) - .getValue(); - if (!isIPv6) { - ofMatch.setDataLayerVirtualLan(vlan); - wildcards &= ~OFMatch.OFPFW_DL_VLAN; - } else { - ((V6Match) ofMatch).setDataLayerVirtualLan(vlan, (short) 0); - } - } - if (match.isPresent(MatchType.DL_VLAN_PR)) { - byte vlanPr = (Byte) match.getField(MatchType.DL_VLAN_PR) - .getValue(); - if (!isIPv6) { - ofMatch.setDataLayerVirtualLanPriorityCodePoint(vlanPr); - wildcards &= ~OFMatch.OFPFW_DL_VLAN_PCP; - } else { - ((V6Match) ofMatch) - .setDataLayerVirtualLanPriorityCodePoint(vlanPr, - (byte) 0); - } - } - if (match.isPresent(MatchType.DL_TYPE)) { - short ethType = (Short) match.getField(MatchType.DL_TYPE) - .getValue(); - if (!isIPv6) { - ofMatch.setDataLayerType(ethType); - wildcards &= ~OFMatch.OFPFW_DL_TYPE; - } else { - ((V6Match) ofMatch).setDataLayerType(ethType, (short) 0); - } - } - if (match.isPresent(MatchType.NW_TOS)) { - /* - * OF 1.0 switch expects the TOS as the 6 msb in the byte. it is - * actually the DSCP field followed by a zero ECN - */ - byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue(); - byte dscp = (byte) ((int) tos << 2); - if (!isIPv6) { - ofMatch.setNetworkTypeOfService(dscp); - wildcards &= ~OFMatch.OFPFW_NW_TOS; - } else { - ((V6Match) ofMatch).setNetworkTypeOfService(dscp, (byte) 0); - } - } - if (match.isPresent(MatchType.NW_PROTO)) { - byte proto = (Byte) match.getField(MatchType.NW_PROTO) - .getValue(); - if (!isIPv6) { - ofMatch.setNetworkProtocol(proto); - wildcards &= ~OFMatch.OFPFW_NW_PROTO; - } else { - ((V6Match) ofMatch).setNetworkProtocol(proto, (byte) 0); - } - } - if (match.isPresent(MatchType.NW_SRC)) { - InetAddress address = (InetAddress) match.getField( - MatchType.NW_SRC).getValue(); - InetAddress mask = (InetAddress) match.getField( - MatchType.NW_SRC).getMask(); - if (!isIPv6) { - ofMatch.setNetworkSource(NetUtils.byteArray4ToInt(address - .getAddress())); - int maskLength = NetUtils - .getSubnetMaskLength((mask == null) ? null : mask - .getAddress()); - wildcards = (wildcards & ~OFMatch.OFPFW_NW_SRC_MASK) - | (maskLength << OFMatch.OFPFW_NW_SRC_SHIFT); - } else { - ((V6Match) ofMatch).setNetworkSource(address, mask); - } - } - if (match.isPresent(MatchType.NW_DST)) { - InetAddress address = (InetAddress) match.getField( - MatchType.NW_DST).getValue(); - InetAddress mask = (InetAddress) match.getField( - MatchType.NW_DST).getMask(); - if (!isIPv6) { - ofMatch.setNetworkDestination(NetUtils - .byteArray4ToInt(address.getAddress())); - int maskLength = NetUtils - .getSubnetMaskLength((mask == null) ? null : mask - .getAddress()); - wildcards = (wildcards & ~OFMatch.OFPFW_NW_DST_MASK) - | (maskLength << OFMatch.OFPFW_NW_DST_SHIFT); - } else { - ((V6Match) ofMatch).setNetworkDestination(address, mask); - } - } - if (match.isPresent(MatchType.TP_SRC)) { - short port = (Short) match.getField(MatchType.TP_SRC) - .getValue(); - if (!isIPv6) { - ofMatch.setTransportSource(port); - wildcards &= ~OFMatch.OFPFW_TP_SRC; - } else { - ((V6Match) ofMatch).setTransportSource(port, (short) 0); - } - } - if (match.isPresent(MatchType.TP_DST)) { - short port = (Short) match.getField(MatchType.TP_DST) - .getValue(); - if (!isIPv6) { - ofMatch.setTransportDestination(port); - wildcards &= ~OFMatch.OFPFW_TP_DST; - } else { - ((V6Match) ofMatch) - .setTransportDestination(port, (short) 0); - } - } - - if (!isIPv6) { - ofMatch.setWildcards(U32.t(Long.valueOf(wildcards))); - } - } - logger.trace("SAL Match: {} Openflow Match: {}", flow.getMatch(), - ofMatch); - return ofMatch; - } - - /** - * Returns the list of actions in OF 1.0 form - * - * @return - */ - public List getOFActions() { - if (this.actionsList == null) { - actionsList = new ArrayList(); - for (Action action : flow.getActions()) { - if (action.getType() == ActionType.OUTPUT) { - Output a = (Output) action; - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setMaxLength((short) 0xffff); - ofAction.setPort(PortConverter.toOFPort(a.getPort())); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.DROP) { - continue; - } - if (action.getType() == ActionType.LOOPBACK) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_IN_PORT.getValue()); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.FLOOD) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_FLOOD.getValue()); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.FLOOD_ALL) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_ALL.getValue()); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.CONTROLLER) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_CONTROLLER.getValue()); - // We want the whole frame hitting the match be sent to the - // controller - ofAction.setMaxLength((short) 0xffff); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SW_PATH) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_LOCAL.getValue()); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.HW_PATH) { - OFActionOutput ofAction = new OFActionOutput(); - ofAction.setPort(OFPort.OFPP_NORMAL.getValue()); - actionsList.add(ofAction); - actionsLength += OFActionOutput.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_VLAN_ID) { - SetVlanId a = (SetVlanId) action; - OFActionVirtualLanIdentifier ofAction = new OFActionVirtualLanIdentifier(); - ofAction.setVirtualLanIdentifier((short) a.getVlanId()); - actionsList.add(ofAction); - actionsLength += OFActionVirtualLanIdentifier.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_VLAN_PCP) { - SetVlanPcp a = (SetVlanPcp) action; - OFActionVirtualLanPriorityCodePoint ofAction = new OFActionVirtualLanPriorityCodePoint(); - ofAction.setVirtualLanPriorityCodePoint(Integer.valueOf( - a.getPcp()).byteValue()); - actionsList.add(ofAction); - actionsLength += OFActionVirtualLanPriorityCodePoint.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.POP_VLAN) { - OFActionStripVirtualLan ofAction = new OFActionStripVirtualLan(); - actionsList.add(ofAction); - actionsLength += OFActionStripVirtualLan.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_DL_SRC) { - SetDlSrc a = (SetDlSrc) action; - OFActionDataLayerSource ofAction = new OFActionDataLayerSource(); - ofAction.setDataLayerAddress(a.getDlAddress()); - actionsList.add(ofAction); - actionsLength += OFActionDataLayerSource.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_DL_DST) { - SetDlDst a = (SetDlDst) action; - OFActionDataLayerDestination ofAction = new OFActionDataLayerDestination(); - ofAction.setDataLayerAddress(a.getDlAddress()); - actionsList.add(ofAction); - actionsLength += OFActionDataLayerDestination.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_NW_SRC) { - SetNwSrc a = (SetNwSrc) action; - OFActionNetworkLayerSource ofAction = new OFActionNetworkLayerSource(); - ofAction.setNetworkAddress(NetUtils.byteArray4ToInt(a - .getAddress().getAddress())); - actionsList.add(ofAction); - actionsLength += OFActionNetworkLayerAddress.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_NW_DST) { - SetNwDst a = (SetNwDst) action; - OFActionNetworkLayerDestination ofAction = new OFActionNetworkLayerDestination(); - ofAction.setNetworkAddress(NetUtils.byteArray4ToInt(a - .getAddress().getAddress())); - actionsList.add(ofAction); - actionsLength += OFActionNetworkLayerAddress.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_NW_TOS) { - SetNwTos a = (SetNwTos) action; - OFActionNetworkTypeOfService ofAction = new OFActionNetworkTypeOfService(); - ofAction.setNetworkTypeOfService(Integer.valueOf( - a.getNwTos()).byteValue()); - actionsList.add(ofAction); - actionsLength += OFActionNetworkTypeOfService.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_TP_SRC) { - SetTpSrc a = (SetTpSrc) action; - OFActionTransportLayerSource ofAction = new OFActionTransportLayerSource(); - ofAction.setTransportPort(Integer.valueOf(a.getPort()) - .shortValue()); - actionsList.add(ofAction); - actionsLength += OFActionTransportLayer.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_TP_DST) { - SetTpDst a = (SetTpDst) action; - OFActionTransportLayerDestination ofAction = new OFActionTransportLayerDestination(); - ofAction.setTransportPort(Integer.valueOf(a.getPort()) - .shortValue()); - actionsList.add(ofAction); - actionsLength += OFActionTransportLayer.MINIMUM_LENGTH; - continue; - } - if (action.getType() == ActionType.SET_NEXT_HOP) { - // TODO - continue; - } - } - } - logger.trace("SAL Actions: {} Openflow Actions: {}", flow.getActions(), - actionsList); - return actionsList; - } - - /** - * Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or to an OF 1.0 + - * IPv6 extension (V6FlowMod) Flow modifier Message - * - * @param sw - * @param command - * @param port - * @return - */ - public OFMessage getOFFlowMod(short command, OFPort port) { - OFMessage fm = (isIPv6) ? new V6FlowMod() : new OFFlowMod(); - if (this.ofMatch == null) { - getOFMatch(); - } - if (this.actionsList == null) { - getOFActions(); - } - if (!isIPv6) { - ((OFFlowMod) fm).setMatch(this.ofMatch); - ((OFFlowMod) fm).setActions(this.actionsList); - ((OFFlowMod) fm).setPriority(flow.getPriority()); - ((OFFlowMod) fm).setCookie(flow.getId()); - ((OFFlowMod) fm).setBufferId(OFPacketOut.BUFFER_ID_NONE); - ((OFFlowMod) fm).setLength(U16.t(OFFlowMod.MINIMUM_LENGTH - + actionsLength)); - ((OFFlowMod) fm).setIdleTimeout(flow.getIdleTimeout()); - ((OFFlowMod) fm).setHardTimeout(flow.getHardTimeout()); - ((OFFlowMod) fm).setCommand(command); - if (port != null) { - ((OFFlowMod) fm).setOutPort(port); - } - if (command == OFFlowMod.OFPFC_ADD - || command == OFFlowMod.OFPFC_MODIFY - || command == OFFlowMod.OFPFC_MODIFY_STRICT) { - if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) { - // Instruct switch to let controller know when flow expires - ((OFFlowMod) fm).setFlags((short) 1); - } - } - } else { - ((V6FlowMod) fm).setVendor(); - ((V6FlowMod) fm).setMatch((V6Match) ofMatch); - ((V6FlowMod) fm).setActions(this.actionsList); - ((V6FlowMod) fm).setPriority(flow.getPriority()); - ((V6FlowMod) fm).setCookie(flow.getId()); - ((V6FlowMod) fm).setLength(U16.t(OFVendor.MINIMUM_LENGTH - + ((V6Match) ofMatch).getIPv6ExtMinHdrLen() - + ((V6Match) ofMatch).getIPv6MatchLen() - + ((V6Match) ofMatch).getPadSize() + actionsLength)); - ((V6FlowMod) fm).setIdleTimeout(flow.getIdleTimeout()); - ((V6FlowMod) fm).setHardTimeout(flow.getHardTimeout()); - ((V6FlowMod) fm).setCommand(command); - if (port != null) { - ((V6FlowMod) fm).setOutPort(port); - } - if (command == OFFlowMod.OFPFC_ADD - || command == OFFlowMod.OFPFC_MODIFY - || command == OFFlowMod.OFPFC_MODIFY_STRICT) { - if (flow.getIdleTimeout() != 0 || flow.getHardTimeout() != 0) { - // Instruct switch to let controller know when flow expires - ((V6FlowMod) fm).setFlags((short) 1); - } - } - } - logger.trace("Openflow Match: {} Openflow Actions: {}", ofMatch, - actionsList); - logger.trace("Openflow Mod Message: {}", fm); - return fm; - } - - public Flow getFlow(Node node) { - if (this.flow == null) { - Match salMatch = new Match(); - - /* - * Installed flow may not have a Match defined like in case of a - * drop all flow - */ - if (ofMatch != null) { - if (!isIPv6) { - // Compute OF1.0 Match - if (ofMatch.getInputPort() != 0) { - salMatch.setField(new MatchField(MatchType.IN_PORT, - NodeConnectorCreator.createNodeConnector( - (Short) ofMatch.getInputPort(), node))); - } - if (ofMatch.getDataLayerSource() != null - && !NetUtils - .isZeroMAC(ofMatch.getDataLayerSource())) { - byte srcMac[] = ofMatch.getDataLayerSource(); - salMatch.setField(new MatchField(MatchType.DL_SRC, - srcMac.clone())); - } - if (ofMatch.getDataLayerDestination() != null - && !NetUtils.isZeroMAC(ofMatch - .getDataLayerDestination())) { - byte dstMac[] = ofMatch.getDataLayerDestination(); - salMatch.setField(new MatchField(MatchType.DL_DST, - dstMac.clone())); - } - if (ofMatch.getDataLayerType() != 0) { - salMatch.setField(new MatchField(MatchType.DL_TYPE, - ofMatch.getDataLayerType())); - } - if (ofMatch.getDataLayerVirtualLan() != 0) { - salMatch.setField(new MatchField(MatchType.DL_VLAN, - ofMatch.getDataLayerVirtualLan())); - } - if (ofMatch.getDataLayerVirtualLanPriorityCodePoint() != 0) { - salMatch.setField(MatchType.DL_VLAN_PR, ofMatch - .getDataLayerVirtualLanPriorityCodePoint()); - } - if (ofMatch.getNetworkSource() != 0) { - salMatch.setField(MatchType.NW_SRC, NetUtils - .getInetAddress(ofMatch.getNetworkSource()), - NetUtils.getInetNetworkMask( - ofMatch.getNetworkSourceMaskLen(), - false)); - } - if (ofMatch.getNetworkDestination() != 0) { - salMatch.setField(MatchType.NW_DST, - NetUtils.getInetAddress(ofMatch - .getNetworkDestination()), - NetUtils.getInetNetworkMask( - ofMatch.getNetworkDestinationMaskLen(), - false)); - } - if (ofMatch.getNetworkTypeOfService() != 0) { - int dscp = NetUtils.getUnsignedByte(ofMatch - .getNetworkTypeOfService()); - byte tos = (byte) (dscp >> 2); - salMatch.setField(MatchType.NW_TOS, tos); - } - if (ofMatch.getNetworkProtocol() != 0) { - salMatch.setField(MatchType.NW_PROTO, - ofMatch.getNetworkProtocol()); - } - if (ofMatch.getTransportSource() != 0) { - salMatch.setField(MatchType.TP_SRC, - ((Short) ofMatch.getTransportSource())); - } - if (ofMatch.getTransportDestination() != 0) { - salMatch.setField(MatchType.TP_DST, - ((Short) ofMatch.getTransportDestination())); - } - } else { - // Compute OF1.0 + IPv6 extensions Match - V6Match v6Match = (V6Match) ofMatch; - if (v6Match.getInputPort() != 0) { - // Mask on input port is not defined - salMatch.setField(new MatchField(MatchType.IN_PORT, - NodeConnectorCreator.createOFNodeConnector( - (Short) v6Match.getInputPort(), node))); - } - if (v6Match.getDataLayerSource() != null - && !NetUtils - .isZeroMAC(ofMatch.getDataLayerSource())) { - byte srcMac[] = v6Match.getDataLayerSource(); - salMatch.setField(new MatchField(MatchType.DL_SRC, - srcMac.clone())); - } - if (v6Match.getDataLayerDestination() != null - && !NetUtils.isZeroMAC(ofMatch - .getDataLayerDestination())) { - byte dstMac[] = v6Match.getDataLayerDestination(); - salMatch.setField(new MatchField(MatchType.DL_DST, - dstMac.clone())); - } - if (v6Match.getDataLayerType() != 0) { - salMatch.setField(new MatchField(MatchType.DL_TYPE, - v6Match.getDataLayerType())); - } - if (v6Match.getDataLayerVirtualLan() != 0) { - salMatch.setField(new MatchField(MatchType.DL_VLAN, - v6Match.getDataLayerVirtualLan())); - } - if (v6Match.getDataLayerVirtualLanPriorityCodePoint() != 0) { - salMatch.setField(MatchType.DL_VLAN_PR, v6Match - .getDataLayerVirtualLanPriorityCodePoint()); - } - if (v6Match.getNetworkSrc() != null) { - salMatch.setField(MatchType.NW_SRC, - v6Match.getNetworkSrc(), - v6Match.getNetworkSourceMask()); - } - if (v6Match.getNetworkDest() != null) { - salMatch.setField(MatchType.NW_DST, - v6Match.getNetworkDest(), - v6Match.getNetworkDestinationMask()); - } - if (v6Match.getNetworkTypeOfService() != 0) { - int dscp = NetUtils.getUnsignedByte(v6Match - .getNetworkTypeOfService()); - byte tos = (byte) (dscp >> 2); - salMatch.setField(MatchType.NW_TOS, tos); - } - if (v6Match.getNetworkProtocol() != 0) { - salMatch.setField(MatchType.NW_PROTO, - v6Match.getNetworkProtocol()); - } - if (v6Match.getTransportSource() != 0) { - salMatch.setField(MatchType.TP_SRC, - ((Short) v6Match.getTransportSource())); - } - if (v6Match.getTransportDestination() != 0) { - salMatch.setField(MatchType.TP_DST, - ((Short) v6Match.getTransportDestination())); - } - } - } - - // Convert actions - Action salAction = null; - List salActionList = new ArrayList(); - if (actionsList == null) { - salActionList.add(new Drop()); - } else { - for (OFAction ofAction : actionsList) { - if (ofAction instanceof OFActionOutput) { - short ofPort = ((OFActionOutput) ofAction).getPort(); - if (ofPort == OFPort.OFPP_CONTROLLER.getValue()) { - salAction = new Controller(); - } else if (ofPort == OFPort.OFPP_NONE.getValue()) { - salAction = new Drop(); - } else if (ofPort == OFPort.OFPP_IN_PORT.getValue()) { - salAction = new Loopback(); - } else if (ofPort == OFPort.OFPP_FLOOD.getValue()) { - salAction = new Flood(); - } else if (ofPort == OFPort.OFPP_ALL.getValue()) { - salAction = new FloodAll(); - } else if (ofPort == OFPort.OFPP_LOCAL.getValue()) { - salAction = new SwPath(); - } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) { - salAction = new HwPath(); - } else if (ofPort == OFPort.OFPP_TABLE.getValue()) { - salAction = new HwPath(); // TODO: we do not handle - // table in sal for now - } else { - salAction = new Output( - NodeConnectorCreator.createOFNodeConnector( - ofPort, node)); - } - } else if (ofAction instanceof OFActionVirtualLanIdentifier) { - salAction = new SetVlanId( - ((OFActionVirtualLanIdentifier) ofAction) - .getVirtualLanIdentifier()); - } else if (ofAction instanceof OFActionStripVirtualLan) { - salAction = new PopVlan(); - } else if (ofAction instanceof OFActionVirtualLanPriorityCodePoint) { - salAction = new SetVlanPcp( - ((OFActionVirtualLanPriorityCodePoint) ofAction) - .getVirtualLanPriorityCodePoint()); - } else if (ofAction instanceof OFActionDataLayerSource) { - salAction = new SetDlSrc( - ((OFActionDataLayerSource) ofAction) - .getDataLayerAddress().clone()); - } else if (ofAction instanceof OFActionDataLayerDestination) { - salAction = new SetDlDst( - ((OFActionDataLayerDestination) ofAction) - .getDataLayerAddress().clone()); - } else if (ofAction instanceof OFActionNetworkLayerSource) { - byte addr[] = BigInteger.valueOf( - ((OFActionNetworkLayerSource) ofAction) - .getNetworkAddress()).toByteArray(); - InetAddress ip = null; - try { - ip = InetAddress.getByAddress(addr); - } catch (UnknownHostException e) { - logger.error("", e); - } - salAction = new SetNwSrc(ip); - } else if (ofAction instanceof OFActionNetworkLayerDestination) { - byte addr[] = BigInteger.valueOf( - ((OFActionNetworkLayerDestination) ofAction) - .getNetworkAddress()).toByteArray(); - InetAddress ip = null; - try { - ip = InetAddress.getByAddress(addr); - } catch (UnknownHostException e) { - logger.error("", e); - } - salAction = new SetNwDst(ip); - } else if (ofAction instanceof OFActionNetworkTypeOfService) { - salAction = new SetNwTos( - ((OFActionNetworkTypeOfService) ofAction) - .getNetworkTypeOfService()); - } else if (ofAction instanceof OFActionTransportLayerSource) { - Short port = ((OFActionTransportLayerSource) ofAction) - .getTransportPort(); - int intPort = NetUtils.getUnsignedShort(port); - salAction = new SetTpSrc(intPort); - } else if (ofAction instanceof OFActionTransportLayerDestination) { - Short port = ((OFActionTransportLayerDestination) ofAction) - .getTransportPort(); - int intPort = NetUtils.getUnsignedShort(port); - salAction = new SetTpDst(intPort); - } - salActionList.add(salAction); - } - } - // Create Flow - flow = new Flow(salMatch, salActionList); - } - logger.trace("Openflow Match: {} Openflow Actions: {}", ofMatch, - actionsList); - logger.trace("SAL Flow: {}", flow); - return flow; - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerNotifier.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerNotifier.java deleted file mode 100644 index 2a62d6c34a..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerNotifier.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.protocol_plugin.openflow.IFlowProgrammerNotifier; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Flow Programmer Notifier class for relaying asynchronous messages received - * from the network node to the listeners on the proper container - */ -public class FlowProgrammerNotifier implements IFlowProgrammerNotifier { - protected static final Logger logger = LoggerFactory - .getLogger(FlowProgrammerNotifier.class); - private IPluginOutFlowProgrammerService salNotifier; - - public FlowProgrammerNotifier() { - salNotifier = null; - } - - void init(Component c) { - logger.debug("INIT called!"); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - logger.debug("DESTROY called!"); - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - logger.debug("START called!"); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - logger.debug("STOP called!"); - } - - public void setPluginOutFlowProgrammerService( - IPluginOutFlowProgrammerService s) { - this.salNotifier = s; - } - - public void unsetPluginOutFlowProgrammerService( - IPluginOutFlowProgrammerService s) { - if (this.salNotifier == s) { - this.salNotifier = null; - } - } - - @Override - public void flowRemoved(Node node, Flow flow) { - if (salNotifier != null) { - salNotifier.flowRemoved(node, flow); - } else { - logger.warn("Unable to relay switch message to upper layer"); - } - } - - @Override - public void flowErrorReported(Node node, long rid, Object err) { - if (salNotifier != null) { - salNotifier.flowErrorReported(node, rid, err); - } else { - logger.warn("Unable to relay switch error message to upper layer"); - } - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java deleted file mode 100644 index 7f90c884cd..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerService.java +++ /dev/null @@ -1,754 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.opendaylight.controller.protocol_plugin.openflow.IFlowProgrammerNotifier; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService; -import org.opendaylight.controller.sal.match.Match; -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.HexEncode; -import org.opendaylight.controller.sal.utils.NodeCreator; -import org.opendaylight.controller.sal.utils.Status; -import org.opendaylight.controller.sal.utils.StatusCode; -import org.openflow.protocol.OFError; -import org.openflow.protocol.OFFlowMod; -import org.openflow.protocol.OFFlowRemoved; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFType; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.factory.MessageParseException; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Represents the openflow plugin component in charge of programming the flows - * the flow programming and relay them to functional modules above SAL. - */ -public class FlowProgrammerService implements IPluginInFlowProgrammerService, - IMessageListener, IContainerListener, IInventoryShimExternalListener, - CommandProvider { - private static final Logger log = LoggerFactory - .getLogger(FlowProgrammerService.class); - private IController controller; - private ConcurrentMap flowProgrammerNotifiers; - private Map> containerToNc; - private ConcurrentMap> xid2rid; - private int barrierMessagePriorCount = getBarrierMessagePriorCount(); - - public FlowProgrammerService() { - controller = null; - flowProgrammerNotifiers = new ConcurrentHashMap(); - containerToNc = new HashMap>(); - xid2rid = new ConcurrentHashMap>(); - } - - public void setController(IController core) { - this.controller = core; - } - - public void unsetController(IController core) { - if (this.controller == core) { - this.controller = null; - } - } - - public void setFlowProgrammerNotifier(Map props, - IFlowProgrammerNotifier s) { - if (props == null || props.get("containerName") == null) { - log.error("Didn't receive the service correct properties"); - return; - } - String containerName = (String) props.get("containerName"); - this.flowProgrammerNotifiers.put(containerName, s); - } - - public void unsetFlowProgrammerNotifier(Map props, - IFlowProgrammerNotifier s) { - if (props == null || props.get("containerName") == null) { - log.error("Didn't receive the service correct properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (this.flowProgrammerNotifiers != null - && this.flowProgrammerNotifiers.containsKey(containerName) - && this.flowProgrammerNotifiers.get(containerName) == s) { - this.flowProgrammerNotifiers.remove(containerName); - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - this.controller.addMessageListener(OFType.FLOW_REMOVED, this); - this.controller.addMessageListener(OFType.ERROR, this); - registerWithOSGIConsole(); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - } - - @Override - public Status addFlow(Node node, Flow flow) { - return addFlowInternal(node, flow, 0); - } - - @Override - public Status modifyFlow(Node node, Flow oldFlow, Flow newFlow) { - return modifyFlowInternal(node, oldFlow, newFlow, 0); - } - - @Override - public Status removeFlow(Node node, Flow flow) { - return removeFlowInternal(node, flow, 0); - } - - @Override - public Status addFlowAsync(Node node, Flow flow, long rid) { - return addFlowInternal(node, flow, rid); - } - - @Override - public Status modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, - long rid) { - return modifyFlowInternal(node, oldFlow, newFlow, rid); - } - - @Override - public Status removeFlowAsync(Node node, Flow flow, long rid) { - return removeFlowInternal(node, flow, rid); - } - - private Status addFlowInternal(Node node, Flow flow, long rid) { - String action = "add"; - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - return new Status(StatusCode.NOTACCEPTABLE, errorString("send", - action, "Invalid node type")); - } - - if (controller != null) { - ISwitch sw = controller.getSwitch((Long) node.getID()); - if (sw != null) { - FlowConverter x = new FlowConverter(flow); - OFMessage msg = x.getOFFlowMod(OFFlowMod.OFPFC_ADD, null); - - Object result; - if (rid == 0) { - /* - * Synchronous message send. Each message is followed by a - * Barrier message. - */ - result = sw.syncSend(msg); - } else { - log.debug("Sending flow asynchronously"); - /* - * Message will be sent asynchronously. A Barrier message - * will be inserted automatically to synchronize the - * progression. - */ - result = asyncMsgSend(node, sw, msg, rid); - } - return getStatusInternal(result, action, rid); - } else { - return new Status(StatusCode.GONE, errorString("send", action, - "Switch is not available")); - } - } - return new Status(StatusCode.INTERNALERROR, errorString("send", action, - "Internal plugin error")); - } - - private Status modifyFlowInternal(Node node, Flow oldFlow, Flow newFlow, long rid) { - String action = "modify"; - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - return new Status(StatusCode.NOTACCEPTABLE, errorString("send", - action, "Invalid node type")); - } - if (controller != null) { - ISwitch sw = controller.getSwitch((Long) node.getID()); - if (sw != null) { - OFMessage msg1 = null, msg2 = null; - - // If priority and match portion are the same, send a - // modification message - if (oldFlow.getPriority() != newFlow.getPriority() - || !oldFlow.getMatch().equals(newFlow.getMatch())) { - msg1 = new FlowConverter(oldFlow).getOFFlowMod( - OFFlowMod.OFPFC_DELETE_STRICT, OFPort.OFPP_NONE); - msg2 = new FlowConverter(newFlow).getOFFlowMod( - OFFlowMod.OFPFC_ADD, null); - } else { - msg1 = new FlowConverter(newFlow).getOFFlowMod( - OFFlowMod.OFPFC_MODIFY_STRICT, null); - } - /* - * Synchronous message send - */ - action = (msg2 == null) ? "modify" : "delete"; - Object result; - if (rid == 0) { - /* - * Synchronous message send. Each message is followed by a - * Barrier message. - */ - result = sw.syncSend(msg1); - } else { - /* - * Message will be sent asynchronously. A Barrier message - * will be inserted automatically to synchronize the - * progression. - */ - result = asyncMsgSend(node, sw, msg1, rid); - } - - Status rv = getStatusInternal(result, action, rid); - if ((msg2 == null) || !rv.isSuccess()) { - return rv; - } - - action = "add"; - if (rid == 0) { - /* - * Synchronous message send. Each message is followed by a - * Barrier message. - */ - result = sw.syncSend(msg2); - } else { - /* - * Message will be sent asynchronously. A Barrier message - * will be inserted automatically to synchronize the - * progression. - */ - result = asyncMsgSend(node, sw, msg2, rid); - } - return getStatusInternal(result, action, rid); - } else { - return new Status(StatusCode.GONE, errorString("send", action, - "Switch is not available")); - } - } - return new Status(StatusCode.INTERNALERROR, errorString("send", action, - "Internal plugin error")); - } - - private Status removeFlowInternal(Node node, Flow flow, long rid) { - String action = "remove"; - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - return new Status(StatusCode.NOTACCEPTABLE, errorString("send", - action, "Invalid node type")); - } - if (controller != null) { - ISwitch sw = controller.getSwitch((Long) node.getID()); - if (sw != null) { - OFMessage msg = new FlowConverter(flow).getOFFlowMod( - OFFlowMod.OFPFC_DELETE_STRICT, OFPort.OFPP_NONE); - Object result; - if (rid == 0) { - /* - * Synchronous message send. Each message is followed by a - * Barrier message. - */ - result = sw.syncSend(msg); - } else { - /* - * Message will be sent asynchronously. A Barrier message - * will be inserted automatically to synchronize the - * progression. - */ - result = asyncMsgSend(node, sw, msg, rid); - } - return getStatusInternal(result, action, rid); - } else { - return new Status(StatusCode.GONE, errorString("send", action, - "Switch is not available")); - } - } - return new Status(StatusCode.INTERNALERROR, errorString("send", action, - "Internal plugin error")); - } - - @Override - public Status removeAllFlows(Node node) { - return new Status(StatusCode.SUCCESS); - } - - private String errorString(String phase, String action, String cause) { - return "Failed to " - + ((phase != null) ? phase + " the " + action - + " flow message: " : action + " the flow: ") + cause; - } - - @Override - public void receive(ISwitch sw, OFMessage msg) { - if (msg instanceof OFFlowRemoved) { - handleFlowRemovedMessage(sw, (OFFlowRemoved) msg); - } else if (msg instanceof OFError) { - handleErrorMessage(sw, (OFError) msg); - } - } - - private void handleFlowRemovedMessage(ISwitch sw, OFFlowRemoved msg) { - Node node = NodeCreator.createOFNode(sw.getId()); - Flow flow = new FlowConverter(msg.getMatch(), - new ArrayList(0)).getFlow(node); - flow.setPriority(msg.getPriority()); - flow.setIdleTimeout(msg.getIdleTimeout()); - flow.setId(msg.getCookie()); - - Match match = flow.getMatch(); - NodeConnector inPort = match.isPresent(MatchType.IN_PORT) ? (NodeConnector) match - .getField(MatchType.IN_PORT).getValue() : null; - - for (Map.Entry containerNotifier : flowProgrammerNotifiers - .entrySet()) { - String container = containerNotifier.getKey(); - IFlowProgrammerNotifier notifier = containerNotifier.getValue(); - /* - * Switch only provide us with the match information. For now let's - * try to identify the container membership only from the input port - * match field. In any case, upper layer consumers can derive - * whether the notification was not for them. More sophisticated - * filtering can be added later on. - */ - if (inPort == null - || container.equals(GlobalConstants.DEFAULT.toString()) - || this.containerToNc.get(container).contains(inPort)) { - notifier.flowRemoved(node, flow); - } - } - } - - private void handleErrorMessage(ISwitch sw, OFError errorMsg) { - Node node = NodeCreator.createOFNode(sw.getId()); - OFMessage offendingMsg = null; - try { - offendingMsg = errorMsg.getOffendingMsg(); - } catch (MessageParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Integer xid; - if (offendingMsg != null) { - xid = offendingMsg.getXid(); - } else { - xid = errorMsg.getXid(); - } - - Long rid = getMessageRid(sw.getId(), xid); - /* - * Null or zero requestId indicates that the error message is meant for - * a sync message. It will be handled by the sync message worker thread. - * Hence we are done here. - */ - if ((rid == null) || (rid == 0)) { - return; - } - - /* - * Notifies the caller that error has been reported for a previous flow - * programming request - */ - for (Map.Entry containerNotifier : flowProgrammerNotifiers - .entrySet()) { - IFlowProgrammerNotifier notifier = containerNotifier.getValue(); - notifier.flowErrorReported(node, rid, errorMsg); - } - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType type) { - Set target = null; - - switch (type) { - case ADDED: - if (!containerToNc.containsKey(containerName)) { - containerToNc.put(containerName, new HashSet()); - } - containerToNc.get(containerName).add(p); - break; - case CHANGED: - break; - case REMOVED: - target = containerToNc.get(containerName); - if (target != null) { - target.remove(p); - } - break; - default: - } - } - - @Override - public void containerModeUpdated(UpdateType t) { - - } - - @Override - public Status syncSendBarrierMessage(Node node) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - return new Status(StatusCode.NOTACCEPTABLE, - "The node does not support Barrier message."); - } - - if (controller != null) { - long swid = (Long) node.getID(); - ISwitch sw = controller.getSwitch(swid); - if (sw != null) { - sw.syncSendBarrierMessage(); - clearXid2Rid(swid); - return (new Status(StatusCode.SUCCESS)); - } else { - return new Status(StatusCode.GONE, - "The node does not have a valid Switch reference."); - } - } - return new Status(StatusCode.INTERNALERROR, - "Failed to send Barrier message."); - } - - @Override - public Status asyncSendBarrierMessage(Node node) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - return new Status(StatusCode.NOTACCEPTABLE, - "The node does not support Barrier message."); - } - - if (controller != null) { - long swid = (Long) node.getID(); - ISwitch sw = controller.getSwitch(swid); - if (sw != null) { - sw.asyncSendBarrierMessage(); - clearXid2Rid(swid); - return (new Status(StatusCode.SUCCESS)); - } else { - return new Status(StatusCode.GONE, - "The node does not have a valid Switch reference."); - } - } - return new Status(StatusCode.INTERNALERROR, - "Failed to send Barrier message."); - } - - /** - * This method sends the message asynchronously until the number of messages - * sent reaches a threshold. Then a Barrier message is sent automatically - * for sync purpose. An unique Request ID associated with the message is - * passed down by the caller. The Request ID will be returned to the caller - * when an error message is received from the switch. - * - * @param node - * The node - * @param msg - * The switch - * @param msg - * The OF message to be sent - * @param rid - * The Request Id - * @return result - */ - private Object asyncMsgSend(Node node, ISwitch sw, OFMessage msg, long rid) { - Object result = Boolean.TRUE; - long swid = (Long) node.getID(); - int xid; - - xid = sw.asyncSend(msg); - addXid2Rid(swid, xid, rid); - - Map swxid2rid = this.xid2rid.get(swid); - if (swxid2rid == null) { - return result; - } - - int size = swxid2rid.size(); - if (size % barrierMessagePriorCount == 0) { - result = asyncSendBarrierMessage(node); - } - - return result; - } - - /** - * A number of async messages are sent followed by a synchronous Barrier - * message. This method returns the maximum async messages that can be sent - * before the Barrier message. - * - * @return The max count of async messages sent prior to Barrier message - */ - private int getBarrierMessagePriorCount() { - String count = System.getProperty("of.barrierMessagePriorCount"); - int rv = 100; - - if (count != null) { - try { - rv = Integer.parseInt(count); - } catch (Exception e) { - } - } - - return rv; - } - - /** - * This method returns the message Request ID previously assigned by the - * caller for a given OF message xid - * - * @param swid - * The switch id - * @param xid - * The OF message xid - * @return The Request ID - */ - private Long getMessageRid(long swid, Integer xid) { - Long rid = null; - - if (xid == null) { - return rid; - } - - Map swxid2rid = this.xid2rid.get(swid); - if (swxid2rid != null) { - rid = swxid2rid.get(xid); - } - return rid; - } - - /** - * This method returns a copy of outstanding xid to rid mappings.for a given - * switch - * - * @param swid - * The switch id - * @return a copy of xid2rid mappings - */ - public Map getSwXid2Rid(long swid) { - Map swxid2rid = this.xid2rid.get(swid); - - if (swxid2rid != null) { - return new HashMap(swxid2rid); - } else { - return new HashMap(); - } - } - - /** - * Adds xid to rid mapping to the local DB - * - * @param swid - * The switch id - * @param xid - * The OF message xid - * @param rid - * The message Request ID - */ - private void addXid2Rid(long swid, int xid, long rid) { - Map swxid2rid = this.xid2rid.get(swid); - if (swxid2rid != null) { - swxid2rid.put(xid, rid); - } - } - - /** - * When an Error message is received, this method will be invoked to remove - * the offending xid from the local DB. - * - * @param swid - * The switch id - * @param xid - * The OF message xid - */ - private void removeXid2Rid(long swid, int xid) { - Map swxid2rid = this.xid2rid.get(swid); - if (swxid2rid != null) { - swxid2rid.remove(xid); - } - } - - /** - * Convert various result into Status - * - * @param result - * The returned result from previous action - * @param action - * add/modify/delete flow action - * @param rid - * The Request ID associated with the flow message - * @return Status - */ - private Status getStatusInternal(Object result, String action, long rid) { - if (result instanceof Boolean) { - return ((Boolean) result == Boolean.TRUE) ? new Status( - StatusCode.SUCCESS, rid) : new Status( - StatusCode.TIMEOUT, errorString(null, action, - "Request Timed Out")); - } else if (result instanceof Status) { - return (Status) result; - } else if (result instanceof OFError) { - OFError res = (OFError) result; - return new Status(StatusCode.INTERNALERROR, errorString( - "program", action, Utils.getOFErrorString(res))); - } else { - return new Status(StatusCode.INTERNALERROR, errorString( - "send", action, "Internal Error")); - } - } - - /** - * When a Barrier reply is received, this method will be invoked to clear - * the local DB - * - * @param swid - * The switch id - */ - private void clearXid2Rid(long swid) { - Map swxid2rid = this.xid2rid.get(swid); - if (swxid2rid != null) { - swxid2rid.clear(); - } - } - - @Override - public void updateNode(Node node, UpdateType type, Set props) { - long swid = (Long)node.getID(); - - switch (type) { - case ADDED: - Map swxid2rid = new HashMap(); - this.xid2rid.put(swid, swxid2rid); - break; - case CHANGED: - break; - case REMOVED: - this.xid2rid.remove(swid); - break; - default: - } - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - } - - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, - null); - } - - @Override - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("-- Flow Programmer Service --\n"); - help.append("\t px2r - Print outstanding xid2rid mappings for a given node id\n"); - help.append("\t px2rc - Print max num of async msgs prior to the Barrier\n"); - return help.toString(); - } - - public void _px2r(CommandInterpreter ci) { - String st = ci.nextArgument(); - if (st == null) { - ci.println("Please enter a valid node id"); - return; - } - - long sid; - try { - sid = HexEncode.stringToLong(st); - } catch (NumberFormatException e) { - ci.println("Please enter a valid node id"); - return; - } - - Map swxid2rid = this.xid2rid.get(sid); - if (swxid2rid == null) { - ci.println("The node id entered does not exist"); - return; - } - - ci.println("xid rid"); - - Set xidSet = swxid2rid.keySet(); - if (xidSet == null) { - return; - } - - for (Integer xid : xidSet) { - ci.println(xid + " " + swxid2rid.get(xid)); - } - } - - public void _px2rc(CommandInterpreter ci) { - ci.println("Max num of async messages sent prior to the Barrier message is " - + barrierMessagePriorCount); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowStatisticsConverter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowStatisticsConverter.java deleted file mode 100644 index 82dbf670a9..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowStatisticsConverter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.reader.FlowOnNode; -import org.openflow.protocol.statistics.OFFlowStatisticsReply; -import org.openflow.protocol.statistics.OFStatistics; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Converts an openflow list of flow statistics in a SAL list of FlowOnNode - * objects - * - * - * - */ -public class FlowStatisticsConverter { - private static final Logger log = LoggerFactory - .getLogger(FlowStatisticsConverter.class); - private List ofStatsList; - private List flowOnNodeList; - - public FlowStatisticsConverter(List statsList) { - if (statsList == null) {// || statsList.isEmpty()) { - this.ofStatsList = new ArrayList(1); // dummy list - } else { - this.ofStatsList = statsList; // new - // ArrayList(statsList); - } - this.flowOnNodeList = null; - } - - public List getFlowOnNodeList(Node node) { - if (ofStatsList != null && flowOnNodeList == null) { - flowOnNodeList = new ArrayList(); - FlowConverter flowConverter = null; - OFFlowStatisticsReply ofFlowStat; - V6StatsReply v6StatsReply; - for (OFStatistics ofStat : ofStatsList) { - FlowOnNode flowOnNode = null; - if (ofStat instanceof OFFlowStatisticsReply) { - ofFlowStat = (OFFlowStatisticsReply) ofStat; - flowConverter = new FlowConverter(ofFlowStat.getMatch(), - ofFlowStat.getActions()); - Flow flow = flowConverter.getFlow(node); - flow.setPriority(ofFlowStat.getPriority()); - flow.setIdleTimeout(ofFlowStat.getIdleTimeout()); - flow.setHardTimeout(ofFlowStat.getHardTimeout()); - flowOnNode = new FlowOnNode(flow); - flowOnNode.setByteCount(ofFlowStat.getByteCount()); - flowOnNode.setPacketCount(ofFlowStat.getPacketCount()); - flowOnNode.setDurationSeconds(ofFlowStat - .getDurationSeconds()); - flowOnNode.setDurationNanoseconds(ofFlowStat - .getDurationNanoseconds()); - } else if (ofStat instanceof V6StatsReply) { - v6StatsReply = (V6StatsReply) ofStat; - flowConverter = new FlowConverter(v6StatsReply.getMatch(), - v6StatsReply.getActions()); - Flow flow = flowConverter.getFlow(node); - flow.setPriority(v6StatsReply.getPriority()); - flow.setIdleTimeout(v6StatsReply.getIdleTimeout()); - flow.setHardTimeout(v6StatsReply.getHardTimeout()); - flowOnNode = new FlowOnNode(flow); - flowOnNode.setByteCount(v6StatsReply.getByteCount()); - flowOnNode.setPacketCount(v6StatsReply.getPacketCount()); - flowOnNode.setDurationSeconds(v6StatsReply - .getDurationSeconds()); - flowOnNode.setDurationNanoseconds(v6StatsReply - .getDurationNanoseconds()); - } else { - continue; - } - flowOnNodeList.add(flowOnNode); - } - } - log.trace("OFStatistics: {} FlowOnNode: {}", ofStatsList, - flowOnNodeList); - return flowOnNodeList; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java deleted file mode 100644 index 60fbd70843..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryService.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Collections; -import java.util.Date; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.sal.core.Actions; -import org.opendaylight.controller.sal.core.Buffers; -import org.opendaylight.controller.sal.core.Capabilities; -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.core.Description; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.Tables; -import org.opendaylight.controller.sal.core.TimeStamp; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; -import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.openflow.protocol.statistics.OFDescriptionStatistics; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The class describes inventory service protocol plugin. One instance per - * container of the network. Each instance gets container specific inventory - * events from InventoryServiceShim. It interacts with SAL to pass inventory - * data to the upper application. - * - * - */ -public class InventoryService implements IInventoryShimInternalListener, - IPluginInInventoryService, IStatisticsListener { - protected static final Logger logger = LoggerFactory - .getLogger(InventoryService.class); - private Set pluginOutInventoryServices = Collections - .synchronizedSet(new HashSet()); - private IController controller = null; - private ConcurrentMap> nodeProps; // properties are maintained in global container only - private ConcurrentMap> nodeConnectorProps; // properties are maintained in global container only - private boolean isDefaultContainer = false; - - void setController(IController s) { - this.controller = s; - } - - void unsetController(IController s) { - if (this.controller == s) { - this.controller = null; - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - @SuppressWarnings("rawtypes") - void init(Component c) { - logger.trace("INIT called!"); - - Dictionary props = c.getServiceProperties(); - if (props != null) { - String containerName = (String) props.get("containerName"); - isDefaultContainer = containerName.equals(GlobalConstants.DEFAULT - .toString()); - } - - nodeProps = new ConcurrentHashMap>(); - nodeConnectorProps = new ConcurrentHashMap>(); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - logger.trace("DESTROY called!"); - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - logger.trace("START called!"); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - logger.trace("STOP called!"); - } - - public void setPluginOutInventoryServices(IPluginOutInventoryService service) { - logger.trace("Got a service set request {}", service); - if (this.pluginOutInventoryServices != null) { - this.pluginOutInventoryServices.add(service); - } - } - - public void unsetPluginOutInventoryServices( - IPluginOutInventoryService service) { - logger.trace("Got a service UNset request"); - if (this.pluginOutInventoryServices != null) { - this.pluginOutInventoryServices.remove(service); - } - } - - protected Node OFSwitchToNode(ISwitch sw) { - Node node = null; - Object id = sw.getId(); - - try { - node = new Node(NodeIDType.OPENFLOW, id); - } catch (ConstructionException e) { - logger.error("",e); - } - - return node; - } - - /** - * Retrieve nodes from openflow - */ - @Override - public ConcurrentMap> getNodeProps() { - if (nodeProps == null) - return null; - Map switches = controller.getSwitches(); - for (Map.Entry entry : switches.entrySet()) { - ISwitch sw = entry.getValue(); - Node node = OFSwitchToNode(sw); - Map propMap = null; - if (isDefaultContainer) { - propMap = new HashMap(); - byte tables = sw.getTables(); - Tables t = new Tables(tables); - if (t != null) { - propMap.put(Tables.TablesPropName, t); - } - int cap = sw.getCapabilities(); - Capabilities c = new Capabilities(cap); - if (c != null) { - propMap.put(Capabilities.CapabilitiesPropName, c); - } - int act = sw.getActions(); - Actions a = new Actions(act); - if (a != null) { - propMap.put(Actions.ActionsPropName, a); - } - int buffers = sw.getBuffers(); - Buffers b = new Buffers(buffers); - if (b != null) { - propMap.put(Buffers.BuffersPropName, b); - } - Date connectedSince = sw.getConnectedDate(); - Long connectedSinceTime = (connectedSince == null) ? 0 - : connectedSince.getTime(); - TimeStamp timeStamp = new TimeStamp(connectedSinceTime, - "connectedSince"); - propMap.put(TimeStamp.TimeStampPropName, timeStamp); - nodeProps.put(node, propMap); - } - } - return nodeProps; - } - - @Override - public ConcurrentMap> getNodeConnectorProps( - Boolean refresh) { - if (nodeConnectorProps == null) - return null; - - if (isDefaultContainer && refresh) { - Map switches = controller.getSwitches(); - for (ISwitch sw : switches.values()) { - Map> ncProps = InventoryServiceHelper - .OFSwitchToProps(sw); - for (Map.Entry> entry : ncProps - .entrySet()) { - updateNodeConnector(entry.getKey(), UpdateType.ADDED, - entry.getValue()); - } - } - } - - return nodeConnectorProps; - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - logger.trace("updateNodeConnector {} type {}", nodeConnector, - type.getName()); - if (nodeConnectorProps == null) { - logger.trace("nodeConnectorProps is null"); - return; - } - - Map propMap = nodeConnectorProps.get(nodeConnector); - switch (type) { - case ADDED: - case CHANGED: - if (propMap == null) - propMap = new HashMap(); - - if (props != null) { - for (Property prop : props) { - propMap.put(prop.getName(), prop); - } - } - nodeConnectorProps.put(nodeConnector, propMap); - break; - case REMOVED: - nodeConnectorProps.remove(nodeConnector); - break; - default: - return; - } - - // update sal and discovery - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNodeConnector(nodeConnector, type, props); - } - } - } - - private void addNode(Node node, Set props) { - logger.trace("{} added", node); - if (nodeProps == null) - return; - - // update local cache - Map propMap = new HashMap(); - for (Property prop : props) { - propMap.put(prop.getName(), prop); - } - nodeProps.put(node, propMap); - - // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.ADDED, props); - } - } - } - - private void removeNode(Node node) { - logger.trace("{} removed", node); - if (nodeProps == null) - return; - - // update local cache - nodeProps.remove(node); - - Set removeSet = new HashSet(); - for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) { - if (nodeConnector.getNode().equals(node)) { - removeSet.add(nodeConnector); - } - } - for (NodeConnector nodeConnector : removeSet) { - nodeConnectorProps.remove(nodeConnector); - } - - // update sal - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.REMOVED, null); - } - } - } - - private void updateSwitchProperty(Long switchId, Set propSet) { - // update local cache - Node node = OFSwitchToNode(controller.getSwitch(switchId)); - Map propMap = nodeProps.get(node); - if (propMap == null) { - propMap = new HashMap(); - } - - boolean change = false; - for (Property prop : propSet) { - String propertyName = prop.getName(); - Property currentProp = propMap.get(propertyName); - if (!prop.equals(currentProp)) { - change = true; - propMap.put(propertyName, prop); - } - } - nodeProps.put(node, propMap); - - // Update sal if any of the properties has changed - if (change) { - synchronized (pluginOutInventoryServices) { - for (IPluginOutInventoryService service : pluginOutInventoryServices) { - service.updateNode(node, UpdateType.CHANGED, propSet); - } - } - } - } - - @Override - public void updateNode(Node node, UpdateType type, Set props) { - switch (type) { - case ADDED: - addNode(node, props); - break; - case REMOVED: - removeNode(node); - break; - default: - break; - } - } - - @Override - public void descriptionRefreshed(Long switchId, - OFDescriptionStatistics descriptionStats) { - - Set propSet = new HashSet(1); - Description desc = new Description( - descriptionStats.getDatapathDescription()); - propSet.add(desc); - this.updateSwitchProperty(switchId, propSet); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceHelper.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceHelper.java deleted file mode 100644 index 79973ee0bf..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceHelper.java +++ /dev/null @@ -1,167 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.sal.core.Bandwidth; -import org.opendaylight.controller.sal.core.AdvertisedBandwidth; -import org.opendaylight.controller.sal.core.SupportedBandwidth; -import org.opendaylight.controller.sal.core.PeerBandwidth; -import org.opendaylight.controller.sal.core.Config; -import org.opendaylight.controller.sal.core.Name; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.State; - -import org.opendaylight.controller.sal.utils.NodeCreator; - -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.openflow.protocol.OFPhysicalPort; -import org.openflow.protocol.OFPhysicalPort.OFPortConfig; -import org.openflow.protocol.OFPhysicalPort.OFPortFeatures; -import org.openflow.protocol.OFPhysicalPort.OFPortState; - -/** - * The class provides helper functions to retrieve inventory properties from - * OpenFlow messages - */ -public class InventoryServiceHelper { - /* - * Returns BandWidth property from OpenFlow OFPhysicalPort features - */ - public static Bandwidth OFPortToBandWidth(int portFeatures) { - Bandwidth bw = null; - int value = portFeatures - & (OFPortFeatures.OFPPF_10MB_FD.getValue() - | OFPortFeatures.OFPPF_10MB_HD.getValue() - | OFPortFeatures.OFPPF_100MB_FD.getValue() - | OFPortFeatures.OFPPF_100MB_HD.getValue() - | OFPortFeatures.OFPPF_1GB_FD.getValue() - | OFPortFeatures.OFPPF_1GB_HD.getValue() | OFPortFeatures.OFPPF_10GB_FD - .getValue()); - - switch (value) { - case 1: - case 2: - bw = new Bandwidth(Bandwidth.BW10Mbps); - break; - case 4: - case 8: - bw = new Bandwidth(Bandwidth.BW100Mbps); - break; - case 16: - case 32: - bw = new Bandwidth(Bandwidth.BW1Gbps); - break; - case 64: - bw = new Bandwidth(Bandwidth.BW10Gbps); - break; - default: - break; - } - return bw; - } - - /* - * Returns Config property from OpenFLow OFPhysicalPort config - */ - public static Config OFPortToConfig(int portConfig) { - Config config; - if ((OFPortConfig.OFPPC_PORT_DOWN.getValue() & portConfig) != 0) - config = new Config(Config.ADMIN_DOWN); - else - config = new Config(Config.ADMIN_UP); - return config; - } - - /* - * Returns State property from OpenFLow OFPhysicalPort state - */ - public static State OFPortToState(int portState) { - State state; - if ((OFPortState.OFPPS_LINK_DOWN.getValue() & portState) != 0) - state = new State(State.EDGE_DOWN); - else - state = new State(State.EDGE_UP); - return state; - } - - /* - * Returns set of properties from OpenFLow OFPhysicalPort - */ - public static Set OFPortToProps(OFPhysicalPort port) { - Set props = new HashSet(); - Bandwidth bw = InventoryServiceHelper.OFPortToBandWidth(port - .getCurrentFeatures()); - if (bw != null) { - props.add(bw); - } - - Bandwidth abw = InventoryServiceHelper.OFPortToBandWidth(port.getAdvertisedFeatures()); - if (abw != null) { - AdvertisedBandwidth a = new AdvertisedBandwidth(abw.getValue()); - if (a != null) { - props.add(a); - } - } - Bandwidth sbw = InventoryServiceHelper.OFPortToBandWidth(port.getSupportedFeatures()); - if (sbw != null) { - SupportedBandwidth s = new SupportedBandwidth(sbw.getValue()); - if (s != null) { - props.add(s); - } - } - Bandwidth pbw = InventoryServiceHelper.OFPortToBandWidth(port.getPeerFeatures()); - if (pbw != null) { - PeerBandwidth p = new PeerBandwidth(pbw.getValue()); - if (p != null) { - props.add(p); - } - } - props.add(new Name(port.getName())); - props.add(InventoryServiceHelper.OFPortToConfig(port.getConfig())); - props.add(InventoryServiceHelper.OFPortToState(port.getState())); - return props; - } - - /* - * Returns set of properties for each nodeConnector in an OpenFLow switch - */ - public static Map> OFSwitchToProps(ISwitch sw) { - Map> ncProps = new HashMap>(); - - if (sw == null) { - return ncProps; - } - - Node node = NodeCreator.createOFNode(sw.getId()); - if (node == null) { - return ncProps; - } - - Set props; - NodeConnector nodeConnector; - OFPhysicalPort port; - Map ports = sw.getPhysicalPorts(); - for (Map.Entry entry : ports.entrySet()) { - nodeConnector = PortConverter.toNodeConnector(entry.getKey(), node); - port = entry.getValue(); - props = InventoryServiceHelper.OFPortToProps(port); - ncProps.put(nodeConnector, props); - } - - return ncProps; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java deleted file mode 100644 index 49143c8dfa..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener; -import org.opendaylight.controller.sal.core.Actions; -import org.opendaylight.controller.sal.core.Buffers; -import org.opendaylight.controller.sal.core.Capabilities; -import org.opendaylight.controller.sal.core.ConstructionException; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.Tables; -import org.opendaylight.controller.sal.core.TimeStamp; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.openflow.protocol.OFMessage; -import org.openflow.protocol.OFPortStatus; -import org.openflow.protocol.OFPortStatus.OFPortReason; -import org.openflow.protocol.OFType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The class describes a shim layer that bridges inventory events from Openflow - * core to various listeners. The notifications are filtered based on container - * configurations. - * - * - */ -public class InventoryServiceShim implements IContainerListener, - IMessageListener, ISwitchStateListener { - protected static final Logger logger = LoggerFactory - .getLogger(InventoryServiceShim.class); - private IController controller = null; - private ConcurrentMap inventoryShimInternalListeners = new ConcurrentHashMap(); - private List inventoryShimExternalListeners = new CopyOnWriteArrayList(); - private ConcurrentMap> containerMap = new ConcurrentHashMap>(); - - void setController(IController s) { - this.controller = s; - } - - void unsetController(IController s) { - if (this.controller == s) { - this.controller = null; - } - } - - void setInventoryShimInternalListener(Map props, - IInventoryShimInternalListener s) { - if (props == null) { - logger.error("setInventoryShimInternalListener property is null"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("setInventoryShimInternalListener containerName not supplied"); - return; - } - if ((this.inventoryShimInternalListeners != null) - && !this.inventoryShimInternalListeners.containsValue(s)) { - this.inventoryShimInternalListeners.put(containerName, s); - logger.trace( - "Added inventoryShimInternalListener for container {}", - containerName); - } - } - - void unsetInventoryShimInternalListener(Map props, - IInventoryShimInternalListener s) { - if (props == null) { - logger.error("unsetInventoryShimInternalListener property is null"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("unsetInventoryShimInternalListener containerName not supplied"); - return; - } - if ((this.inventoryShimInternalListeners != null) - && this.inventoryShimInternalListeners.get(containerName) != null - && this.inventoryShimInternalListeners.get(containerName) - .equals(s)) { - this.inventoryShimInternalListeners.remove(containerName); - logger.trace( - "Removed inventoryShimInternalListener for container {}", - containerName); - } - } - - void setInventoryShimExternalListener(IInventoryShimExternalListener s) { - logger.trace("Set inventoryShimExternalListener"); - if ((this.inventoryShimExternalListeners != null) - && !this.inventoryShimExternalListeners.contains(s)) { - this.inventoryShimExternalListeners.add(s); - } - } - - void unsetInventoryShimExternalListener(IInventoryShimExternalListener s) { - if ((this.inventoryShimExternalListeners != null) - && this.inventoryShimExternalListeners.contains(s)) { - this.inventoryShimExternalListeners.remove(s); - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - this.controller.addMessageListener(OFType.PORT_STATUS, this); - this.controller.addSwitchStateListener(this); - } - - /** - * Function called after registering the service in OSGi service registry. - */ - void started() { - /* Start with existing switches */ - startService(); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - this.controller.removeMessageListener(OFType.PACKET_IN, this); - this.controller.removeSwitchStateListener(this); - - this.inventoryShimInternalListeners.clear(); - this.containerMap.clear(); - this.controller = null; - } - - @Override - public void receive(ISwitch sw, OFMessage msg) { - try { - if (msg instanceof OFPortStatus) { - handlePortStatusMessage(sw, (OFPortStatus) msg); - } - } catch (ConstructionException e) { - logger.error("",e); - } - return; - } - - protected void handlePortStatusMessage(ISwitch sw, OFPortStatus m) - throws ConstructionException { - Node node = new Node(NodeIDType.OPENFLOW, sw.getId()); - NodeConnector nodeConnector = PortConverter.toNodeConnector(m.getDesc() - .getPortNumber(), node); - UpdateType type = null; - - if (m.getReason() == (byte) OFPortReason.OFPPR_ADD.ordinal()) { - type = UpdateType.ADDED; - } else if (m.getReason() == (byte) OFPortReason.OFPPR_DELETE.ordinal()) { - type = UpdateType.REMOVED; - } else if (m.getReason() == (byte) OFPortReason.OFPPR_MODIFY.ordinal()) { - type = UpdateType.CHANGED; - } - - logger.trace("handlePortStatusMessage {} type {}", nodeConnector, type); - - if (type != null) { - // get node connector properties - Set props = InventoryServiceHelper.OFPortToProps(m - .getDesc()); - notifyInventoryShimListener(nodeConnector, type, props); - } - } - - @Override - public void switchAdded(ISwitch sw) { - if (sw == null) - return; - - // Add all the nodeConnectors of this switch - Map> ncProps = InventoryServiceHelper - .OFSwitchToProps(sw); - for (Map.Entry> entry : ncProps.entrySet()) { - notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, - entry.getValue()); - } - - // Add this node - addNode(sw); - } - - @Override - public void switchDeleted(ISwitch sw) { - if (sw == null) - return; - - removeNode(sw); - } - - @Override - public void containerModeUpdated(UpdateType t) { - // do nothing - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType t) { - if (this.containerMap == null) { - logger.error("containerMap is NULL"); - return; - } - List containers = this.containerMap.get(p); - if (containers == null) { - containers = new CopyOnWriteArrayList(); - } - boolean updateMap = false; - switch (t) { - case ADDED: - if (!containers.contains(containerName)) { - containers.add(containerName); - updateMap = true; - } - break; - case REMOVED: - if (containers.contains(containerName)) { - containers.remove(containerName); - updateMap = true; - } - break; - case CHANGED: - break; - } - if (updateMap) { - if (containers.isEmpty()) { - // Do cleanup to reduce memory footprint if no - // elements to be tracked - this.containerMap.remove(p); - } else { - this.containerMap.put(p, containers); - } - } - - // notify InventoryService - notifyInventoryShimInternalListener(containerName, p, t, null); - } - - private void notifyInventoryShimExternalListener(Node node, - UpdateType type, Set props) { - for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) { - s.updateNode(node, type, props); - } - } - - private void notifyInventoryShimExternalListener( - NodeConnector nodeConnector, UpdateType type, Set props) { - for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) { - s.updateNodeConnector(nodeConnector, type, props); - } - } - - private void notifyInventoryShimInternalListener(String container, - NodeConnector nodeConnector, UpdateType type, Set props) { - IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners - .get(container); - if (inventoryShimInternalListener != null) { - inventoryShimInternalListener.updateNodeConnector(nodeConnector, - type, props); - logger.trace( - "notifyInventoryShimInternalListener {} type {} for container {}", - nodeConnector, type, container); - } - } - - /* - * Notify all internal and external listeners - */ - private void notifyInventoryShimListener(NodeConnector nodeConnector, - UpdateType type, Set props) { - // Always notify default InventoryService. Store properties in default - // one. - notifyInventoryShimInternalListener(GlobalConstants.DEFAULT.toString(), - nodeConnector, type, props); - - // Now notify other containers - List containers = containerMap.get(nodeConnector); - if (containers != null) { - for (String container : containers) { - // no property stored in container components. - notifyInventoryShimInternalListener(container, nodeConnector, - type, null); - } - } - - // Notify DiscoveryService - notifyInventoryShimExternalListener(nodeConnector, type, props); - } - - /* - * Notify all internal and external listeners - */ - private void notifyInventoryShimListener(Node node, UpdateType type, - Set props) { - switch (type) { - case ADDED: - // Notify only the default Inventory Service - IInventoryShimInternalListener inventoryShimDefaultListener = inventoryShimInternalListeners - .get(GlobalConstants.DEFAULT.toString()); - if (inventoryShimDefaultListener != null) { - inventoryShimDefaultListener.updateNode(node, type, props); - } - break; - case REMOVED: - // Notify all Inventory Service containers - for (IInventoryShimInternalListener inventoryShimInternalListener : inventoryShimInternalListeners - .values()) { - inventoryShimInternalListener.updateNode(node, type, null); - } - break; - default: - break; - } - - // Notify external listener - notifyInventoryShimExternalListener(node, type, props); - } - - private void addNode(ISwitch sw) { - Node node; - try { - node = new Node(NodeIDType.OPENFLOW, sw.getId()); - } catch (ConstructionException e) { - logger.error("{}", e.getMessage()); - return; - } - - UpdateType type = UpdateType.ADDED; - - Set props = new HashSet(); - Long sid = (Long) node.getID(); - - Date connectedSince = controller.getSwitches().get(sid) - .getConnectedDate(); - Long connectedSinceTime = (connectedSince == null) ? 0 : connectedSince - .getTime(); - props.add(new TimeStamp(connectedSinceTime, "connectedSince")); - - byte tables = sw.getTables(); - Tables t = new Tables(tables); - if (t != null) { - props.add(t); - } - int cap = sw.getCapabilities(); - Capabilities c = new Capabilities(cap); - if (c != null) { - props.add(c); - } - int act = sw.getActions(); - Actions a = new Actions(act); - if (a != null) { - props.add(a); - } - int buffers = sw.getBuffers(); - Buffers b = new Buffers(buffers); - if (b != null) { - props.add(b); - } - // Notify all internal and external listeners - notifyInventoryShimListener(node, type, props); - } - - private void removeNode(ISwitch sw) { - Node node; - try { - node = new Node(NodeIDType.OPENFLOW, sw.getId()); - } catch (ConstructionException e) { - logger.error("{}", e.getMessage()); - return; - } - - UpdateType type = UpdateType.REMOVED; - - // Notify all internal and external listeners - notifyInventoryShimListener(node, type, null); - } - - private void startService() { - // Get a snapshot of all the existing switches - Map switches = this.controller.getSwitches(); - for (ISwitch sw : switches.values()) { - switchAdded(sw); - } - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java deleted file mode 100644 index cf9a2c517d..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/OFStatisticsManager.java +++ /dev/null @@ -1,1255 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Deque; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.LinkedBlockingQueue; - -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsListener; -import org.opendaylight.controller.protocol_plugin.openflow.IStatisticsServiceShimListener; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsRequest; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.HexEncode; -import org.openflow.protocol.OFError; -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFStatisticsRequest; -import org.openflow.protocol.statistics.OFAggregateStatisticsRequest; -import org.openflow.protocol.statistics.OFDescriptionStatistics; -import org.openflow.protocol.statistics.OFFlowStatisticsReply; -import org.openflow.protocol.statistics.OFFlowStatisticsRequest; -import org.openflow.protocol.statistics.OFPortStatisticsReply; -import org.openflow.protocol.statistics.OFPortStatisticsRequest; -import org.openflow.protocol.statistics.OFQueueStatisticsRequest; -import org.openflow.protocol.statistics.OFStatistics; -import org.openflow.protocol.statistics.OFStatisticsType; -import org.openflow.protocol.statistics.OFVendorStatistics; -import org.openflow.util.HexString; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * It periodically polls the different OF statistics from the OF switches and - * caches them for quick retrieval for the above layers' modules It also - * provides an API to directly query the switch about the statistics - */ -public class OFStatisticsManager implements IOFStatisticsManager, - IInventoryShimExternalListener, CommandProvider { - private static final Logger log = LoggerFactory - .getLogger(OFStatisticsManager.class); - private static final int initialSize = 64; - private static final long flowStatsPeriod = 10000; - private static final long descriptionStatsPeriod = 60000; - private static final long portStatsPeriod = 5000; - private static final long flowTableStatsPeriod = 60000; - private static final long tickPeriod = 1000; - private static short statisticsTickNumber = (short) (flowStatsPeriod / tickPeriod); - private static short descriptionTickNumber = (short) (descriptionStatsPeriod / tickPeriod); - private static short portTickNumber = (short) (portStatsPeriod / tickPeriod); - private static short flowTableTickNumber = (short) (flowTableStatsPeriod / tickPeriod); - private static short factoredSamples = (short) 2; - private static short counter = 1; - private IController controller = null; - private ConcurrentMap> flowStatistics; - private ConcurrentMap> descStatistics; - private ConcurrentMap> portStatistics; - private ConcurrentMap> flowTableStatistics; - private List dummyList; - private ConcurrentMap statisticsTimerTicks; - protected BlockingQueue pendingStatsRequests; - protected BlockingQueue switchPortStatsUpdated; - private Thread statisticsCollector; - private Thread txRatesUpdater; - private Timer statisticsTimer; - private TimerTask statisticsTimerTask; - private ConcurrentMap switchSupportsVendorExtStats; - private Map> txRates; // Per port sampled (every - // portStatsPeriod) transmit - // rate - private Set descriptionListeners; - private ConcurrentMap statisticsServiceShimListener; - - /** - * The object containing the latest factoredSamples tx rate samples for a - * given switch port - */ - protected class TxRates { - Deque sampledTxBytes; // contains the latest factoredSamples - // sampled transmitted bytes - - public TxRates() { - sampledTxBytes = new LinkedBlockingDeque(); - } - - public void update(Long txBytes) { - /* - * Based on how many samples our average works on, we might have to - * remove the oldest sample - */ - if (sampledTxBytes.size() == factoredSamples) { - sampledTxBytes.removeLast(); - } - - // Add the latest sample to the top of the queue - sampledTxBytes.addFirst(txBytes); - } - - /** - * Returns the average transmit rate in bps - * - * @return the average transmit rate [bps] - */ - public long getAverageTxRate() { - long average = 0; - /* - * If we cannot provide the value for the time window length set - */ - if (sampledTxBytes.size() < factoredSamples) { - return average; - } - long increment = (long) (sampledTxBytes.getFirst() - sampledTxBytes - .getLast()); - long timePeriod = (long) (factoredSamples * portStatsPeriod) - / (long) tickPeriod; - average = (8L * increment) / timePeriod; - return average; - } - } - - public void setController(IController core) { - this.controller = core; - } - - public void unsetController(IController core) { - if (this.controller == core) { - this.controller = null; - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - flowStatistics = new ConcurrentHashMap>(); - descStatistics = new ConcurrentHashMap>(); - portStatistics = new ConcurrentHashMap>(); - flowTableStatistics = new ConcurrentHashMap>(); - dummyList = new ArrayList(1); - statisticsTimerTicks = new ConcurrentHashMap( - initialSize); - pendingStatsRequests = new LinkedBlockingQueue( - initialSize); - switchPortStatsUpdated = new LinkedBlockingQueue(initialSize); - switchSupportsVendorExtStats = new ConcurrentHashMap( - initialSize); - txRates = new HashMap>(initialSize); - descriptionListeners = new HashSet(); - - statisticsServiceShimListener = - new ConcurrentHashMap(); - configStatsPollIntervals(); - - // Initialize managed timers - statisticsTimer = new Timer(); - statisticsTimerTask = new TimerTask() { - @Override - public void run() { - decrementTicks(); - } - }; - - // Initialize Statistics collector thread - statisticsCollector = new Thread(new Runnable() { - @Override - public void run() { - while (true) { - try { - StatsRequest req = pendingStatsRequests.take(); - acquireStatistics(req.switchId, req.type); - } catch (InterruptedException e) { - log.warn("Flow Statistics Collector thread " - + "interrupted", e); - } - } - } - }, "Statistics Collector"); - - // Initialize Tx Rate Updater thread - txRatesUpdater = new Thread(new Runnable() { - @Override - public void run() { - while (true) { - try { - long switchId = switchPortStatsUpdated.take(); - updatePortsTxRate(switchId); - } catch (InterruptedException e) { - log.warn("TX Rate Updater thread interrupted", e); - } - } - } - }, "TX Rate Updater"); - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - this.statisticsServiceShimListener = null; - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - // Start managed timers - statisticsTimer.scheduleAtFixedRate(statisticsTimerTask, 0, tickPeriod); - - // Start statistics collector thread - statisticsCollector.start(); - - // Start bandwidth utilization computer thread - txRatesUpdater.start(); - - // OSGI console - registerWithOSGIConsole(); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - // Stop managed timers - statisticsTimer.cancel(); - } - - public void setStatisticsListener(IStatisticsListener s) { - this.descriptionListeners.add(s); - } - - public void unsetStatisticsListener(IStatisticsListener s) { - if (s != null) { - this.descriptionListeners.remove(s); - } - } - - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, - null); - } - - private static class StatsRequest { - protected Long switchId; - protected OFStatisticsType type; - - public StatsRequest(Long d, OFStatisticsType t) { - switchId = d; - type = t; - } - - public String toString() { - return "SReq = {switchId=" + switchId + ", type=" + type + "}"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((switchId == null) ? 0 : switchId.hashCode()); - result = prime * result + ((type == null) ? 0 : type.ordinal()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - StatsRequest other = (StatsRequest) obj; - if (switchId == null) { - if (other.switchId != null) { - return false; - } - } else if (!switchId.equals(other.switchId)) { - return false; - } - if (type != other.type) { - return false; - } - return true; - } - } - - public void setStatisticsServiceShimListener(Map props, - IStatisticsServiceShimListener s) { - if (props == null) { - log.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - log.error("containerName not supplied"); - return; - } - if ((this.statisticsServiceShimListener != null) - && !this.statisticsServiceShimListener.containsValue(s)) { - this.statisticsServiceShimListener.put(containerName, s); - log.trace("Added inventoryShimInternalListener for container:" - + containerName); - } - - } - - public void unsetStatisticsServiceShimListener(Map props, - IStatisticsServiceShimListener s) { - if (props == null) { - log.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - log.error("containerName not supplied"); - return; - } - if ((this.statisticsServiceShimListener != null) - && this.statisticsServiceShimListener - .get(containerName) != null - && this.statisticsServiceShimListener - .get(containerName).equals(s)) { - this.statisticsServiceShimListener.remove(containerName); - log.trace("Removed inventoryShimInternalListener for container: " - + containerName); - } - } - - - private void addStatisticsTicks(Long switchId) { - // Start of Change - - // By default, ODL assumes that switch supports Vendor statistics. - // It is designed in such a way that if the switch doesn't support Vendor Stats, - // then "Flow Stats" would be acquired. - - // Behavior is overridden NOT to assume default support for Vendor Stats - - //switchSupportsVendorExtStats.put(switchId, Boolean.TRUE); // Assume switch supports Vendor extension stats - switchSupportsVendorExtStats.put(switchId, Boolean.FALSE); - - // End of Change - - statisticsTimerTicks.put(switchId, new StatisticsTicks(true)); - log.info("Added Switch {} to target pool", - HexString.toHexString(switchId.longValue())); - } - - protected static class StatisticsTicks { - private short flowStatisticsTicks; - private short descriptionTicks; - private short portStatisticsTicks; - private short flowTableStatisticsTicks; - - public StatisticsTicks(boolean scattered) { - if (scattered) { - // scatter bursts by statisticsTickPeriod - if (++counter < 0) { - counter = 0; - } // being paranoid here - flowStatisticsTicks = (short) (1 + counter - % statisticsTickNumber); - descriptionTicks = (short) (1 + counter % descriptionTickNumber); - portStatisticsTicks = (short) (1 + counter % portTickNumber); - flowTableStatisticsTicks = (short) (1 + counter % flowTableTickNumber); - } else { - flowStatisticsTicks = statisticsTickNumber; - descriptionTicks = descriptionTickNumber; - portStatisticsTicks = portTickNumber; - flowTableStatisticsTicks = flowTableTickNumber; - } - } - - public boolean decrementFlowTicksIsZero() { - // Please ensure no code is inserted between the if check and the - // flowStatisticsTicks reset - if (--flowStatisticsTicks == 0) { - flowStatisticsTicks = statisticsTickNumber; - return true; - } - return false; - } - - public boolean decrementDescTicksIsZero() { - // Please ensure no code is inserted between the if check and the - // descriptionTicks reset - if (--descriptionTicks == 0) { - descriptionTicks = descriptionTickNumber; - return true; - } - return false; - } - - public boolean decrementPortTicksIsZero() { - // Please ensure no code is inserted between the if check and the - // descriptionTicks reset - if (--portStatisticsTicks == 0) { - portStatisticsTicks = portTickNumber; - return true; - } - return false; - } - - public boolean decrementFlowTableTicksIsZero() { - // Please ensure no code is inserted between the if check and the descriptionTicks reset - if (--flowTableStatisticsTicks == 0) { - flowTableStatisticsTicks = flowTableTickNumber; - return true; - } - return false; - } - - public String toString() { - return "{fT=" + flowStatisticsTicks + ",dT=" + descriptionTicks - + ",pT=" + portStatisticsTicks + ",tT=" + flowTableStatisticsTicks + "}"; - } - } - - private void printInfoMessage(String type, StatsRequest request) { - log.info( - "{} stats request not inserted for switch: {}. Queue size: {}. Collector state: {}.", - new Object[] { type, HexString.toHexString(request.switchId), - pendingStatsRequests.size(), - statisticsCollector.getState().toString() }); - } - - protected void decrementTicks() { - StatsRequest request = null; - for (Map.Entry entry : statisticsTimerTicks - .entrySet()) { - StatisticsTicks clock = entry.getValue(); - Long switchId = entry.getKey(); - if (clock.decrementFlowTicksIsZero() == true) { - request = (switchSupportsVendorExtStats.get(switchId) == Boolean.TRUE) ? new StatsRequest( - switchId, OFStatisticsType.VENDOR) : new StatsRequest( - switchId, OFStatisticsType.FLOW); - // If a request for this switch is already in the queue, skip to - // add this new request - if (!pendingStatsRequests.contains(request) - && false == pendingStatsRequests.offer(request)) { - printInfoMessage("Flow", request); - } - } - - if (clock.decrementDescTicksIsZero() == true) { - request = new StatsRequest(switchId, OFStatisticsType.DESC); - // If a request for this switch is already in the queue, skip to - // add this new request - if (!pendingStatsRequests.contains(request) - && false == pendingStatsRequests.offer(request)) { - printInfoMessage("Description", request); - } - } - - if (clock.decrementPortTicksIsZero() == true) { - request = new StatsRequest(switchId, OFStatisticsType.PORT); - // If a request for this switch is already in the queue, skip to - // add this new request - if (!pendingStatsRequests.contains(request) - && false == pendingStatsRequests.offer(request)) { - printInfoMessage("Port", request); - } - } - - if (clock.decrementFlowTableTicksIsZero() == true) { - request = new StatsRequest(switchId, OFStatisticsType.TABLE); - // If a request for this switch is already in the queue, skip to add this new request - if (!pendingStatsRequests.contains(request) - && false == pendingStatsRequests.offer(request)) { - printInfoMessage("Flow Table", request); - } - } - } - } - - private void removeStatsRequestTasks(Long switchId) { - log.info("Cleaning Statistics database for switch {}", - HexEncode.longToHexString(switchId)); - // To be safe, let's attempt removal of both VENDOR and FLOW request. It - // does not hurt - pendingStatsRequests.remove(new StatsRequest(switchId, - OFStatisticsType.VENDOR)); - pendingStatsRequests.remove(new StatsRequest(switchId, - OFStatisticsType.FLOW)); - pendingStatsRequests.remove(new StatsRequest(switchId, - OFStatisticsType.DESC)); - pendingStatsRequests.remove(new StatsRequest(switchId, - OFStatisticsType.PORT)); - pendingStatsRequests.remove(new StatsRequest(switchId, - OFStatisticsType.TABLE)); - // Take care of the TX rate databases - switchPortStatsUpdated.remove(switchId); - txRates.remove(switchId); - } - - private void clearFlowStatsAndTicks(Long switchId) { - statisticsTimerTicks.remove(switchId); - removeStatsRequestTasks(switchId); - flowStatistics.remove(switchId); - log.info("Statistics removed for switch {}", - HexString.toHexString(switchId)); - } - - private void acquireStatistics(Long switchId, OFStatisticsType statType) { - - // Query the switch on all matches - List values = this.acquireStatistics(switchId, statType, - null); - - String containerName = GlobalConstants.DEFAULT.toString(); - - // Update local caching database if got a valid response - if (values != null && !values.isEmpty()) { - if ((statType == OFStatisticsType.FLOW) - || (statType == OFStatisticsType.VENDOR)) { - flowStatistics.put(switchId, values); - - notifyStatisticsListener(containerName, statType, switchId, values); - - } else if (statType == OFStatisticsType.DESC) { - // Notify who may be interested in a description change - notifyDescriptionListeners(switchId, values); - - // Overwrite cache - descStatistics.put(switchId, values); - - notifyStatisticsListener(containerName, statType, switchId, values); - } else if (statType == OFStatisticsType.PORT) { - // Overwrite cache with new port statistics for this switch - portStatistics.put(switchId, values); - - // Wake up the thread which maintains the TX byte counters for - // each port - switchPortStatsUpdated.offer(switchId); - - notifyStatisticsListener(containerName, statType, switchId, values); - } else if (statType == OFStatisticsType.TABLE) { - - // Overwrite cache - flowTableStatistics.put(switchId, values); - - notifyStatisticsListener(containerName, statType, switchId, values); - } - } - } - - private void notifyStatisticsListener(String containerName, OFStatisticsType type, Long switchId, List values){ - - IStatisticsServiceShimListener statisticsServiceShimListener = - this.statisticsServiceShimListener.get(containerName); - - if (statisticsServiceShimListener != null) { - - switch (type) { - case FLOW: - statisticsServiceShimListener. - flowStatisticsUpdate(switchId, values, containerName); - break; - case PORT: - statisticsServiceShimListener. - portStatisticsUpdate(switchId, values, containerName); - break; - case DESC: - statisticsServiceShimListener. - descStatisticsUpdate(switchId, values, containerName); - break; - case TABLE: - statisticsServiceShimListener. - flowTableStatisticsUpdate(switchId, values, containerName); - break; - default: - break; - } - - log.trace(type + " " + switchId + " on container " - + containerName); - } - } - - private void notifyDescriptionListeners(Long switchId, - List values) { - for (IStatisticsListener l : this.descriptionListeners) { - l.descriptionRefreshed(switchId, - ((OFDescriptionStatistics) values.get(0))); - } - } - - /* - * Generic function to get the statistics form a OF switch - */ - @SuppressWarnings("unchecked") - private List acquireStatistics(Long switchId, - OFStatisticsType statsType, Object target) { - List values = null; - String type = null; - ISwitch sw = controller.getSwitch(switchId); - - if (sw != null) { - OFStatisticsRequest req = new OFStatisticsRequest(); - req.setStatisticType(statsType); - int requestLength = req.getLengthU(); - - if (statsType == OFStatisticsType.FLOW) { - OFMatch match = null; - if (target == null) { - // All flows request - match = new OFMatch(); - match.setWildcards(0xffffffff); - } else if (!(target instanceof OFMatch)) { - // Malformed request - log.warn("Invalid target type for Flow stats request: {}", - target.getClass()); - return null; - } else { - // Specific flow request - match = (OFMatch) target; - } - OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest(); - specificReq.setMatch(match); - specificReq.setOutPort(OFPort.OFPP_NONE.getValue()); - specificReq.setTableId((byte) 0xff); - req.setStatistics(Collections - .singletonList((OFStatistics) specificReq)); - requestLength += specificReq.getLength(); - type = "FLOW"; - } else if (statsType == OFStatisticsType.VENDOR) { - V6StatsRequest specificReq = new V6StatsRequest(); - specificReq.setOutPort(OFPort.OFPP_NONE.getValue()); - specificReq.setTableId((byte) 0xff); - req.setStatistics(Collections - .singletonList((OFStatistics) specificReq)); - requestLength += specificReq.getLength(); - type = "VENDOR"; - } else if (statsType == OFStatisticsType.AGGREGATE) { - OFAggregateStatisticsRequest specificReq = new OFAggregateStatisticsRequest(); - OFMatch match = new OFMatch(); - match.setWildcards(0xffffffff); - specificReq.setMatch(match); - specificReq.setOutPort(OFPort.OFPP_NONE.getValue()); - specificReq.setTableId((byte) 0xff); - req.setStatistics(Collections - .singletonList((OFStatistics) specificReq)); - requestLength += specificReq.getLength(); - type = "AGGREGATE"; - } else if (statsType == OFStatisticsType.PORT) { - short targetPort; - if (target == null) { - // All ports request - targetPort = (short) OFPort.OFPP_NONE.getValue(); - } else if (!(target instanceof Short)) { - // Malformed request - log.warn("Invalid target type for Port stats request: {}", - target.getClass()); - return null; - } else { - // Specific port request - targetPort = (Short) target; - } - OFPortStatisticsRequest specificReq = new OFPortStatisticsRequest(); - specificReq.setPortNumber(targetPort); - req.setStatistics(Collections - .singletonList((OFStatistics) specificReq)); - requestLength += specificReq.getLength(); - type = "PORT"; - } else if (statsType == OFStatisticsType.QUEUE) { - OFQueueStatisticsRequest specificReq = new OFQueueStatisticsRequest(); - specificReq.setPortNumber((short) OFPort.OFPP_ALL.getValue()); - specificReq.setQueueId(0xffffffff); - req.setStatistics(Collections - .singletonList((OFStatistics) specificReq)); - requestLength += specificReq.getLength(); - type = "QUEUE"; - } else if (statsType == OFStatisticsType.DESC) { - type = "DESC"; - } else if (statsType == OFStatisticsType.TABLE) { - type = "TABLE"; - } - req.setLengthU(requestLength); - Object result = sw.getStatistics(req); - - if (result == null) { - log.warn("Request Timed Out for ({}) from switch {}", type, - HexString.toHexString(switchId)); - } else if (result instanceof OFError) { - log.warn("Switch {} failed to handle ({}) stats request: {}", - new Object[] { HexString.toHexString(switchId), type, - Utils.getOFErrorString((OFError) result) }); - if (this.switchSupportsVendorExtStats.get(switchId) == Boolean.TRUE) { - log.warn( - "Switching back to regular Flow stats requests for switch {}", - HexString.toHexString(switchId)); - this.switchSupportsVendorExtStats.put(switchId, - Boolean.FALSE); - } - } else { - values = (List) result; - } - } - return values; - } - - @Override - public List getOFFlowStatistics(Long switchId) { - List list = flowStatistics.get(switchId); - - /* - * Check on emptiness as interference between add and get is still - * possible on the inner list (the concurrentMap entry's value) - */ - - return list; - - /* - return (list == null || list.isEmpty()) ? this.dummyList - : (list.get(0) instanceof OFVendorStatistics) ? this - .v6StatsListToOFStatsList(list) : list; - */ - } - - @Override - public List getOFFlowStatistics(Long switchId, OFMatch ofMatch) { - List statsList = flowStatistics.get(switchId); - - /* - * Check on emptiness as interference between add and get is still - * possible on the inner list (the concurrentMap entry's value) - */ - if (statsList == null || statsList.isEmpty()) { - return this.dummyList; - } - - if (statsList.get(0) instanceof OFVendorStatistics) { - /* - * Caller could provide regular OF match when we instead pull the - * vendor statistics from this node Caller is not supposed to know - * whether this switch supports vendor extensions statistics - * requests - */ - /* - V6Match targetMatch = (ofMatch instanceof V6Match) ? (V6Match) ofMatch - : new V6Match(ofMatch); - - List targetList = v6StatsListToOFStatsList(statsList); - for (OFStatistics stats : targetList) { - V6StatsReply v6Stats = (V6StatsReply) stats; - V6Match v6Match = v6Stats.getMatch(); - if (v6Match.equals(targetMatch)) { - List list = new ArrayList(); - list.add(stats); - return list; - } - } - */ - } else { - for (OFStatistics stats : statsList) { - OFFlowStatisticsReply flowStats = (OFFlowStatisticsReply) stats; - if (flowStats.getMatch().equals(ofMatch)) { - List list = new ArrayList(); - list.add(stats); - return list; - } - } - } - return this.dummyList; - } - - /* - * Converts the v6 vendor statistics to the OFStatistics - */ - /* - private List v6StatsListToOFStatsList( - List statistics) { - List v6statistics = new ArrayList(); - if (statistics != null && !statistics.isEmpty()) { - for (OFStatistics stats : statistics) { - if (stats instanceof OFVendorStatistics) { - List r = getV6ReplyStatistics((OFVendorStatistics) stats); - if (r != null) { - v6statistics.addAll(r); - } - } - } - } - return v6statistics; - } - */ - - /* - - private static List getV6ReplyStatistics( - OFVendorStatistics stat) { - int length = stat.getLength(); - List results = new ArrayList(); - if (length < 12) - return null; // Nicira Hdr is 12 bytes. We need atleast that much - ByteBuffer data = ByteBuffer.allocate(length); - stat.writeTo(data); - data.rewind(); - log.trace("getV6ReplyStatistics: Buffer BYTES ARE {}", - HexString.toHexString(data.array())); - - int vendor = data.getInt(); // first 4 bytes is vendor id. - if (vendor != V6StatsRequest.NICIRA_VENDOR_ID) { - log.warn("Unexpected vendor id: 0x{}", Integer.toHexString(vendor)); - return null; - } else { - // go ahead by 8 bytes which is 8 bytes of 0 - data.getLong(); // should be all 0's - length -= 12; // 4 bytes Nicira Hdr + 8 bytes from above line have - // been consumed - } - - V6StatsReply v6statsreply; - int min_len; - while (length > 0) { - v6statsreply = new V6StatsReply(); - min_len = v6statsreply.getLength(); - if (length < v6statsreply.getLength()) - break; - v6statsreply.setActionFactory(stat.getActionFactory()); - v6statsreply.readFrom(data); - if (v6statsreply.getLength() < min_len) - break; - v6statsreply.setVendorId(vendor); - log.trace("V6StatsReply: {}", v6statsreply); - length -= v6statsreply.getLength(); - results.add(v6statsreply); - } - return results; - } - */ - - @Override - public List queryStatistics(Long switchId, - OFStatisticsType statType, Object target) { - /* - * Caller does not know and it is not supposed to know whether this - * switch supports vendor extension. We adjust the target for him - */ - if (statType == OFStatisticsType.FLOW) { - if (switchSupportsVendorExtStats.get(switchId) == Boolean.TRUE) { - statType = OFStatisticsType.VENDOR; - } - } - - List list = this.acquireStatistics(switchId, statType, - target); - - return list; - - /* - return (list == null) ? null - : (statType == OFStatisticsType.VENDOR) ? v6StatsListToOFStatsList(list) - : list; - */ - } - - @Override - public List getOFDescStatistics(Long switchId) { - if (!descStatistics.containsKey(switchId)) - return this.dummyList; - - return descStatistics.get(switchId); - } - - @Override - public List getOFPortStatistics(Long switchId) { - if (!portStatistics.containsKey(switchId)) { - return this.dummyList; - } - - return portStatistics.get(switchId); - } - - @Override - public List getOFPortStatistics(Long switchId, short portId) { - if (!portStatistics.containsKey(switchId)) { - return this.dummyList; - } - List list = new ArrayList(1); - for (OFStatistics stats : portStatistics.get(switchId)) { - if (((OFPortStatisticsReply) stats).getPortNumber() == portId) { - list.add(stats); - break; - } - } - return list; - } - - @Override - public List getOFTableStatistics(Long switchId) { - if (!flowTableStatistics.containsKey(switchId)) - return this.dummyList; - - return flowTableStatistics.get(switchId); - } - - @Override - public int getFlowsNumber(long switchId) { - return this.flowStatistics.get(switchId).size(); - } - - /* - * InventoryShim replay for us all the switch addition which happened before - * we were brought up - */ - @Override - public void updateNode(Node node, UpdateType type, Set props) { - Long switchId = (Long) node.getID(); - switch (type) { - case ADDED: - addStatisticsTicks(switchId); - break; - case REMOVED: - clearFlowStatsAndTicks(switchId); - default: - } - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - // No action - } - - /** - * Update the cached port rates for this switch with the latest retrieved - * port transmit byte count - * - * @param switchId - */ - private synchronized void updatePortsTxRate(long switchId) { - List newPortStatistics = this.portStatistics - .get(switchId); - if (newPortStatistics == null) { - return; - } - Map rates = this.txRates.get(switchId); - if (rates == null) { - // First time rates for this switch are added - rates = new HashMap(); - txRates.put(switchId, rates); - } - for (OFStatistics stats : newPortStatistics) { - OFPortStatisticsReply newPortStat = (OFPortStatisticsReply) stats; - short port = newPortStat.getPortNumber(); - TxRates portRatesHolder = rates.get(port); - if (portRatesHolder == null) { - // First time rates for this port are added - portRatesHolder = new TxRates(); - rates.put(port, portRatesHolder); - } - // Get and store the number of transmitted bytes for this port - // And handle the case where agent does not support the counter - long transmitBytes = newPortStat.getTransmitBytes(); - long value = (transmitBytes < 0) ? 0 : transmitBytes; - portRatesHolder.update(value); - } - } - - @Override - public synchronized long getTransmitRate(Long switchId, Short port) { - long average = 0; - if (switchId == null || port == null) { - return average; - } - Map perSwitch = txRates.get(switchId); - if (perSwitch == null) { - return average; - } - TxRates portRates = perSwitch.get(port); - if (portRates == null) { - return average; - } - return portRates.getAverageTxRate(); - } - - /* - * Manual switch name configuration code - */ - @Override - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("---OF Statistics Manager utilities---\n"); - help.append("\t ofdumpstatsmgr - " - + "Print Internal Stats Mgr db\n"); - help.append("\t ofstatsmgrintervals (in seconds) - " - + "Set/Show flow/port/dedscription/table stats poll intervals\n"); - return help.toString(); - } - - private boolean isValidSwitchId(String switchId) { - String regexDatapathID = "^([0-9a-fA-F]{1,2}[:-]){7}[0-9a-fA-F]{1,2}$"; - String regexDatapathIDLong = "^[0-9a-fA-F]{1,16}$"; - - return (switchId != null && (switchId.matches(regexDatapathID) || switchId - .matches(regexDatapathIDLong))); - } - - public long getSwitchIDLong(String switchId) { - int radix = 16; - String switchString = "0"; - - if (isValidSwitchId(switchId)) { - if (switchId.contains(":")) { - // Handle the 00:00:AA:BB:CC:DD:EE:FF notation - switchString = switchId.replace(":", ""); - } else if (switchId.contains("-")) { - // Handle the 00-00-AA-BB-CC-DD-EE-FF notation - switchString = switchId.replace("-", ""); - } else { - // Handle the 0123456789ABCDEF notation - switchString = switchId; - } - } - return Long.parseLong(switchString, radix); - } - - /* - * Internal information dump code - */ - private String prettyPrintSwitchMap(ConcurrentMap map) { - StringBuffer buffer = new StringBuffer(); - buffer.append("{"); - for (Entry entry : map.entrySet()) { - buffer.append(HexString.toHexString(entry.getKey()) + "=" - + entry.getValue().toString() + " "); - } - buffer.append("}"); - return buffer.toString(); - } - - public void _ofdumpstatsmgr(CommandInterpreter ci) { - ci.println("Global Counter: " + counter); - ci.println("Timer Ticks: " + prettyPrintSwitchMap(statisticsTimerTicks)); - ci.println("PendingStatsQueue: " + pendingStatsRequests); - ci.println("PendingStatsQueue size: " + pendingStatsRequests.size()); - ci.println("Stats Collector alive: " + statisticsCollector.isAlive()); - ci.println("Stats Collector State: " - + statisticsCollector.getState().toString()); - ci.println("StatsTimer: " + statisticsTimer.toString()); - ci.println("Flow Stats Period: " + statisticsTickNumber + " s"); - ci.println("Desc Stats Period: " + descriptionTickNumber + " s"); - ci.println("Port Stats Period: " + portTickNumber + " s"); - ci.println("Flow Table Stats Period: " + flowTableTickNumber + " s"); - } - - public void _resetSwitchCapability(CommandInterpreter ci) { - String sidString = ci.nextArgument(); - Long sid = null; - if (sidString == null) { - ci.println("Insert the switch id (numeric value)"); - return; - } - try { - sid = Long.valueOf(sidString); - this.switchSupportsVendorExtStats.put(sid, Boolean.TRUE); - ci.println("Vendor capability for switch " + sid + " set to " - + this.switchSupportsVendorExtStats.get(sid)); - } catch (NumberFormatException e) { - ci.println("Invalid switch id. Has to be numeric."); - } - - } - - public void _ofbw(CommandInterpreter ci) { - String sidString = ci.nextArgument(); - Long sid = null; - if (sidString == null) { - ci.println("Insert the switch id (numeric value)"); - return; - } - try { - sid = Long.valueOf(sidString); - } catch (NumberFormatException e) { - ci.println("Invalid switch id. Has to be numeric."); - } - if (sid != null) { - Map thisSwitchRates = txRates.get(sid); - ci.println("Bandwidth utilization (" + factoredSamples - * portTickNumber + " sec average) for switch " - + HexEncode.longToHexString(sid) + ":"); - if (thisSwitchRates == null) { - ci.println("Not available"); - } else { - for (Entry entry : thisSwitchRates.entrySet()) { - ci.println("Port: " + entry.getKey() + ": " - + entry.getValue().getAverageTxRate() + " bps"); - } - } - } - } - - public void _txratewindow(CommandInterpreter ci) { - String averageWindow = ci.nextArgument(); - short seconds = 0; - if (averageWindow == null) { - ci.println("Insert the length in seconds of the median " - + "window for tx rate"); - ci.println("Current: " + factoredSamples * portTickNumber + " secs"); - return; - } - try { - seconds = Short.valueOf(averageWindow); - } catch (NumberFormatException e) { - ci.println("Invalid period."); - } - OFStatisticsManager.factoredSamples = (short) (seconds / portTickNumber); - ci.println("New: " + factoredSamples * portTickNumber + " secs"); - } - - public void _ofstatsmgrintervals(CommandInterpreter ci) { - String flowStatsInterv = ci.nextArgument(); - String portStatsInterv = ci.nextArgument(); - String descStatsInterv = ci.nextArgument(); - String flowTableStatsInterv = ci.nextArgument(); - - if (flowStatsInterv == null || portStatsInterv == null - || descStatsInterv == null || flowTableStatsInterv == null) { - ci.println("Usage: ostatsmgrintervals (in seconds)"); - ci.println("Current Values: fP=" + statisticsTickNumber + "s pP=" - + portTickNumber + "s dP=" + descriptionTickNumber + - "s tP=" + flowTableTickNumber + "s"); - return; - } - Short fP, pP, dP, tP; - try { - fP = Short.parseShort(flowStatsInterv); - pP = Short.parseShort(portStatsInterv); - dP = Short.parseShort(descStatsInterv); - tP = Short.parseShort(flowTableStatsInterv); - } catch (Exception e) { - ci.println("Invalid format values: " + e.getMessage()); - return; - } - - if (pP <= 1 || fP <= 1 || dP <= 1 || tP <= 1) { - ci.println("Invalid values. fP, pP, dP, tP have to be greater than 1."); - return; - } - - statisticsTickNumber = fP; - portTickNumber = pP; - descriptionTickNumber = dP; - flowTableTickNumber = tP; - - - ci.println("New Values: fP=" + statisticsTickNumber + "s pP=" - + portTickNumber + "s dP=" + descriptionTickNumber + - "s tP=" + flowTableTickNumber + "s"); - } - - /** - * This method retrieves user configurations from config.ini and updates - * statisticsTickNumber/portTickNumber/descriptionTickNumber/flowTableTickNumber accordingly. - */ - private void configStatsPollIntervals() { - String fsStr = System.getProperty("of.flowStatsPollInterval"); - String psStr = System.getProperty("of.portStatsPollInterval"); - String dsStr = System.getProperty("of.descStatsPollInterval"); - String tsStr = System.getProperty("of.flowTableStatsPollInterval"); - Short fs, ps, ds, ts; - - if (fsStr != null) { - try { - fs = Short.parseShort(fsStr); - if (fs > 0) { - statisticsTickNumber = fs; - } - } catch (Exception e) { - } - } - - if (psStr != null) { - try { - ps = Short.parseShort(psStr); - if (ps > 0) { - portTickNumber = ps; - } - } catch (Exception e) { - } - } - - if (dsStr != null) { - try { - ds = Short.parseShort(dsStr); - if (ds > 0) { - descriptionTickNumber = ds; - } - } catch (Exception e) { - } - } - if (tsStr != null) { - try { - ts = Short.parseShort(dsStr); - if (ts > 0) { - flowTableTickNumber = ts; - } - } catch (Exception e) { - } - } - - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortConverter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortConverter.java deleted file mode 100644 index 0b605ab875..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType; -import org.opendaylight.controller.sal.utils.NetUtils; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.openflow.protocol.OFPort; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Abstract class which provides the utilities for converting the Openflow port - * number to the equivalent NodeConnector and vice versa - * - * - * - */ -public abstract class PortConverter { - private static final Logger log = LoggerFactory - .getLogger(PortConverter.class); - private static final int maxOFPhysicalPort = NetUtils - .getUnsignedShort(OFPort.OFPP_MAX.getValue()); - - /** - * Converts the Openflow port number to the equivalent NodeConnector. - */ - public static NodeConnector toNodeConnector(short ofPort, Node node) { - // Restore original OF unsigned 16 bits value for the comparison - int unsignedOFPort = NetUtils.getUnsignedShort(ofPort); - log.trace("Openflow port number signed: {} unsigned: {}", ofPort, - unsignedOFPort); - if (unsignedOFPort > maxOFPhysicalPort) { - if (ofPort == OFPort.OFPP_LOCAL.getValue()) { - return NodeConnectorCreator.createNodeConnector( - NodeConnectorIDType.SWSTACK, - NodeConnector.SPECIALNODECONNECTORID, node); - } else if (ofPort == OFPort.OFPP_NORMAL.getValue()) { - return NodeConnectorCreator.createNodeConnector( - NodeConnectorIDType.HWPATH, - NodeConnector.SPECIALNODECONNECTORID, node); - } else if (ofPort == OFPort.OFPP_CONTROLLER.getValue()) { - return NodeConnectorCreator.createNodeConnector( - NodeConnectorIDType.CONTROLLER, - NodeConnector.SPECIALNODECONNECTORID, node); - } - } - return NodeConnectorCreator.createNodeConnector(ofPort, node); - } - - /** - * Converts the NodeConnector to the equivalent Openflow port number - */ - public static short toOFPort(NodeConnector salPort) { - log.trace("SAL Port", salPort); - if (salPort.getType().equals(NodeConnectorIDType.SWSTACK)) { - return OFPort.OFPP_LOCAL.getValue(); - } else if (salPort.getType().equals(NodeConnectorIDType.HWPATH)) { - return OFPort.OFPP_NORMAL.getValue(); - } else if (salPort.getType().equals(NodeConnectorIDType.CONTROLLER)) { - return OFPort.OFPP_CONTROLLER.getValue(); - } - return (Short) salPort.getID(); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java deleted file mode 100644 index b18eae971b..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/PortStatisticsConverter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; -import org.opendaylight.controller.sal.utils.NodeCreator; -import org.openflow.protocol.statistics.OFPortStatisticsReply; -import org.openflow.protocol.statistics.OFStatistics; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Converts an openflow list of port statistics in a SAL list of - * NodeConnectorStatistics objects - * - * - * - */ -public class PortStatisticsConverter { - private static final Logger log = LoggerFactory - .getLogger(PortStatisticsConverter.class); - private long switchId; - private List ofStatsList; - private List ncStatsList; - - public PortStatisticsConverter(long switchId, List statsList) { - this.switchId = switchId; - if (statsList == null || statsList.isEmpty()) { - this.ofStatsList = new ArrayList(1); // dummy list - } else { - this.ofStatsList = new ArrayList(statsList); - } - this.ncStatsList = null; - } - - public List getNodeConnectorStatsList() { - if (this.ofStatsList != null && this.ncStatsList == null) { - this.ncStatsList = new ArrayList(); - OFPortStatisticsReply ofPortStat; - Node node = NodeCreator.createOFNode(switchId); - for (OFStatistics ofStat : this.ofStatsList) { - ofPortStat = (OFPortStatisticsReply) ofStat; - NodeConnectorStatistics NCStat = new NodeConnectorStatistics(); - NCStat.setNodeConnector(PortConverter.toNodeConnector( - ofPortStat.getPortNumber(), node)); - NCStat.setReceivePacketCount(ofPortStat.getreceivePackets()); - NCStat.setTransmitPacketCount(ofPortStat.getTransmitPackets()); - NCStat.setReceiveByteCount(ofPortStat.getReceiveBytes()); - NCStat.setTransmitByteCount(ofPortStat.getTransmitBytes()); - NCStat.setReceiveDropCount(ofPortStat.getReceiveDropped()); - NCStat.setTransmitDropCount(ofPortStat.getTransmitDropped()); - NCStat.setReceiveErrorCount(ofPortStat.getreceiveErrors()); - NCStat.setTransmitErrorCount(ofPortStat.getTransmitErrors()); - NCStat.setReceiveFrameErrorCount(ofPortStat - .getReceiveFrameErrors()); - NCStat.setReceiveOverRunErrorCount(ofPortStat - .getReceiveOverrunErrors()); - NCStat.setReceiveCRCErrorCount(ofPortStat.getReceiveCRCErrors()); - NCStat.setCollisionCount(ofPortStat.getCollisions()); - this.ncStatsList.add(NCStat); - } - } - log.trace("OFStatistics: {} NodeConnectorStatistics: {}", ofStatsList, - ncStatsList); - return this.ncStatsList; - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadService.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadService.java deleted file mode 100644 index 9ff3d21ff0..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadService.java +++ /dev/null @@ -1,149 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Dictionary; -import java.util.List; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.Node.NodeIDType; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.reader.FlowOnNode; -import org.opendaylight.controller.sal.reader.IPluginInReadService; -import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; -import org.opendaylight.controller.sal.reader.NodeDescription; - -/** - * Container Instance of IPluginInReadService implementation class - * - * - * - */ -public class ReadService implements IPluginInReadService { - private static final Logger logger = LoggerFactory - .getLogger(ReadService.class); - private IPluginReadServiceFilter filter; - private String containerName; - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - @SuppressWarnings("unchecked") - void init(Component c) { - Dictionary props = c.getServiceProperties(); - containerName = (props != null) ? (String) props.get("containerName") - : null; - } - - /** - * Function called by the dependency manager when at least one - * dependency become unsatisfied or when the component is shutting - * down because for example bundle is being stopped. - * - */ - void destroy() { - } - - /** - * Function called by dependency manager after "init ()" is called - * and after the services provided by the class are registered in - * the service registry - * - */ - void start() { - } - - /** - * Function called by the dependency manager before the services - * exported by the component are unregistered, this will be - * followed by a "destroy ()" calls - * - */ - void stop() { - } - - public void setService(IPluginReadServiceFilter filter) { - this.filter = filter; - } - - public void unsetService(IPluginReadServiceFilter filter) { - this.filter = null; - } - - @Override - public FlowOnNode readFlow(Node node, Flow flow, boolean cached) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return null; - } - - return filter.readFlow(containerName, node, flow, cached); - } - - @Override - public List readAllFlow(Node node, boolean cached) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return null; - } - - return filter.readAllFlow(containerName, node, cached); - } - - @Override - public NodeDescription readDescription(Node node, boolean cached) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return null; - } - - return filter.readDescription(node, cached); - } - - @Override - public NodeConnectorStatistics readNodeConnector(NodeConnector connector, - boolean cached) { - if (!connector.getNode().getType() - .equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return null; - } - return filter.readNodeConnector(containerName, connector, cached); - } - - @Override - public List readAllNodeConnector(Node node, - boolean cached) { - if (!node.getType().equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return null; - } - - return filter.readAllNodeConnector(containerName, node, cached); - } - - @Override - public long getTransmitRate(NodeConnector connector) { - if (!connector.getNode().getType() - .equals(NodeIDType.OPENFLOW)) { - logger.error("Invalid node type"); - return 0; - } - return filter.getTransmitRate(containerName, connector); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java deleted file mode 100644 index 73c703e2de..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java +++ /dev/null @@ -1,421 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; -import org.opendaylight.controller.protocol_plugin.openflow.IPluginReadServiceFilter; -import org.opendaylight.controller.protocol_plugin.openflow.core.IController; -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.statistics.OFPortStatisticsReply; -import org.openflow.protocol.statistics.OFStatistics; -import org.openflow.protocol.statistics.OFStatisticsType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.action.Action; -import org.opendaylight.controller.sal.action.ActionType; -import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.match.Match; -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.reader.FlowOnNode; -import org.opendaylight.controller.sal.reader.NodeConnectorStatistics; -import org.opendaylight.controller.sal.reader.NodeDescription; -import org.opendaylight.controller.sal.utils.GlobalConstants; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.opendaylight.controller.sal.utils.NodeCreator; - -/** - * Read Service shim layer which is in charge of filtering the flow statistics - * based on container. It is a Global instance. - * - * - * - */ -public class ReadServiceFilter implements IPluginReadServiceFilter, - IContainerListener { - private static final Logger logger = LoggerFactory - .getLogger(ReadServiceFilter.class); - private IController controller = null; - private IOFStatisticsManager statsMgr = null; - private Map> containerToNc; - - public void setController(IController core) { - this.controller = core; - } - - public void unsetController(IController core) { - if (this.controller == core) { - this.controller = null; - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - containerToNc = new HashMap>(); - } - - /** - * Function called by the dependency manager when at least one - * dependency become unsatisfied or when the component is shutting - * down because for example bundle is being stopped. - * - */ - void destroy() { - } - - /** - * Function called by dependency manager after "init ()" is called - * and after the services provided by the class are registered in - * the service registry - * - */ - void start() { - } - - /** - * Function called by the dependency manager before the services - * exported by the component are unregistered, this will be - * followed by a "destroy ()" calls - * - */ - void stop() { - } - - public void setService(IOFStatisticsManager service) { - this.statsMgr = service; - } - - public void unsetService(IOFStatisticsManager service) { - this.statsMgr = null; - } - - @Override - public FlowOnNode readFlow(String container, Node node, Flow flow, - boolean cached) { - - if (controller == null) { - // Avoid to provide cached statistics if controller went down. - // They are not valid anymore anyway - logger.error("Internal plugin error"); - return null; - } - - long sid = (Long) node.getID(); - OFMatch ofMatch = new FlowConverter(flow).getOFMatch(); - List ofList = (cached == true) ? statsMgr - .getOFFlowStatistics(sid, ofMatch) : statsMgr.queryStatistics( - sid, OFStatisticsType.FLOW, ofMatch); - - /* - * Convert and filter the statistics per container - */ - List flowOnNodeList = new FlowStatisticsConverter(ofList) - .getFlowOnNodeList(node); - List filteredList = filterFlowListPerContainer(container, - node, flowOnNodeList); - - return (filteredList == null || filteredList.isEmpty()) ? null - : filteredList.get(0); - } - - @Override - public List readAllFlow(String container, Node node, - boolean cached) { - - long sid = (Long) node.getID(); - List ofList = (cached == true) ? statsMgr - .getOFFlowStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.FLOW, null); - - /* - * Convert and filter the statistics per container - */ - List flowOnNodeList = new FlowStatisticsConverter(ofList) - .getFlowOnNodeList(node); - List filteredList = filterFlowListPerContainer(container, - node, flowOnNodeList); - - return (filteredList == null) ? null : filteredList; - - } - - @Override - public NodeDescription readDescription(Node node, boolean cached) { - - if (controller == null) { - logger.error("Internal plugin error"); - return null; - } - - long sid = (Long) node.getID(); - List ofList = (cached == true) ? statsMgr - .getOFDescStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.DESC, null); - - return new DescStatisticsConverter(ofList).getHwDescription(); - } - - /** - * Filters a list of FlowOnNode elements based on the container - * - * @param container - * @param nodeId - * @param list - * @return - */ - public List filterFlowListPerContainer(String container, - Node nodeId, List list) { - if (list == null) { - return null; - } - - // Create new filtered list of flows - List newList = new ArrayList(); - - for (FlowOnNode target : list) { - // Check whether the described flow (match + actions) belongs to this container - if (flowBelongToContainer(container, nodeId, target.getFlow())) { - newList.add(target); - } - } - - return newList; - } - - /** - * Filters a list of FlowOnNode elements based on the container - * - * @param container - * @param nodeId - * @param list - * @return - */ - public List filterPortListPerContainer(String container, - long switchId, List list) { - if (list == null) { - return null; - } - - // Create new filtered list of flows - List newList = new ArrayList(); - - for (OFStatistics stat : list) { - OFPortStatisticsReply target = (OFPortStatisticsReply) stat; - NodeConnector nc = NodeConnectorCreator.createOFNodeConnector( - target.getPortNumber(), NodeCreator.createOFNode(switchId)); - if (containerOwnsNodeConnector(container, nc)) { - newList.add(target); - } - } - - return newList; - } - - /** - * Returns whether the specified flow (flow match + actions) - * belongs to the container - * - * @param container - * @param node - * @param flow - * @return true if it belongs - */ - public boolean flowBelongToContainer(String container, Node node, Flow flow) { - // All flows belong to the default container - if (container.equals(GlobalConstants.DEFAULT.toString())) { - return true; - } - return (flowPortsBelongToContainer(container, node, flow) - && flowVlanBelongsToContainer(container, node, flow) && flowSpecAllowsFlow( - container, flow.getMatch())); - } - - /** - * Returns whether the passed NodeConnector belongs to the container - * - * @param container container name - * @param p node connector to test - * @return true if belongs false otherwise - */ - public boolean containerOwnsNodeConnector(String container, NodeConnector p) { - // All node connectors belong to the default container - if (container.equals(GlobalConstants.DEFAULT.toString())) { - return true; - } - Set portSet = containerToNc.get(container); - return (portSet == null) ? false : portSet.contains(p); - } - - /** - * Returns whether the container flowspec allows the passed flow - * - * @param container - * @param match - * @return - */ - private boolean flowSpecAllowsFlow(String container, Match match) { - return true; // Always true for now - } - - /** - * Check whether the vlan field in the flow match is the same - * of the static vlan configured for the container - * - * @param container - * @param node - * @param flow - * @return - */ - private boolean flowVlanBelongsToContainer(String container, Node node, - Flow flow) { - return true; // Always true for now - } - - /** - * Check whether the ports in the flow match and flow actions for - * the specified node belong to the container - * - * @param container - * @param node - * @param flow - * @return - */ - private boolean flowPortsBelongToContainer(String container, Node node, - Flow flow) { - Match m = flow.getMatch(); - if (m.isPresent(MatchType.IN_PORT)) { - NodeConnector inPort = (NodeConnector) m - .getField(MatchType.IN_PORT).getValue(); - - // If the incoming port is specified, check if it belongs to - if (!containerOwnsNodeConnector(container, inPort)) { - return false; - } - } - - // If an outgoing port is specified, it must belong to this container - for (Action action : flow.getActions()) { - if (action.getType() == ActionType.OUTPUT) { - NodeConnector outPort = (NodeConnector) ((Output) action) - .getPort(); - if (!containerOwnsNodeConnector(container, outPort)) { - return false; - } - } - } - return true; - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType type) { - Set target = null; - - switch (type) { - case ADDED: - if (!containerToNc.containsKey(containerName)) { - containerToNc.put(containerName, new HashSet()); - } - containerToNc.get(containerName).add(p); - break; - case CHANGED: - break; - case REMOVED: - target = containerToNc.get(containerName); - if (target != null) { - target.remove(p); - } - break; - default: - } - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - // Not interested in this event - } - - @Override - public void containerModeUpdated(UpdateType t) { - // do nothing - } - - @Override - public NodeConnectorStatistics readNodeConnector(String containerName, - NodeConnector connector, boolean cached) { - if (!containerOwnsNodeConnector(containerName, connector)) { - return null; - } - Node node = connector.getNode(); - long sid = (Long) node.getID(); - short portId = (Short) connector.getID(); - List ofList = (cached == true) ? statsMgr - .getOFPortStatistics(sid, portId) : statsMgr.queryStatistics( - sid, OFStatisticsType.PORT, portId); - - List ncStatistics = new PortStatisticsConverter( - sid, ofList).getNodeConnectorStatsList(); - return (ncStatistics.isEmpty()) ? new NodeConnectorStatistics() - : ncStatistics.get(0); - } - - @Override - public List readAllNodeConnector( - String containerName, Node node, boolean cached) { - - long sid = (Long) node.getID(); - List ofList = (cached == true) ? statsMgr - .getOFPortStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.FLOW, null); - - List filteredList = filterPortListPerContainer( - containerName, sid, ofList); - - return new PortStatisticsConverter(sid, filteredList) - .getNodeConnectorStatsList(); - } - - @Override - public long getTransmitRate(String containerName, NodeConnector connector) { - if (!containerOwnsNodeConnector(containerName, connector)) { - return 0; - } - - long switchId = (Long) connector.getNode().getID(); - short port = (Short) connector.getID(); - - return statsMgr.getTransmitRate(switchId, port); - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java deleted file mode 100644 index e80f2ae5ea..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServiceShim.java +++ /dev/null @@ -1,704 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.LinkedBlockingQueue; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.eclipse.osgi.framework.console.CommandInterpreter; -import org.eclipse.osgi.framework.console.CommandProvider; -import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener; -import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsManager; -import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider; -import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.Bandwidth; -import org.opendaylight.controller.sal.core.Config; -import org.opendaylight.controller.sal.core.ContainerFlow; -import org.opendaylight.controller.sal.core.Edge; -import org.opendaylight.controller.sal.core.IContainerListener; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.State; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.discovery.IDiscoveryService; -import org.opendaylight.controller.sal.utils.GlobalConstants; - -/** - * The class describes a shim layer that relays the topology events from - * OpenFlow core to various listeners. The notifications are filtered based on - * container configurations. - */ -public class TopologyServiceShim implements IDiscoveryService, - IContainerListener, CommandProvider, IRefreshInternalProvider, - IInventoryShimExternalListener { - protected static final Logger logger = LoggerFactory - .getLogger(TopologyServiceShim.class); - private ConcurrentMap topologyServiceShimListeners = new ConcurrentHashMap(); - private ConcurrentMap> containerMap = new ConcurrentHashMap>(); - private ConcurrentMap>>> edgeMap = new ConcurrentHashMap>>>(); - - private BlockingQueue notifyQ; - private Thread notifyThread; - private BlockingQueue bulkNotifyQ; - private Thread ofPluginTopoBulkUpdate; - private volatile Boolean shuttingDown = false; - private IOFStatisticsManager statsMgr; - private Timer pollTimer; - private TimerTask txRatePoller; - private Thread bwUtilNotifyThread; - private BlockingQueue bwUtilNotifyQ; - private List connectorsOverUtilized; - private float bwThresholdFactor = (float) 0.8; // Threshold = 80% of link - // bandwidth - - class NotifyEntry { - String container; - Pair> edgeProps; - UpdateType type; - - NotifyEntry(String container, Pair> edgeProps, - UpdateType type) { - this.container = container; - this.edgeProps = edgeProps; - this.type = type; - } - } - - class TopologyNotify implements Runnable { - private final BlockingQueue notifyQ; - - TopologyNotify(BlockingQueue notifyQ) { - this.notifyQ = notifyQ; - } - - public void run() { - while (true) { - try { - NotifyEntry entry = notifyQ.take(); - - ITopologyServiceShimListener topologServiceShimListener = topologyServiceShimListeners - .get(entry.container); - topologServiceShimListener.edgeUpdate( - entry.edgeProps.getLeft(), entry.type, - entry.edgeProps.getRight()); - - entry = null; - } catch (InterruptedException e1) { - logger.warn("TopologyNotify interrupted {}", e1.getMessage()); - if (shuttingDown) { - return; - } - } catch (Exception e2) { - logger.error("",e2); - } - } - } - } - - class UtilizationUpdate { - NodeConnector connector; - UpdateType type; - - UtilizationUpdate(NodeConnector connector, UpdateType type) { - this.connector = connector; - this.type = type; - } - } - - class BwUtilizationNotify implements Runnable { - private final BlockingQueue notifyQ; - - BwUtilizationNotify(BlockingQueue notifyQ) { - this.notifyQ = notifyQ; - } - - public void run() { - while (true) { - try { - UtilizationUpdate update = notifyQ.take(); - NodeConnector connector = update.connector; - Set containerList = edgeMap.keySet(); - for (String container : containerList) { - Map>> edgePropsMap = edgeMap - .get(container); - Edge edge = edgePropsMap.get(connector).getLeft(); - if (edge.getTailNodeConnector().equals(connector)) { - ITopologyServiceShimListener topologServiceShimListener = topologyServiceShimListeners - .get(container); - if (update.type == UpdateType.ADDED) { - topologServiceShimListener - .edgeOverUtilized(edge); - } else { - topologServiceShimListener - .edgeUtilBackToNormal(edge); - } - } - } - } catch (InterruptedException e1) { - logger.warn( - "Edge Bandwidth Utilization Notify Thread interrupted {}", - e1.getMessage()); - if (shuttingDown) { - return; - } - } catch (Exception e2) { - logger.error("",e2); - } - } - } - } - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - void init() { - logger.trace("Init called"); - connectorsOverUtilized = new ArrayList(); - notifyQ = new LinkedBlockingQueue(); - notifyThread = new Thread(new TopologyNotify(notifyQ)); - bwUtilNotifyQ = new LinkedBlockingQueue(); - bwUtilNotifyThread = new Thread(new BwUtilizationNotify(bwUtilNotifyQ)); - bulkNotifyQ = new LinkedBlockingQueue(); - ofPluginTopoBulkUpdate = new Thread(new Runnable() { - @Override - public void run() { - while (true) { - try { - String containerName = bulkNotifyQ.take(); - logger.debug("Bulk Notify container:{}", containerName); - TopologyBulkUpdate(containerName); - } catch (InterruptedException e) { - logger.warn("Topology Bulk update thread interrupted"); - if (shuttingDown) { - return; - } - } - } - } - }, "Topology Bulk Update"); - - // Initialize node connector tx bit rate poller timer - pollTimer = new Timer(); - txRatePoller = new TimerTask() { - @Override - public void run() { - pollTxBitRates(); - } - }; - - registerWithOSGIConsole(); - } - - /** - * Continuously polls the transmit bit rate for all the node connectors from - * statistics manager and trigger the warning notification upward when the - * transmit rate is above a threshold which is a percentage of the edge - * bandwidth - */ - protected void pollTxBitRates() { - Map>> globalContainerEdges = edgeMap - .get(GlobalConstants.DEFAULT.toString()); - if (globalContainerEdges == null) { - return; - } - - for (NodeConnector connector : globalContainerEdges.keySet()) { - // Skip if node connector belongs to production switch - if (connector.getType().equals( - NodeConnector.NodeConnectorIDType.PRODUCTION)) { - continue; - } - - // Get edge for which this node connector is head - Pair> props = this.edgeMap.get( - GlobalConstants.DEFAULT.toString()).get(connector); - // On switch mgr restart the props get reset - if (props == null) { - continue; - } - Set propSet = props.getRight(); - if (propSet == null) { - continue; - } - - float bw = 0; - for (Property prop : propSet) { - if (prop instanceof Bandwidth) { - bw = ((Bandwidth) prop).getValue(); - break; - } - } - - // Skip if agent did not provide a bandwidth info for the edge - if (bw == 0) { - continue; - } - - // Compare bandwidth usage - Long switchId = (Long) connector.getNode().getID(); - Short port = (Short) connector.getID(); - float rate = statsMgr.getTransmitRate(switchId, port); - if (rate > bwThresholdFactor * bw) { - if (!connectorsOverUtilized.contains(connector)) { - connectorsOverUtilized.add(connector); - this.bwUtilNotifyQ.add(new UtilizationUpdate(connector, - UpdateType.ADDED)); - } - } else { - if (connectorsOverUtilized.contains(connector)) { - connectorsOverUtilized.remove(connector); - this.bwUtilNotifyQ.add(new UtilizationUpdate(connector, - UpdateType.REMOVED)); - } - } - } - - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - logger.trace("DESTROY called!"); - notifyQ = null; - notifyThread = null; - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - logger.trace("START called!"); - notifyThread.start(); - bwUtilNotifyThread.start(); - ofPluginTopoBulkUpdate.start(); - pollTimer.scheduleAtFixedRate(txRatePoller, 10000, 5000); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - logger.trace("STOP called!"); - shuttingDown = true; - notifyThread.interrupt(); - } - - void setTopologyServiceShimListener(Map props, - ITopologyServiceShimListener s) { - if (props == null) { - logger.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("containerName not supplied"); - return; - } - if ((this.topologyServiceShimListeners != null) - && !this.topologyServiceShimListeners - .containsKey(containerName)) { - this.topologyServiceShimListeners.put(containerName, s); - logger.trace("Added topologyServiceShimListener for container: {}", - containerName); - } - } - - void unsetTopologyServiceShimListener(Map props, - ITopologyServiceShimListener s) { - if (props == null) { - logger.error("Didn't receive the service properties"); - return; - } - String containerName = (String) props.get("containerName"); - if (containerName == null) { - logger.error("containerName not supplied"); - return; - } - if ((this.topologyServiceShimListeners != null) - && this.topologyServiceShimListeners.containsKey(containerName) - && this.topologyServiceShimListeners.get(containerName).equals( - s)) { - this.topologyServiceShimListeners.remove(containerName); - logger.trace("Removed topologyServiceShimListener for container: {}", - containerName); - } - } - - void setStatisticsManager(IOFStatisticsManager s) { - this.statsMgr = s; - } - - void unsetStatisticsManager(IOFStatisticsManager s) { - if (this.statsMgr == s) { - this.statsMgr = null; - } - } - - private void removeNodeConnector(String container, - NodeConnector nodeConnector) { - Map>> edgePropsMap = edgeMap - .get(container); - if (edgePropsMap == null) { - return; - } - - // Remove edge in one direction - Pair> edgeProps = edgePropsMap.get(nodeConnector); - if (edgeProps == null) { - return; - } - notifyEdge(container, edgeProps.getLeft(), UpdateType.REMOVED, null); - - // Remove edge in another direction - edgeProps = edgePropsMap - .get(edgeProps.getLeft().getHeadNodeConnector()); - if (edgeProps == null) { - return; - } - notifyEdge(container, edgeProps.getLeft(), UpdateType.REMOVED, null); - } - - private void notifyEdge(String container, Edge edge, UpdateType type, - Set props) { - ConcurrentMap>> edgePropsMap = edgeMap - .get(container); - NodeConnector src = edge.getTailNodeConnector(); - Pair> edgeProps = new ImmutablePair>( - edge, props); - - switch (type) { - case ADDED: - case CHANGED: - if (edgePropsMap == null) { - edgePropsMap = new ConcurrentHashMap>>(); - } else { - if (edgePropsMap.containsKey(src) - && edgePropsMap.get(src).equals(edgeProps)) { - // Entry already exists. Return here. - return; - } - } - edgePropsMap.put(src, edgeProps); - edgeMap.put(container, edgePropsMap); - break; - case REMOVED: - if (edgePropsMap != null) { - edgePropsMap.remove(src); - if (edgePropsMap.isEmpty()) { - edgeMap.remove(container); - } else { - edgeMap.put(container, edgePropsMap); - } - } - break; - default: - logger.debug("notifyEdge: invalid {} for Edge {} in container {}", - type, edge, container); - return; - } - - notifyQ.add(new NotifyEntry(container, edgeProps, type)); - - logger.debug("notifyEdge: {} Edge {} in container {}", - type, edge, container); - } - - @Override - public void notifyEdge(Edge edge, UpdateType type, Set props) { - if ((edge == null) || (type == null)) { - return; - } - - // Notify default container - notifyEdge(GlobalConstants.DEFAULT.toString(), edge, type, props); - - // Notify the corresponding containers - List containers = getEdgeContainers(edge); - if (containers != null) { - for (String container : containers) { - notifyEdge(container, edge, type, props); - } - } - } - - /* - * Return a list of containers the edge associated with - */ - private List getEdgeContainers(Edge edge) { - NodeConnector src = edge.getTailNodeConnector(), dst = edge - .getHeadNodeConnector(); - - if (!src.getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { - /* Find the common containers for both ends */ - List srcContainers = this.containerMap.get(src), dstContainers = this.containerMap - .get(dst), cmnContainers = null; - if ((srcContainers != null) && (dstContainers != null)) { - cmnContainers = new ArrayList(srcContainers); - cmnContainers.retainAll(dstContainers); - } - return cmnContainers; - } else { - /* - * If the neighbor is part of a monitored production network, get - * the containers that the edge port belongs to - */ - return this.containerMap.get(dst); - } - } - - @Override - public void tagUpdated(String containerName, Node n, short oldTag, - short newTag, UpdateType t) { - } - - @Override - public void containerFlowUpdated(String containerName, - ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) { - } - - @Override - public void nodeConnectorUpdated(String containerName, NodeConnector p, - UpdateType t) { - if (this.containerMap == null) { - logger.error("containerMap is NULL"); - return; - } - List containers = this.containerMap.get(p); - if (containers == null) { - containers = new CopyOnWriteArrayList(); - } - boolean updateMap = false; - switch (t) { - case ADDED: - if (!containers.contains(containerName)) { - containers.add(containerName); - updateMap = true; - } - break; - case REMOVED: - if (containers.contains(containerName)) { - containers.remove(containerName); - updateMap = true; - removeNodeConnector(containerName, p); - } - break; - case CHANGED: - break; - } - if (updateMap) { - if (containers.isEmpty()) { - // Do cleanup to reduce memory footprint if no - // elements to be tracked - this.containerMap.remove(p); - } else { - this.containerMap.put(p, containers); - } - } - } - - @Override - public void containerModeUpdated(UpdateType t) { - // do nothing - } - - private void registerWithOSGIConsole() { - BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) - .getBundleContext(); - bundleContext.registerService(CommandProvider.class.getName(), this, - null); - } - - @Override - public String getHelp() { - StringBuffer help = new StringBuffer(); - help.append("---Topology Service Shim---\n"); - help.append("\t pem [container] - Print edgeMap entries"); - help.append(" for a given container\n"); - return help.toString(); - } - - public void _pem(CommandInterpreter ci) { - String container = ci.nextArgument(); - if (container == null) { - container = GlobalConstants.DEFAULT.toString(); - } - - ci.println("Container: " + container); - ci.println(" Edge Bandwidth"); - - Map>> edgePropsMap = edgeMap - .get(container); - if (edgePropsMap == null) { - return; - } - int count = 0; - for (Pair> edgeProps : edgePropsMap.values()) { - if (edgeProps == null) { - continue; - } - - long bw = 0; - for (Property prop : edgeProps.getRight()) { - if (prop.getName().equals(Bandwidth.BandwidthPropName)) { - bw = ((Bandwidth) prop).getValue(); - } - } - count++; - ci.println(edgeProps.getLeft() + " " + bw); - } - ci.println("Total number of Edges: " + count); - } - - public void _bwfactor(CommandInterpreter ci) { - String factorString = ci.nextArgument(); - if (factorString == null) { - ci.println("Bw threshold: " + this.bwThresholdFactor); - ci.println("Insert a non null bw threshold"); - return; - } - bwThresholdFactor = Float.parseFloat(factorString); - ci.println("New Bw threshold: " + this.bwThresholdFactor); - } - - /** - * This method will trigger topology updates to be sent toward SAL. SAL then - * pushes the updates to ALL the applications that have registered as - * listeners for this service. SAL has no way of knowing which application - * requested for the refresh. - * - * As an example of this case, is stopping and starting the Topology - * Manager. When the topology Manager is stopped, and restarted, it will no - * longer have the latest topology. Hence, a request is sent here. - * - * @param containerName - * @return void - */ - @Override - public void requestRefresh(String containerName) { - // wake up a bulk update thread and exit - // the thread will execute the bulkUpdate() - bulkNotifyQ.add(containerName); - } - - /** - * Reading the current topology database, the method will replay all the - * edge updates for the ITopologyServiceShimListener instance in the given - * container, which will in turn publish them toward SAL. - * - * @param containerName - */ - private void TopologyBulkUpdate(String containerName) { - Map>> edgePropMap = null; - - logger.debug("Try bulk update for container:{}", containerName); - edgePropMap = edgeMap.get(containerName); - if (edgePropMap == null) { - logger.debug("No edges known for container:{}", containerName); - return; - } - ITopologyServiceShimListener topologServiceShimListener = topologyServiceShimListeners - .get(containerName); - if (topologServiceShimListener == null) { - logger.debug("No topology service shim listener for container:{}", - containerName); - return; - } - int i = 0; - for (Pair> edgeProps : edgePropMap.values()) { - if (edgeProps != null) { - i++; - logger.trace("Add edge {}", edgeProps.getLeft()); - topologServiceShimListener.edgeUpdate(edgeProps.getLeft(), - UpdateType.ADDED, edgeProps.getRight()); - } - } - logger.debug("Sent {} updates", i); - } - - @Override - public void updateNode(Node node, UpdateType type, Set props) { - } - - @Override - public void updateNodeConnector(NodeConnector nodeConnector, - UpdateType type, Set props) { - List containers = new ArrayList(); - List conList = this.containerMap.get(nodeConnector); - - containers.add(GlobalConstants.DEFAULT.toString()); - if (conList != null) { - containers.addAll(conList); - } - - switch (type) { - case ADDED: - break; - case CHANGED: - if (props == null) { - break; - } - - boolean rmEdge = false; - for (Property prop : props) { - if (((prop instanceof Config) && (((Config) prop).getValue() != Config.ADMIN_UP)) - || ((prop instanceof State) && (((State) prop) - .getValue() != State.EDGE_UP))) { - /* - * If port admin down or link down, remove the edges - * associated with the port - */ - rmEdge = true; - break; - } - } - - if (rmEdge) { - for (String cName : containers) { - removeNodeConnector(cName, nodeConnector); - } - } - break; - case REMOVED: - for (String cName : containers) { - removeNodeConnector(cName, nodeConnector); - } - break; - default: - break; - } - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServices.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServices.java deleted file mode 100644 index 57b55bfecd..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/TopologyServices.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.util.Dictionary; -import java.util.Set; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider; -import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.opendaylight.controller.sal.core.Edge; -import org.opendaylight.controller.sal.core.Property; -import org.opendaylight.controller.sal.core.UpdateType; -import org.opendaylight.controller.sal.topology.IPluginInTopologyService; -import org.opendaylight.controller.sal.topology.IPluginOutTopologyService; - -public class TopologyServices implements ITopologyServiceShimListener, - IPluginInTopologyService { - protected static final Logger logger = LoggerFactory - .getLogger(TopologyServices.class); - private IPluginOutTopologyService salTopoService = null; - private IRefreshInternalProvider topoRefreshService = null; - private String containerName; - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - * - */ - @SuppressWarnings("unchecked") - void init(Component c) { - logger.trace("INIT called!"); - Dictionary props = c.getServiceProperties(); - containerName = (props != null) ? (String) props.get("containerName") - : null; - } - - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { - logger.trace("DESTROY called!"); - } - - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - logger.trace("START called!"); - } - - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - logger.trace("STOP called!"); - } - - /** - * Retrieve SAL service IPluginOutTopologyService - * - * @param s - * Called by Dependency Manager as soon as the SAL service is - * available - */ - public void setPluginOutTopologyService(IPluginOutTopologyService s) { - logger.trace("Setting IPluginOutTopologyService to: {}", s); - this.salTopoService = s; - } - - /** - * called when SAL service IPluginOutTopologyService is no longer available - * - * @param s - * Called by Dependency Manager as soon as the SAL service is - * unavailable - */ - public void unsetPluginOutTopologyService(IPluginOutTopologyService s) { - if (this.salTopoService == s) { - logger.trace("UNSetting IPluginOutTopologyService from: {}", s); - this.salTopoService = null; - } - } - - /** - * Retrieve OF protocol_plugin service IRefreshInternalProvider - * - * @param s - * Called by Dependency Manager as soon as the SAL service is - * available - */ - public void setRefreshInternalProvider(IRefreshInternalProvider s) { - logger.trace("Setting IRefreshInternalProvider to: {}", s); - this.topoRefreshService = s; - } - - /** - * called when OF protocol_plugin service IRefreshInternalProvider is no - * longer available - * - * @param s - * Called by Dependency Manager as soon as the SAL service is - * unavailable - */ - public void unsetRefreshInternalProvider(IRefreshInternalProvider s) { - if (this.topoRefreshService == s) { - logger.trace("UNSetting IRefreshInternalProvider from: {}", s); - this.topoRefreshService = null; - } - } - - @Override - public void edgeUpdate(Edge edge, UpdateType type, Set props) { - if (this.salTopoService != null) { - this.salTopoService.edgeUpdate(edge, type, props); - } - } - - @Override - public void sollicitRefresh() { - logger.debug("Got a request to refresh topology"); - topoRefreshService.requestRefresh(containerName); - } - - @Override - public void edgeOverUtilized(Edge edge) { - if (this.salTopoService != null) { - this.salTopoService.edgeOverUtilized(edge); - } - } - - @Override - public void edgeUtilBackToNormal(Edge edge) { - if (this.salTopoService != null) { - this.salTopoService.edgeUtilBackToNormal(edge); - } - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Utils.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Utils.java deleted file mode 100644 index 52f501c8cb..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/Utils.java +++ /dev/null @@ -1,79 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.nio.ByteBuffer; - -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Error; -import org.openflow.protocol.OFError; -import org.openflow.protocol.OFError.OFBadActionCode; -import org.openflow.protocol.OFError.OFBadRequestCode; -import org.openflow.protocol.OFError.OFErrorType; -import org.openflow.protocol.OFError.OFFlowModFailedCode; -import org.openflow.protocol.OFError.OFHelloFailedCode; -import org.openflow.protocol.OFError.OFPortModFailedCode; -import org.openflow.protocol.OFError.OFQueueOpFailedCode; - -public abstract class Utils { - public static String getOFErrorString(OFError error) { - // Handle VENDOR extension errors here - - /* - if (error.getErrorType() == V6Error.NICIRA_VENDOR_ERRORTYPE) { - V6Error er = new V6Error(error); - byte[] b = error.getError(); - ByteBuffer bb = ByteBuffer.allocate(b.length); - bb.put(b); - bb.rewind(); - er.readFrom(bb); - return er.toString(); - } - */ - - // Handle OF1.0 errors here - OFErrorType et = OFErrorType.values()[0xffff & error.getErrorType()]; - String errorStr = "Error : " + et.toString(); - switch (et) { - case OFPET_HELLO_FAILED: - OFHelloFailedCode hfc = OFHelloFailedCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + hfc.toString(); - break; - case OFPET_BAD_REQUEST: - OFBadRequestCode brc = OFBadRequestCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + brc.toString(); - break; - case OFPET_BAD_ACTION: - OFBadActionCode bac = OFBadActionCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + bac.toString(); - break; - case OFPET_FLOW_MOD_FAILED: - OFFlowModFailedCode fmfc = OFFlowModFailedCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + fmfc.toString(); - break; - case OFPET_PORT_MOD_FAILED: - OFPortModFailedCode pmfc = OFPortModFailedCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + pmfc.toString(); - break; - case OFPET_QUEUE_OP_FAILED: - OFQueueOpFailedCode qofc = OFQueueOpFailedCode.values()[0xffff & error - .getErrorCode()]; - errorStr += " " + qofc.toString(); - break; - default: - break; - } - return errorStr; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java deleted file mode 100644 index 06be542542..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Error.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import java.nio.ByteBuffer; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.OFError; - -public class V6Error extends OFError { - - - private static final long serialVersionUID = 1L; - public static int MINIMUM_LENGTH = 20;//OfHdr(8) + NXET_VENDOR(2) + NXEC_VENDOR_ERROR(2) + struct nx_vendor_error(8) - public static final short NICIRA_VENDOR_ERRORTYPE = (short)0xb0c2; - protected int V6VendorId; - protected short V6VendorErrorType; - protected short V6VendorErrorCode; - protected byte[] V6ErrorData; - - public V6Error(OFError e) { - this.length = (short)e.getLengthU(); - this.errorType = e.getErrorType(); - this.errorCode = e.getErrorCode(); - this.xid = e.getXid(); - } - - /* - @Override - public void readFrom(ByteBuffer data) { - this.V6VendorId = data.getInt(); - this.V6VendorErrorType = data.getShort(); - this.V6VendorErrorCode = data.getShort(); - int dataLength = this.getLengthU() - MINIMUM_LENGTH; - if (dataLength > 0) { - this.V6ErrorData = new byte[dataLength]; - data.get(this.V6ErrorData); - } - } - */ - - /** - * @return the V6VendorId - */ - public int getVendorId() { - return V6VendorId; - } - - - - /** - * @return the V6VendorErrorType - */ - /* - public short getVendorErrorType() { - return V6VendorErrorType; - } - */ - - /** - * @return the VendorErrorType - */ - public short getVendorErrorCode() { - return V6VendorErrorCode; - } - - /** - * @return the Error Bytes - */ - public byte[] getError() { - return V6ErrorData; - } - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - - @Override - public String toString() { - return "V6Error[" + ReflectionToStringBuilder.toString(this) + "]"; - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6FlowMod.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6FlowMod.java deleted file mode 100644 index 513ac5e08e..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6FlowMod.java +++ /dev/null @@ -1,244 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.OFPacketOut; -import org.openflow.protocol.OFPort; -import org.openflow.protocol.OFVendor; -import org.openflow.protocol.action.OFAction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class is used to create IPv6 Vendor Extension messages. Specfically, It - * defines the methods used in creation of Vendor specific IPv6 Flow Mod message. - * - * - */ -public class V6FlowMod extends OFVendor implements Cloneable { - private static final Logger logger = LoggerFactory - .getLogger(V6FlowMod.class); - private static final long serialVersionUID = 1L; - protected V6Match match; - protected long cookie; - protected short command; - protected short idleTimeout; - protected short hardTimeout; - protected short priority; - protected int bufferId; - protected short outPort; - protected short flags; - protected List actions; - short match_len; - short actions_len; - short pad_size; - - private static int IPV6EXT_ADD_FLOW_MSG_TYPE = 13; - private static int IPV6_EXT_MIN_HDR_LEN = 36; - - /** - * Constructor for the V6FlowMod class. Initializes OFVendor (parent class) - * fields by calling the parent class' constructor. - */ - public V6FlowMod() { - super(); - } - - /** - * This method sets the match fields of V6FlowMod object - * @param match V6Match object for this V6FlowMod message - */ - public void setMatch(V6Match match) { - this.match = match; - } - - /** - * Sets the list of actions V6FlowMod message - * @param actions a list of ordered OFAction objects - */ - public void setActions(List actions) { - this.actions = actions; - } - - /** - * Sets the priority field of V6FlowMod message - * @param priority Priority of the message - */ - public void setPriority(short priority) { - this.priority = priority; - } - - /** - * Sets the cookie field of V6FlowMod message - * @param cookie Cookie of the message - */ - public void setCookie(long cookie) { - this.cookie = cookie; - } - - /** - * Sets the command field of V6FlowMod message - * @param command Command type of the message (ADD or DELETE) - */ - public V6FlowMod setCommand(short command) { - this.command = command; - return this; - } - - /** - * Sets the outPort field of V6FlowMod message - * @param outPort outPort of the message - */ - public V6FlowMod setOutPort(OFPort port) { - this.outPort = port.getValue(); - return this; - } - - /** - * Sets the idle_timeout of V6FlowMod message - * @param idleTimeout idle timeout for this message - */ - public void setIdleTimeout(short idleTimeout) { - this.idleTimeout = idleTimeout; - } - - /** - * Sets the hardTimeout field of V6FlowMod message - * @param hardTimeout hard timeout of the message - */ - public void setHardTimeout(short hardTimeout) { - this.hardTimeout = hardTimeout; - } - - /** - * Returns the Flow Mod message subtype for V6FlowMod message - * @return message subtype - */ - private int getIPv6ExtensionFlowModAddSubType() { - return IPV6EXT_ADD_FLOW_MSG_TYPE; - } - - /** - * Returns the minimum header size for V6Flow Message type - * @return minimum header size - */ - - public int getV6FlowModMinHdrSize() { - return IPV6_EXT_MIN_HDR_LEN; - } - - /** - * Sets the Vendor type in OFVendor message - */ - - public void setVendor() { - super.setVendor(V6StatsRequest.NICIRA_VENDOR_ID); - } - - /** - * Get flags - * @return - */ - public short getFlags() { - return flags; - } - - /** - * Set flags - * @param flags - */ - public void setFlags(short flags) { - this.flags = flags; - } - - /** - * This method forms the Vendor extension IPv6 Flow Mod message.It uses the - * fields in V6FlowMod class, and writes the data according to vendor - * extension format. The fields include flow properties (cookie, timeout, - * priority, etc), flow match, and action list. It also takes care of - * required padding. - */ - - /* - @Override - public void writeTo(ByteBuffer data) { - super.writeTo(data); - data.putInt(getIPv6ExtensionFlowModAddSubType()); - data.putLong(this.cookie); - data.putShort(command); // should be OFPFC_ADD, OFPFC_DELETE_STRICT, etc - data.putShort(this.idleTimeout); - data.putShort(this.hardTimeout); - data.putShort(this.priority); - data.putInt(OFPacketOut.BUFFER_ID_NONE); - data.putShort(outPort); // output_port - data.putShort(flags); // flags - match_len = this.match.getIPv6MatchLen(); - data.putShort(match_len); - byte[] pad = new byte[6]; - data.put(pad); - this.match.writeTo(data); - - pad_size = (short) (((match_len + 7) / 8) * 8 - match_len); - - /* - * action list should be preceded by a padding of 0 to 7 bytes based upon - * above formula. - */ - - /* - byte[] pad2 = new byte[pad_size]; - data.put(pad2); - if (actions != null) { - for (OFAction action : actions) { - actions_len += action.getLength(); - action.writeTo(data); - } - } - logger.trace("{}", this.toString()); - } - */ - - - /** - * Forms the clone of V6FlowMod Object. If Object is returned - * successfully, then returns the cloned object. Throws an - * exception if cloning is not supported. - */ - @Override - public V6FlowMod clone() { - try { - V6Match neoMatch = match.clone(); - V6FlowMod v6flowMod = (V6FlowMod) super.clone(); - v6flowMod.setMatch(neoMatch); - List neoActions = new LinkedList(); - for (OFAction action : this.actions) - neoActions.add((OFAction) action.clone()); - v6flowMod.setActions(neoActions); - return v6flowMod; - } catch (CloneNotSupportedException e) { - // Won't happen - throw new RuntimeException(e); - } - } - - /** - * Prints the contents of V6FlowMod in a string format. - */ - @Override - public String toString() { - return "V6FlowMod[" + ReflectionToStringBuilder.toString(this) + "]"; - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Match.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Match.java deleted file mode 100644 index bdad75f63b..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6Match.java +++ /dev/null @@ -1,1355 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.OFMatch; -import org.openflow.util.U16; -import org.openflow.util.U8; - -import java.net.Inet6Address; -import org.opendaylight.controller.sal.utils.HexEncode; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This Class forms the vendor specific IPv6 Flow Match messages as well as - * processes the vendor specific IPv6 Stats Reply message. - * - * For message creation, it parses the user entered IPv6 match fields, creates - * a sub-message for each field which are later used to form the complete - * message. - * - * For message processing, it parses the incoming message and reads each field - * of the message and stores in appropriate field of V6Match object. - * - * - */ -public class V6Match extends OFMatch implements Cloneable { - private static final Logger logger = LoggerFactory.getLogger(V6Match.class); - private static final long serialVersionUID = 1L; - protected InetAddress nwSrc; - protected InetAddress nwDst; - protected short inputPortMask; - protected byte[] dataLayerSourceMask; - protected byte[] dataLayerDestinationMask; - protected short dataLayerVirtualLanMask; - protected byte dataLayerVirtualLanPriorityCodePointMask; - protected short dataLayerTypeMask; - protected byte networkTypeOfServiceMask; - protected byte networkProtocolMask; - protected InetAddress networkSourceMask; - protected InetAddress networkDestinationMask; - protected short transportSourceMask; - protected short transportDestinationMask; - protected short srcIPv6SubnetMaskbits; - protected short dstIPv6SubnetMaskbits; - - protected MatchFieldState inputPortState; - protected MatchFieldState dlSourceState; - protected MatchFieldState dlDestState; - protected MatchFieldState dlVlanState; - protected MatchFieldState ethTypeState; - protected MatchFieldState nwTosState; - protected MatchFieldState nwProtoState; - protected MatchFieldState nwSrcState; - protected MatchFieldState nwDstState; - protected MatchFieldState tpSrcState; - protected MatchFieldState tpDstState; - protected short match_len = 0; - protected short pad_size = 0; - - private static int IPV6_EXT_MIN_HDR_LEN = 36; - - private enum MatchFieldState { - MATCH_ABSENT, MATCH_FIELD_ONLY, MATCH_FIELD_WITH_MASK - } - - private enum OF_Match_Types { - MATCH_OF_IN_PORT(0), MATCH_OF_ETH_DST(1), MATCH_OF_ETH_SRC(2), MATCH_OF_ETH_TYPE( - 3), MATCH_OF_VLAN_TCI(4), MATCH_OF_IP_TOS(5), MATCH_OF_IP_PROTO( - 6), MATCH_OF_IP_SRC(7), MATCH_OF_IP_DST(8), MATCH_OF_TCP_SRC(9), MATCH_OF_TCP_DST( - 10), MATCH_OF_UDP_SRC(11), MATCH_OF_UDP_DST(12), MATCH_OF_ICMTP_TYPE( - 13), MATCH_OF_ICMP_CODE(14), MATCH_OF_ARP_OP(15); - - private int value; - - private OF_Match_Types(int value) { - this.value = value; - } - - public int getValue() { - return this.value; - } - } - - private enum IPv6Extension_Match_Types { - MATCH_IPV6EXT_TUN_ID(16), MATCH_IPV6EXT_ARP_SHA(17), MATCH_IPV6EXT_ARP_THA( - 18), MATCH_IPV6EXT_IPV6_SRC(19), MATCH_IPV6EXT_IPV6_DST(20); - - private int value; - - private IPv6Extension_Match_Types(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - } - - public enum Extension_Types { - OF_10(0), IPV6EXT(1); - - protected int value; - - private Extension_Types(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - } - - public V6Match() { - super(); - - this.nwSrc = null; - this.nwDst = null; - - this.inputPortMask = 0; - this.dataLayerSourceMask = null; - this.dataLayerDestinationMask = null; - this.dataLayerTypeMask = 0; - this.dataLayerVirtualLanMask = 0; - this.dataLayerVirtualLanPriorityCodePointMask = 0; - this.networkDestinationMask = null; - this.networkSourceMask = null; - this.networkTypeOfServiceMask = 0; - this.networkProtocolMask = 0; - this.transportSourceMask = 0; - this.transportDestinationMask = 0; - - this.inputPortState = MatchFieldState.MATCH_ABSENT; - this.dlSourceState = MatchFieldState.MATCH_ABSENT; - this.dlDestState = MatchFieldState.MATCH_ABSENT; - this.dlVlanState = MatchFieldState.MATCH_ABSENT; - this.ethTypeState = MatchFieldState.MATCH_ABSENT; - this.nwTosState = MatchFieldState.MATCH_ABSENT; - this.nwProtoState = MatchFieldState.MATCH_ABSENT; - this.nwSrcState = MatchFieldState.MATCH_ABSENT; - this.nwDstState = MatchFieldState.MATCH_ABSENT; - this.tpSrcState = MatchFieldState.MATCH_ABSENT; - this.tpDstState = MatchFieldState.MATCH_ABSENT; - - this.match_len = 0; - this.pad_size = 0; - } - - public V6Match(OFMatch match) { - super(); - this.match_len = 0; - this.pad_size = 0; - - this.networkSourceMask = null; - if (match.getNetworkSource() != 0) { - InetAddress address = null; - try { - address = InetAddress.getByAddress(ByteBuffer.allocate(4) - .putInt(match.getNetworkSource()).array()); - } catch (UnknownHostException e) { - logger.error("",e); - } - this.setNetworkSource(address, null); - } else { - this.nwSrc = null; - this.nwSrcState = MatchFieldState.MATCH_ABSENT; - } - - this.networkDestinationMask = null; - if (match.getNetworkDestination() != 0) { - InetAddress address = null; - try { - address = InetAddress.getByAddress(ByteBuffer.allocate(4) - .putInt(match.getNetworkDestination()).array()); - } catch (UnknownHostException e) { - logger.error("",e); - } - this.setNetworkDestination(address, null); - } else { - this.nwDst = null; - this.nwDstState = MatchFieldState.MATCH_ABSENT; - } - - this.inputPortMask = 0; - if (match.getInputPort() != 0) { - this.setInputPort(match.getInputPort(), (short) 0); - } else { - this.inputPortMask = 0; - this.inputPortState = MatchFieldState.MATCH_ABSENT; - } - - this.dataLayerSourceMask = null; - if (match.getDataLayerSource() != null) { - this.setDataLayerSource(match.getDataLayerSource(), null); - } else { - this.dataLayerSource = null; - this.dlSourceState = MatchFieldState.MATCH_ABSENT; - } - this.dataLayerDestinationMask = null; - if (match.getDataLayerDestination() != null) { - this.setDataLayerDestination(match.getDataLayerDestination(), null); - } else { - this.dataLayerDestination = null; - this.dlDestState = MatchFieldState.MATCH_ABSENT; - } - - this.dataLayerTypeMask = 0; - if (match.getDataLayerType() != 0) { - this.setDataLayerType(match.getDataLayerType(), (short) 0); - } else { - this.dataLayerType = 0; - this.ethTypeState = MatchFieldState.MATCH_ABSENT; - } - - this.dataLayerVirtualLanMask = 0; - if (match.getDataLayerVirtualLan() != 0) { - this.setDataLayerVirtualLan(match.getDataLayerVirtualLan(), - (short) 0); - } else { - this.dataLayerVirtualLan = 0; - this.dlVlanState = MatchFieldState.MATCH_ABSENT; - } - - this.dataLayerVirtualLanPriorityCodePointMask = 0; - if (match.getDataLayerVirtualLanPriorityCodePoint() != 0) { - this.setDataLayerVirtualLanPriorityCodePoint(match - .getDataLayerVirtualLanPriorityCodePoint(), (byte) 0); - } else { - this.dataLayerVirtualLanPriorityCodePoint = 0; - } - - this.networkProtocolMask = 0; - if (match.getNetworkProtocol() != 0) { - this.setNetworkProtocol(this.networkProtocol = match - .getNetworkProtocol(), (byte) 0); - } else { - this.networkProtocol = 0; - this.nwProtoState = MatchFieldState.MATCH_ABSENT; - } - - this.networkTypeOfServiceMask = 0; - if (match.getNetworkTypeOfService() != 0) { - this.setNetworkTypeOfService(this.networkTypeOfService = match - .getNetworkTypeOfService(), (byte) 0); - } else { - this.networkTypeOfService = match.getNetworkTypeOfService(); - this.nwTosState = MatchFieldState.MATCH_ABSENT; - } - - this.transportSourceMask = 0; - if (match.getTransportSource() != 0) { - this.setTransportSource(match.getTransportSource(), (short) 0); - } else { - this.transportSource = 0; - this.tpSrcState = MatchFieldState.MATCH_ABSENT; - } - - this.transportDestinationMask = 0; - if (match.getTransportDestination() != 0) { - this.setTransportDestination(match.getTransportDestination(), - (short) 0); - } else { - this.transportDestination = 0; - this.tpDstState = MatchFieldState.MATCH_ABSENT; - } - - this.setWildcards(match.getWildcards()); - } - - private enum IPProtocols { - ICMP(1), TCP(6), UDP(17), ICMPV6(58); - - private int protocol; - - private IPProtocols(int value) { - this.protocol = value; - } - - private byte getValue() { - return (byte) this.protocol; - } - } - - public short getIPv6MatchLen() { - return match_len; - } - - public int getIPv6ExtMinHdrLen() { - return IPV6_EXT_MIN_HDR_LEN; - } - - public short getPadSize() { - return (short) (((match_len + 7) / 8) * 8 - match_len); - } - - private int getIPv6ExtensionMatchHeader(Extension_Types extType, int field, - int has_mask, int length) { - return (((extType.getValue() & 0x0000ffff) << 16) - | ((field & 0x0000007f) << 9) | ((has_mask & 0x00000001) << 8) | (length & 0x000000ff)); - } - - private byte[] getIPv6ExtensionPortMatchMsg(short port) { - ByteBuffer ipv6ext_port_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_IN_PORT.getValue(), 0, 2); - ipv6ext_port_msg.putInt(nxm_header); - ipv6ext_port_msg.putShort(port); - return (ipv6ext_port_msg.array()); - } - - private byte[] getIPv6ExtensionDestMacMatchMsg(byte[] destMac) { - ByteBuffer ipv6ext_destmac_msg = ByteBuffer.allocate(10); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_ETH_DST.getValue(), 0, 6); - ipv6ext_destmac_msg.putInt(nxm_header); - ipv6ext_destmac_msg.put(destMac); - return (ipv6ext_destmac_msg.array()); - } - - private byte[] getIPv6ExtensionSrcMacMatchMsg(byte[] srcMac) { - ByteBuffer ipv6ext_srcmac_msg = ByteBuffer.allocate(10); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_ETH_SRC.getValue(), 0, 6); - ipv6ext_srcmac_msg.putInt(nxm_header); - ipv6ext_srcmac_msg.put(srcMac); - return (ipv6ext_srcmac_msg.array()); - } - - private byte[] getIPv6ExtensionEtherTypeMatchMsg(short EtherType) { - ByteBuffer ipv6ext_etype_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_ETH_TYPE.getValue(), 0, 2); - ipv6ext_etype_msg.putInt(nxm_header); - ipv6ext_etype_msg.putShort(EtherType); - return (ipv6ext_etype_msg.array()); - } - - private byte[] getIPv6ExtensionVlanIDMatchMsg(short VLAN) { - ByteBuffer ipv6ext_vlanid_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_VLAN_TCI.getValue(), 0, 2); - ipv6ext_vlanid_msg.putInt(nxm_header); - ipv6ext_vlanid_msg.putShort(VLAN); - return (ipv6ext_vlanid_msg.array()); - } - - private byte[] getIPv6ExtensionSrcIPv6MatchMsg(byte[] srcIpv6) { - ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(20); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, - IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_SRC.getValue(), 0, - 16); - ipv6ext_ipv6_msg.putInt(nxm_header); - ipv6ext_ipv6_msg.put(srcIpv6); - return (ipv6ext_ipv6_msg.array()); - } - - private byte[] getIPv6ExtensionSrcIPv6MatchwithMaskMsg(byte[] srcIpv6, - short masklen) { - ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(36); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, - IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_SRC.getValue(), 1, - 32); - ipv6ext_ipv6_msg.putInt(nxm_header); - ipv6ext_ipv6_msg.put(srcIpv6); - byte[] ipv6_mask = getIPv6NetworkMaskinBytes(masklen); - ipv6ext_ipv6_msg.put(ipv6_mask); - return (ipv6ext_ipv6_msg.array()); - } - - private byte[] getIPv6ExtensionDstIPv6MatchMsg(byte[] dstIpv6) { - ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(20); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, - IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_DST.getValue(), 0, - 16); - ipv6ext_ipv6_msg.putInt(nxm_header); - ipv6ext_ipv6_msg.put(dstIpv6); - return (ipv6ext_ipv6_msg.array()); - } - - private byte[] getIPv6ExtensionDstIPv6MatchwithMaskMsg(byte[] dstIpv6, - short masklen) { - ByteBuffer ipv6ext_ipv6_msg = ByteBuffer.allocate(36); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.IPV6EXT, - IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_DST.getValue(), 1, - 32); - ipv6ext_ipv6_msg.putInt(nxm_header); - ipv6ext_ipv6_msg.put(dstIpv6); - byte[] ipv6_mask = getIPv6NetworkMaskinBytes(masklen); - ipv6ext_ipv6_msg.put(ipv6_mask); - return (ipv6ext_ipv6_msg.array()); - } - - private byte[] getIPv6ExtensionProtocolMatchMsg(byte protocol) { - ByteBuffer ipv6ext_proto_msg = ByteBuffer.allocate(5); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_IP_PROTO.getValue(), 0, 1); - if (protocol == 0) { - return null; - } - ipv6ext_proto_msg.putInt(nxm_header); - if (protocol == IPProtocols.ICMP.getValue()) { - /* - * The front end passes the same protocol type values for IPv4 - * and IPv6 flows. For the Protocol types we allow in our GUI - * (ICMP, TCP, UDP), ICMP is the only one which is different for - * IPv6. It is 1 for v4 and 58 for v6 Therefore, we overwrite it - * here. - */ - protocol = IPProtocols.ICMPV6.getValue(); - } - ipv6ext_proto_msg.put(protocol); - return (ipv6ext_proto_msg.array()); - } - - private byte[] getIPv6ExtensionTOSMatchMsg(byte tos) { - ByteBuffer ipv6ext_tos_msg = ByteBuffer.allocate(5); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_IP_TOS.getValue(), 0, 1); - ipv6ext_tos_msg.putInt(nxm_header); - ipv6ext_tos_msg.put(tos); - return (ipv6ext_tos_msg.array()); - } - - private byte[] getIPv6ExtensionTCPSrcPortMatchMsg(short src_port) { - ByteBuffer ipv6ext_tcp_srcport_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_TCP_SRC.getValue(), 0, 2); - ipv6ext_tcp_srcport_msg.putInt(nxm_header); - ipv6ext_tcp_srcport_msg.putShort(src_port); - return (ipv6ext_tcp_srcport_msg.array()); - } - - private byte[] getIPv6ExtensionTCPDstPortMatchMsg(short dst_port) { - ByteBuffer ipv6ext_tcp_dstport_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_TCP_DST.getValue(), 0, 2); - ipv6ext_tcp_dstport_msg.putInt(nxm_header); - ipv6ext_tcp_dstport_msg.putShort(dst_port); - return (ipv6ext_tcp_dstport_msg.array()); - } - - private byte[] getIPv6ExtensionUDPSrcPortMatchMsg(short src_port) { - ByteBuffer ipv6ext_udp_srcport_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_UDP_SRC.getValue(), 0, 2); - ipv6ext_udp_srcport_msg.putInt(nxm_header); - ipv6ext_udp_srcport_msg.putShort(src_port); - return (ipv6ext_udp_srcport_msg.array()); - } - - private byte[] getIPv6ExtensionUDPDstPortMatchMsg(short dst_port) { - ByteBuffer ipv6ext_udp_dstport_msg = ByteBuffer.allocate(6); - int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, - OF_Match_Types.MATCH_OF_UDP_DST.getValue(), 0, 2); - ipv6ext_udp_dstport_msg.putInt(nxm_header); - ipv6ext_udp_dstport_msg.putShort(dst_port); - return (ipv6ext_udp_dstport_msg.array()); - } - - /** - * Sets this (V6Match) object's member variables based on a comma-separated key=value pair similar to OFMatch's fromString. - * - * @param match a key=value comma separated string. - */ - @Override - public void fromString(String match) throws IllegalArgumentException { - if (match.equals("") || match.equalsIgnoreCase("any") - || match.equalsIgnoreCase("all") || match.equals("[]")) - match = "OFMatch[]"; - String[] tokens = match.split("[\\[,\\]]"); - String[] values; - int initArg = 0; - if (tokens[0].equals("OFMatch")) - initArg = 1; - this.wildcards = OFPFW_ALL; - int i; - for (i = initArg; i < tokens.length; i++) { - values = tokens[i].split("="); - if (values.length != 2) - throw new IllegalArgumentException("Token " + tokens[i] - + " does not have form 'key=value' parsing " + match); - values[0] = values[0].toLowerCase(); // try to make this case insens - if (values[0].equals(STR_IN_PORT) || values[0].equals("input_port")) { - this.inputPort = U16.t(Integer.valueOf(values[1])); - inputPortState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - } else if (values[0].equals(STR_DL_DST) - || values[0].equals("eth_dst")) { - this.dataLayerDestination = HexEncode - .bytesFromHexString(values[1]); - dlDestState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 10; - } else if (values[0].equals(STR_DL_SRC) - || values[0].equals("eth_src")) { - this.dataLayerSource = HexEncode.bytesFromHexString(values[1]); - dlSourceState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 10; - this.wildcards &= ~OFPFW_DL_SRC; - } else if (values[0].equals(STR_DL_TYPE) - || values[0].equals("eth_type")) { - if (values[1].startsWith("0x")) - this.dataLayerType = U16.t(Integer.valueOf(values[1] - .replaceFirst("0x", ""), 16)); - else - this.dataLayerType = U16.t(Integer.valueOf(values[1])); - ethTypeState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - } else if (values[0].equals(STR_DL_VLAN)) { - this.dataLayerVirtualLan = U16.t(Integer.valueOf(values[1])); - dlVlanState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - } else if (values[0].equals(STR_DL_VLAN_PCP)) { - this.dataLayerVirtualLanPriorityCodePoint = U8.t(Short - .valueOf(values[1])); - this.wildcards &= ~OFPFW_DL_VLAN_PCP; - } else if (values[0].equals(STR_NW_DST) - || values[0].equals("ip_dst")) { - try { - if (values[1].contains("/")) { - String ipv6addr_wmask[] = values[1].split("/"); - this.nwDst = InetAddress.getByName(ipv6addr_wmask[0]); - this.dstIPv6SubnetMaskbits = Short - .valueOf(ipv6addr_wmask[1]); - nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; - match_len += 36; - } else { - this.nwDst = InetAddress.getByName(values[1]); - nwDstState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 20; - } - } catch (UnknownHostException e) { - logger.error("",e); - } - } else if (values[0].equals(STR_NW_SRC) - || values[0].equals("ip_src")) { - try { - if (values[1].contains("/")) { - String ipv6addr_wmask[] = values[1].split("/"); - this.nwSrc = InetAddress.getByName(ipv6addr_wmask[0]); - this.srcIPv6SubnetMaskbits = Short - .valueOf(ipv6addr_wmask[1]); - nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; - match_len += 36; - } else { - this.nwSrc = InetAddress.getByName(values[1]); - nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 20; - } - } catch (UnknownHostException e) { - logger.error("",e); - } - } else if (values[0].equals(STR_NW_PROTO)) { - this.networkProtocol = U8.t(Short.valueOf(values[1])); - if (!(this.networkProtocol == 0)) { - /* - * if user selects proto 0, don't use it - */ - nwProtoState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 5; - } - } else if (values[0].equals(STR_NW_TOS)) { - this.networkTypeOfService = U8.t(Short.valueOf(values[1])); - nwTosState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 5; - } else if (values[0].equals(STR_TP_DST)) { - this.transportDestination = U16.t(Integer.valueOf(values[1])); - tpDstState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - } else if (values[0].equals(STR_TP_SRC)) { - this.transportSource = U16.t(Integer.valueOf(values[1])); - tpSrcState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - } else - throw new IllegalArgumentException("unknown token " + tokens[i] - + " parsing " + match); - } - - /* - * In a V6 extension message action list should be preceded by a padding of 0 to - * 7 bytes based upon following formula. - */ - - pad_size = (short) (((match_len + 7) / 8) * 8 - match_len); - - } - - /** - * Write this message's binary format to the specified ByteBuffer - * - * @param data - */ - /* - @Override - public void writeTo(ByteBuffer data) { - if (inputPortState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_ingress_port_msg = getIPv6ExtensionPortMatchMsg(this.inputPort); - data.put(ipv6ext_ingress_port_msg); - } - if (ethTypeState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_ether_type_msg = getIPv6ExtensionEtherTypeMatchMsg(this.dataLayerType); - data.put(ipv6ext_ether_type_msg); - } - if (dlDestState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_destmac_msg = getIPv6ExtensionDestMacMatchMsg(this.dataLayerDestination); - data.put(ipv6ext_destmac_msg); - } - if (dlSourceState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_srcmac_msg = getIPv6ExtensionSrcMacMatchMsg(this.dataLayerSource); - data.put(ipv6ext_srcmac_msg); - } - if (dlVlanState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_vlan_id_msg = getIPv6ExtensionVlanIDMatchMsg(this.dataLayerVirtualLan); - data.put(ipv6ext_vlan_id_msg); - } - if (nwSrcState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_src_ipv6_msg = getIPv6ExtensionSrcIPv6MatchMsg(this.nwSrc - .getAddress()); - data.put(ipv6ext_src_ipv6_msg); - } else if (nwSrcState == MatchFieldState.MATCH_FIELD_WITH_MASK) { - byte[] ipv6ext_src_ipv6_with_mask_msg = getIPv6ExtensionSrcIPv6MatchwithMaskMsg( - this.nwSrc.getAddress(), this.srcIPv6SubnetMaskbits); - data.put(ipv6ext_src_ipv6_with_mask_msg); - } - if (nwDstState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_dst_ipv6_msg = getIPv6ExtensionDstIPv6MatchMsg(this.nwDst - .getAddress()); - data.put(ipv6ext_dst_ipv6_msg); - } else if (nwDstState == MatchFieldState.MATCH_FIELD_WITH_MASK) { - byte[] ipv6ext_dst_ipv6_with_mask_msg = getIPv6ExtensionDstIPv6MatchwithMaskMsg( - this.nwDst.getAddress(), this.dstIPv6SubnetMaskbits); - data.put(ipv6ext_dst_ipv6_with_mask_msg); - } - if (nwProtoState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_protocol_msg = getIPv6ExtensionProtocolMatchMsg(this.networkProtocol); - if (ipv6ext_protocol_msg != null) { - data.put(ipv6ext_protocol_msg); - } - } - if (nwTosState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_tos_msg = getIPv6ExtensionTOSMatchMsg(this.networkTypeOfService); - data.put(ipv6ext_tos_msg); - } - if (tpSrcState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_srcport_msg = null; - if (this.networkProtocol == IPProtocols.TCP.getValue()) { - ipv6ext_srcport_msg = getIPv6ExtensionTCPSrcPortMatchMsg(this.transportSource); - } else if (this.networkProtocol == IPProtocols.UDP.getValue()) { - ipv6ext_srcport_msg = getIPv6ExtensionUDPSrcPortMatchMsg(this.transportSource); - } - if (ipv6ext_srcport_msg != null) { - data.put(ipv6ext_srcport_msg); - } - } - if (tpDstState == MatchFieldState.MATCH_FIELD_ONLY) { - byte[] ipv6ext_dstport_msg = null; - if (this.networkProtocol == IPProtocols.TCP.getValue()) { - ipv6ext_dstport_msg = getIPv6ExtensionTCPDstPortMatchMsg(this.transportDestination); - } else if (this.networkProtocol == IPProtocols.UDP.getValue()) { - ipv6ext_dstport_msg = getIPv6ExtensionUDPDstPortMatchMsg(this.transportDestination); - } - if (ipv6ext_dstport_msg != null) { - data.put(ipv6ext_dstport_msg); - } - } - logger.trace("{}", this.toString()); - } - */ - - private void readInPort(ByteBuffer data, int nxmLen, boolean hasMask) { - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - /* - * mask is not allowed for inport port - */ - return; - super.setInputPort(data.getShort()); - this.inputPortState = MatchFieldState.MATCH_FIELD_ONLY; - this.wildcards ^= (1 << 0); // Sync with 0F 1.0 Match - this.match_len += 6; - } - - private void readDataLinkDestination(ByteBuffer data, int nxmLen, - boolean hasMask) { - if (hasMask) { - if ((nxmLen != 2 * 6) || (data.remaining() < 2 * 6)) - return; - else { - byte[] bytes = new byte[6]; - data.get(bytes); - super.setDataLayerDestination(bytes); - this.dataLayerDestinationMask = new byte[6]; - data.get(this.dataLayerDestinationMask); - this.dlDestState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 16; - } - } else { - if ((nxmLen != 6) || (data.remaining() < 6)) - return; - else { - byte[] bytes = new byte[6]; - data.get(bytes); - super.setDataLayerDestination(bytes); - this.dlDestState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 10; - } - } - this.wildcards ^= (1 << 3); // Sync with 0F 1.0 Match - } - - private void readDataLinkSource(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in data link source - */ - if ((nxmLen != 6) || (data.remaining() < 6) || (hasMask)) - return; - byte[] bytes = new byte[6]; - data.get(bytes); - super.setDataLayerSource(bytes); - this.dlSourceState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 10; - this.wildcards ^= (1 << 2); // Sync with 0F 1.0 Match - } - - private void readEtherType(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in ethertype - */ - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - return; - super.setDataLayerType(data.getShort()); - this.ethTypeState = MatchFieldState.MATCH_FIELD_ONLY; - this.wildcards ^= (1 << 4); // Sync with 0F 1.0 Match - this.match_len += 6; - } - - private void readVlanTci(ByteBuffer data, int nxmLen, boolean hasMask) { - short vlan_mask = 0xfff; - if (hasMask) { - if ((nxmLen != 2 * 2) || (data.remaining() < 2 * 2)) - return; - else { - short vlan = data.getShort(); - vlan &= vlan_mask; - super.setDataLayerVirtualLan(vlan); - this.dataLayerVirtualLanMask = data.getShort(); - this.dlVlanState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 8; - this.wildcards ^= (1 << 20); - } - } else { - if ((nxmLen != 2) || (data.remaining() < 2)) - return; - else { - short vlan = data.getShort(); - vlan &= vlan_mask; - super.setDataLayerVirtualLan(vlan); - this.dlVlanState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - } - } - - this.wildcards ^= (1 << 1); // Sync with 0F 1.0 Match - } - - private void readIpTos(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in IP TOS - */ - if ((nxmLen != 1) || (data.remaining() < 1) || (hasMask)) - return; - super.setNetworkTypeOfService(data.get()); - this.nwTosState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 5; - this.wildcards ^= (1 << 21); // Sync with 0F 1.0 Match - } - - private void readIpProto(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in IP protocol - */ - if ((nxmLen != 1) || (data.remaining() < 1) || (hasMask)) - return; - super.setNetworkProtocol(data.get()); - this.nwProtoState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 5; - this.wildcards ^= (1 << 5); // Sync with 0F 1.0 Match - } - - private void readIpv4Src(ByteBuffer data, int nxmLen, boolean hasMask) { - if (hasMask) { - if ((nxmLen != 2 * 4) || (data.remaining() < 2 * 4)) - return; - else { - byte[] sbytes = new byte[4]; - data.get(sbytes); - try { - this.nwSrc = InetAddress.getByAddress(sbytes); - } catch (UnknownHostException e) { - return; - } - byte[] mbytes = new byte[4]; - data.get(mbytes); - try { - this.networkSourceMask = InetAddress.getByAddress(mbytes); - } catch (UnknownHostException e) { - return; - } - this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 12; - int prefixlen = getNetworkMaskPrefixLength(mbytes); - this.wildcards ^= (((1 << 6) - 1) << 8); // Sync with 0F 1.0 Match - this.wildcards |= ((32 - prefixlen) << 8); // Sync with 0F 1.0 Match - - } - } else { - if ((nxmLen != 4) || (data.remaining() < 4)) - return; - else { - byte[] sbytes = new byte[4]; - data.get(sbytes); - try { - this.nwSrc = InetAddress.getByAddress(sbytes); - } catch (UnknownHostException e) { - return; - } - this.nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 8; - this.wildcards ^= (((1 << 6) - 1) << 8); // Sync with 0F 1.0 Match - } - } - } - - private void readIpv4Dst(ByteBuffer data, int nxmLen, boolean hasMask) { - if (hasMask) { - if ((nxmLen != 2 * 4) || (data.remaining() < 2 * 4)) - return; - else { - byte[] dbytes = new byte[4]; - data.get(dbytes); - try { - this.nwDst = InetAddress.getByAddress(dbytes); - } catch (UnknownHostException e) { - return; - } - byte[] mbytes = new byte[4]; - data.get(mbytes); - try { - this.networkDestinationMask = InetAddress - .getByAddress(mbytes); - } catch (UnknownHostException e) { - return; - } - this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 12; - int prefixlen = getNetworkMaskPrefixLength(mbytes); - this.wildcards ^= (((1 << 6) - 1) << 14); // Sync with 0F 1.0 Match - this.wildcards |= ((32 - prefixlen) << 14); // Sync with 0F 1.0 Match - } - } else { - if ((nxmLen != 4) || (data.remaining() < 4)) - return; - else { - byte[] dbytes = new byte[4]; - data.get(dbytes); - try { - this.nwDst = InetAddress.getByAddress(dbytes); - } catch (UnknownHostException e) { - return; - } - this.nwDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.wildcards ^= (((1 << 6) - 1) << 14); // Sync with 0F 1.0 Match - this.match_len += 8; - } - } - } - - private void readTcpSrc(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in TCP SRC - */ - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - return; - super.setTransportSource(data.getShort()); - this.tpSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - this.wildcards ^= (1 << 6); // Sync with 0F 1.0 Match - } - - private void readTcpDst(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in TCP DST - */ - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - return; - super.setTransportDestination(data.getShort()); - this.tpDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - this.wildcards ^= (1 << 7); // Sync with 0F 1.0 Match - } - - private void readUdpSrc(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in UDP SRC - */ - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - return; - super.setTransportSource(data.getShort()); - this.tpSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - this.wildcards ^= (1 << 6); // Sync with 0F 1.0 Match - } - - private void readUdpDst(ByteBuffer data, int nxmLen, boolean hasMask) { - /* - * mask is not allowed in UDP DST - */ - if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) - return; - super.setTransportDestination(data.getShort()); - this.tpDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - this.wildcards ^= (1 << 7); // Sync with 0F 1.0 Match - } - - private void readIpv6Src(ByteBuffer data, int nxmLen, boolean hasMask) { - if (hasMask) { - if ((nxmLen != 2 * 16) || (data.remaining() < 2 * 16)) - return; - else { - byte[] sbytes = new byte[16]; - data.get(sbytes); - try { - this.nwSrc = InetAddress.getByAddress(sbytes); - } catch (UnknownHostException e) { - return; - } - byte[] mbytes = new byte[16]; - data.get(mbytes); - try { - this.networkSourceMask = InetAddress.getByAddress(mbytes); - } catch (UnknownHostException e) { - return; - } - this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 36; - } - } else { - if ((nxmLen != 16) || (data.remaining() < 16)) - return; - else { - byte[] sbytes = new byte[16]; - data.get(sbytes); - try { - this.nwSrc = InetAddress.getByAddress(sbytes); - } catch (UnknownHostException e) { - return; - } - this.nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 20; - } - } - } - - private void readIpv6Dst(ByteBuffer data, int nxmLen, boolean hasMask) { - if (hasMask) { - if ((nxmLen != 2 * 16) || (data.remaining() < 2 * 16)) - return; - else { - byte[] dbytes = new byte[16]; - data.get(dbytes); - try { - this.nwDst = InetAddress.getByAddress(dbytes); - } catch (UnknownHostException e) { - return; - } - byte[] mbytes = new byte[16]; - data.get(mbytes); - try { - this.networkDestinationMask = InetAddress - .getByAddress(mbytes); - } catch (UnknownHostException e) { - return; - } - this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 36; - } - } else { - if ((nxmLen != 16) || (data.remaining() < 16)) - return; - else { - byte[] dbytes = new byte[16]; - data.get(dbytes); - try { - this.nwDst = InetAddress.getByAddress(dbytes); - } catch (UnknownHostException e) { - return; - } - this.nwDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 20; - } - } - } - - @Override - public String toString() { - return "V6Match[" + ReflectionToStringBuilder.toString(this) + "]"; - } - - /** - * Read the data corresponding to the match field (received from the wire) - * Input: data: match field(s). Since match field is of variable length, the whole data that are passed in - * are assumed to fem0tbd.be the match fields. - * @param data - */ - /* - @Override - public void readFrom(ByteBuffer data) { - readFromInternal(data); - postprocessWildCardInfo(); - } - */ - - private void readFromInternal(ByteBuffer data) { - this.match_len = 0; - while (data.remaining() > 0) { - if (data.remaining() < 4) { - /* - * at least 4 bytes for each match header - */ - logger.error("Invalid Vendor Extension Header. Size {}", data - .remaining()); - return; - } - /* - * read the 4 byte match header - */ - int nxmVendor = data.getShort(); - int b = data.get(); - int nxmField = b >> 1; - boolean hasMask = ((b & 0x01) == 1) ? true : false; - int nxmLen = data.get(); - if (nxmVendor == Extension_Types.OF_10.getValue()) { - if (nxmField == OF_Match_Types.MATCH_OF_IN_PORT.getValue()) { - readInPort(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_ETH_DST - .getValue()) { - readDataLinkDestination(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_ETH_SRC - .getValue()) { - readDataLinkSource(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_ETH_TYPE - .getValue()) { - readEtherType(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_VLAN_TCI - .getValue()) { - readVlanTci(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_IP_TOS - .getValue()) { - readIpTos(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_IP_PROTO - .getValue()) { - readIpProto(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_IP_SRC - .getValue()) { - readIpv4Src(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_IP_DST - .getValue()) { - readIpv4Dst(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_TCP_SRC - .getValue()) { - readTcpSrc(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_TCP_DST - .getValue()) { - readTcpDst(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_UDP_SRC - .getValue()) { - readUdpSrc(data, nxmLen, hasMask); - } else if (nxmField == OF_Match_Types.MATCH_OF_UDP_DST - .getValue()) { - readUdpDst(data, nxmLen, hasMask); - } else { - // unexpected nxmField - return; - } - } else if (nxmVendor == Extension_Types.IPV6EXT.getValue()) { - if (nxmField == IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_SRC - .getValue()) { - readIpv6Src(data, nxmLen, hasMask); - } else if (nxmField == IPv6Extension_Match_Types.MATCH_IPV6EXT_IPV6_DST - .getValue()) { - readIpv6Dst(data, nxmLen, hasMask); - } else { - // unexpected nxmField - return; - } - } else { - // invalid nxmVendor - return; - } - } - } - - private void postprocessWildCardInfo() { - // Sync with 0F 1.0 Match - if (super.getDataLayerType() == 0x800) { - if (((this.wildcards >> 8) & 0x3f) == 0x3f) { - //ipv4 src processing - this.wildcards ^= (((1 << 5) - 1) << 8); - } - if (((this.wildcards >> 14) & 0x3f) == 0x3f) { - //ipv4 dest processing - this.wildcards ^= (((1 << 5) - 1) << 14); - } - } else { - this.wildcards = 0; - } - } - - @Override - public V6Match clone() { - - V6Match ret = (V6Match) super.clone(); - try { - if (this.nwSrc != null) { - ret.nwSrc = InetAddress.getByAddress(this.nwSrc.getAddress()); - } - if (this.nwDst != null) { - ret.nwDst = InetAddress.getByAddress(this.nwDst.getAddress()); - } - return ret; - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } - } - - /** - * Get nw_dst - * - * @return - */ - - public InetAddress getNetworkDest() { - return this.nwDst; - } - - /** - * Get nw_src - * - * @return - */ - - public void setNetworkSrc(InetAddress address) { - nwSrc = address; - } - - /** - * Set nw_dst - * - * @return - */ - - public void setNetworkDest(InetAddress address) { - nwDst = address; - } - - /** - * Set nw_src - * - * @return - */ - - public InetAddress getNetworkSrc() { - return this.nwSrc; - } - - private int getNetworkMaskPrefixLength(byte[] netMask) { - ByteBuffer nm = ByteBuffer.wrap(netMask); - int trailingZeros = Integer.numberOfTrailingZeros(nm.getInt()); - return 32 - trailingZeros; - } - - public short getInputPortMask() { - return inputPortMask; - } - - public void setInputPort(short port, short mask) { - super.inputPort = port; - this.inputPortState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 6; - // Looks like mask is not allowed for input port. Will discard it - } - - public byte[] getDataLayerSourceMask() { - return dataLayerSourceMask; - } - - public void setDataLayerSource(byte[] mac, byte[] mask) { - if (mac != null) { - System.arraycopy(mac, 0, super.dataLayerSource, 0, mac.length); - } - if (mask == null) { - this.dlSourceState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 10; - } else { - if (this.dataLayerSourceMask == null) { - this.dataLayerSourceMask = new byte[mask.length]; - } - System.arraycopy(mask, 0, this.dataLayerSourceMask, 0, mask.length); - this.dlSourceState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 16; - } - } - - public byte[] getDataLayerDestinationMask() { - return dataLayerDestinationMask; - } - - public void setDataLayerDestination(byte[] mac, byte[] mask) { - if (mac != null) { - System.arraycopy(mac, 0, super.dataLayerDestination, 0, mac.length); - } - if (mask == null) { - this.dlDestState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 10; - } else { - if (this.dataLayerDestinationMask == null) { - this.dataLayerDestinationMask = new byte[mask.length]; - } - System.arraycopy(mask, 0, this.dataLayerDestinationMask, 0, - mask.length); - this.dlDestState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 16; - } - } - - public short getDataLayerVirtualLanMask() { - return dataLayerVirtualLanMask; - } - - public void setDataLayerVirtualLan(short vlan, short mask) { - super.dataLayerVirtualLan = vlan; - if (mask == 0) { - this.dlVlanState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - } else { - this.dataLayerVirtualLanMask = mask; - this.dlVlanState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += 8; - } - } - - public void setDataLayerVirtualLanPriorityCodePoint(byte pcp, byte mask) { - super.dataLayerVirtualLanPriorityCodePoint = pcp; - } - - public void setDataLayerType(short ethType, short mask) { - // mask not allowed - super.dataLayerType = ethType; - this.ethTypeState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - } - - public void setNetworkTypeOfService(byte tos, byte mask) { - // mask not allowed - super.networkTypeOfService = tos; - this.nwTosState = MatchFieldState.MATCH_FIELD_ONLY; - match_len += 5; - } - - public void setNetworkProtocol(byte ipProto, byte mask) { - // mask not allowed - super.networkProtocol = ipProto; - this.nwProtoState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 5; - } - - public InetAddress getNetworkSourceMask() { - return networkSourceMask; - } - - public void setNetworkSource(InetAddress address, InetAddress mask) { - this.nwSrc = address; - if (mask == null) { - this.nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += (address instanceof Inet6Address) ? 20 : 8; - } else { - this.networkSourceMask = mask; - this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += (address instanceof Inet6Address) ? 36 : 12; - } - } - - public InetAddress getNetworkDestinationMask() { - return networkDestinationMask; - } - - public void setNetworkDestination(InetAddress address, InetAddress mask) { - this.nwDst = address; - if (mask == null) { - this.nwDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += (address instanceof Inet6Address) ? 20 : 8; - } else { - this.networkDestinationMask = mask; - this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; - this.match_len += (address instanceof Inet6Address) ? 36 : 12; - } - } - - public void setTransportSource(short tpSrc, short mask) { - // mask not allowed - super.transportSource = tpSrc; - this.tpSrcState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - } - - public short getTransportDestinationMask() { - return transportDestinationMask; - } - - public void setTransportDestination(short tpDst, short mask) { - // mask not allowed - super.transportDestination = tpDst; - this.tpDstState = MatchFieldState.MATCH_FIELD_ONLY; - this.match_len += 6; - } - - private byte[] getIPv6NetworkMaskinBytes(short num) { - byte[] nbytes = new byte[16]; - int quot = num / 8; - int bits = num % 8; - int i; - - for (i = 0; i < quot; i++) { - nbytes[i] = (byte) 0xff; - } - - if (bits > 0) { - nbytes[i] = (byte) 0xff; - nbytes[i] <<= 8 - bits; - } - return nbytes; - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java deleted file mode 100644 index 00005af771..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsReply.java +++ /dev/null @@ -1,335 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import java.nio.ByteBuffer; -import java.util.List; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.action.OFAction; -import org.openflow.protocol.statistics.OFVendorStatistics; -import org.openflow.util.U16; - -/** - * This Class processes the OpenFlow Vendor Extension Reply message of a Stats - * Request. It parses the reply message and initializes fields of V6StatsReply - * object. Multiple instances of this class objects are created and used by - * OpenDaylight's Troubleshooting Application. - * - */ - -public class V6StatsReply extends OFVendorStatistics { - private static final long serialVersionUID = 1L; - - public static int MINIMUM_LENGTH = 48; //48 for nx_flow_stats - - protected short length = (short) MINIMUM_LENGTH; - protected byte tableId; - protected int durationSeconds; - protected int durationNanoseconds; - protected short priority; - protected short idleTimeout; - protected short hardTimeout; - protected short match_len; - protected short idleAge; - protected short hardAge; - protected long cookie; - protected long packetCount; - protected long byteCount; - protected V6Match match; - protected List actions; - - /** - * @return vendor id - */ - public int getVendorId() { - return vendor; - } - - /** - * @param vendor the vendor to set - */ - public void setVendorId(int vendor) { - this.vendor = vendor; - } - - /** - * @return the tableId - */ - public byte getTableId() { - return tableId; - } - - /** - * @param tableId the tableId to set - */ - public void setTableId(byte tableId) { - this.tableId = tableId; - } - - /** - * @return the durationSeconds - */ - public int getDurationSeconds() { - return durationSeconds; - } - - /** - * @param durationSeconds the durationSeconds to set - */ - public void setDurationSeconds(int durationSeconds) { - this.durationSeconds = durationSeconds; - } - - /** - * @return the durationNanoseconds - */ - public int getDurationNanoseconds() { - return durationNanoseconds; - } - - /** - * @param durationNanoseconds the durationNanoseconds to set - */ - public void setDurationNanoseconds(int durationNanoseconds) { - this.durationNanoseconds = durationNanoseconds; - } - - /** - * @return the priority - */ - public short getPriority() { - return priority; - } - - /** - * @param priority the priority to set - */ - public void setPriority(short priority) { - this.priority = priority; - } - - /** - * @return the idleTimeout - */ - public short getIdleTimeout() { - return idleTimeout; - } - - /** - * @param idleTimeout the idleTimeout to set - */ - public void setIdleTimeout(short idleTimeout) { - this.idleTimeout = idleTimeout; - } - - /** - * @return the hardTimeout - */ - public short getHardTimeout() { - return hardTimeout; - } - - /** - * @param hardTimeout the hardTimeout to set - */ - public void setHardTimeout(short hardTimeout) { - this.hardTimeout = hardTimeout; - } - - /** - * @param match_len the match_len to set - */ - public void setMatchLen(short match_len) { - this.match_len = match_len; - } - - /** - * @return the match_len - */ - public short getMatchLen() { - return match_len; - } - - /** - * @return the idleAge - */ - public short getIdleAge() { - return idleAge; - } - - /** - * @param idleAge the idleAge to set - */ - public void setIdleAge(short idleAge) { - this.idleAge = idleAge; - } - - /** - * @return the hardAge - */ - public short getHardAge() { - return hardAge; - } - - /** - * @param hardAge the hardAge to set - */ - public void setHardAge(short hardAge) { - this.hardAge = hardAge; - } - - /** - * @return the cookie - */ - public long getCookie() { - return cookie; - } - - /** - * @param cookie the cookie to set - */ - public void setCookie(long cookie) { - this.cookie = cookie; - } - - /** - * @return the packetCount - */ - public long getPacketCount() { - return packetCount; - } - - /** - * @param packetCount the packetCount to set - */ - public void setPacketCount(long packetCount) { - this.packetCount = packetCount; - } - - /** - * @return the byteCount - */ - public long getByteCount() { - return byteCount; - } - - /** - * @param byteCount the byteCount to set - */ - public void setByteCount(long byteCount) { - this.byteCount = byteCount; - } - - /** - * @param length the length to set - */ - public void setLength(short length) { - this.length = length; - } - - @Override - public int getLength() { - return U16.f(length); - } - - /** - * @return the match - */ - public V6Match getMatch() { - return match; - } - - /** - * @return the actions - */ - public List getActions() { - return actions; - } - - /** - * @param actions the actions to set - */ - public void setActions(List actions) { - this.actions = actions; - } - - /* - @Override - public void readFrom(ByteBuffer data) { - short i; - this.length = data.getShort(); - if (length < MINIMUM_LENGTH) - return; //TBD - Spurious Packet? - this.tableId = data.get(); - data.get(); // pad - this.durationSeconds = data.getInt(); - this.durationNanoseconds = data.getInt(); - this.priority = data.getShort(); - this.idleTimeout = data.getShort(); - this.hardTimeout = data.getShort(); - this.match_len = data.getShort(); - this.idleAge = data.getShort(); - this.hardAge = data.getShort(); - this.cookie = data.getLong(); - this.packetCount = data.getLong(); - this.byteCount = data.getLong(); - if (this.length == MINIMUM_LENGTH) { - return; //TBD - can this happen?? - } - if (this.match == null) - this.match = new V6Match(); - ByteBuffer mbuf = ByteBuffer.allocate(match_len); - for (i = 0; i < match_len; i++) { - mbuf.put(data.get()); - } - mbuf.rewind(); - this.match.readFrom(mbuf); - if (this.actionFactory == null) - throw new RuntimeException("OFActionFactory not set"); - /* - * action list may be preceded by a padding of 0 to 7 bytes based upon this: - */ - /* - short pad_size = (short) (((match_len + 7) / 8) * 8 - match_len); - for (i = 0; i < pad_size; i++) - data.get(); - int action_len = this.length - MINIMUM_LENGTH - (match_len + pad_size); - if (action_len > 0) - this.actions = this.actionFactory.parseActions(data, action_len); - } -*/ - - /* - @Override - public void writeTo(ByteBuffer data) { - super.writeTo(data);//TBD. This Fn needs work. Should never get called though. - - } - */ - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - - @Override - public String toString() { - return "V6StatsReply[" + ReflectionToStringBuilder.toString(this) + "]"; - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java b/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java deleted file mode 100644 index 97d555011f..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6StatsRequest.java +++ /dev/null @@ -1,158 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.openflow.protocol.statistics.OFVendorStatistics; -import java.nio.ByteBuffer; - - -/** - * This Class creates the OpenFlow Vendor Extension IPv6 Flow Stats Request - * messages and also reads the Reply of a stats request message. - * - */ - -public class V6StatsRequest extends OFVendorStatistics { - private static final long serialVersionUID = 1L; - protected int msgsubtype; - protected short outPort; - protected short match_len; - protected byte tableId; - - public static final int NICIRA_VENDOR_ID = 0x00002320; //Nicira ID - private static final int NXST_FLOW = 0x0; //Nicira Flow Stats Request Id - - public V6StatsRequest() { - this.vendor = NICIRA_VENDOR_ID; - this.msgsubtype = NXST_FLOW; - this.match_len = 0; - } - - /** - * @param None. Being set with local variable (TBD). - */ - public void setVendorId() { - this.vendor = NICIRA_VENDOR_ID; - } - - /** - * @return vendor id - */ - public int getVendorId() { - return vendor; - } - - /** - * @param None. Being set with local variable (TBD). - */ - public void setMsgtype() { - this.msgsubtype = NXST_FLOW; - } - - /** - * @return vendor_msgtype - */ - public int getMsgtype() { - return msgsubtype; - } - - /** - * @param outPort the outPort to set - */ - public void setOutPort(short outPort) { - this.outPort = outPort; - } - - /** - * @return the outPort - */ - public short getOutPort() { - return outPort; - } - - /** - * @param match_len the match_len to set - */ - public void setMatchLen(short match_len) { - this.match_len = match_len; - } - - /** - * @return the match_len - */ - public short getMatchLen() { - return match_len; - } - - /** - * @param tableId the tableId to set - */ - public void setTableId(byte tableId) { - this.tableId = tableId; - } - - /** - * @return the tableId - */ - public byte getTableId() { - return tableId; - } - - @Override - public int getLength() { - return 20;// 4(vendor)+4(msgsubtype)+4(pad)+2(outPort)+2(match_len)+1(tableid)+3(pad) - } - - /* - @Override - public void readFrom(ByteBuffer data) { - this.vendor = data.getInt(); - this.msgsubtype = data.getInt(); - data.getInt();//pad 4 bytes - this.outPort = data.getShort(); - this.match_len = data.getShort(); - this.tableId = data.get(); - for (int i = 0; i < 3; i++) - data.get();//pad byte - - } - - @Override - public void writeTo(ByteBuffer data) { - data.putInt(this.vendor); - data.putInt(this.msgsubtype); - data.putInt((int) 0x0);//pad0 - data.putShort(this.outPort); - data.putShort(this.match_len); - data.put(this.tableId); - for (int i = 0; i < 3; i++) - data.put((byte) 0x0);//pad byte - } - */ - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - - @Override - public String toString() { - return "V6StatsRequest[" + ReflectionToStringBuilder.toString(this) - + "]"; - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerServiceTest.java b/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerServiceTest.java deleted file mode 100644 index c314439a14..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowProgrammerServiceTest.java +++ /dev/null @@ -1,363 +0,0 @@ - -/* - * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.controller.protocol_plugin.openflow.internal.FlowConverter; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; -import org.openflow.protocol.OFMatch; -import org.openflow.protocol.action.OFAction; - -import org.opendaylight.controller.sal.action.Action; -import org.opendaylight.controller.sal.action.Flood; -import org.opendaylight.controller.sal.action.FloodAll; -import org.opendaylight.controller.sal.action.HwPath; -import org.opendaylight.controller.sal.action.Loopback; -import org.opendaylight.controller.sal.action.Output; -import org.opendaylight.controller.sal.action.PopVlan; -import org.opendaylight.controller.sal.action.SetDlDst; -import org.opendaylight.controller.sal.action.SetDlSrc; -import org.opendaylight.controller.sal.action.SetNwDst; -import org.opendaylight.controller.sal.action.SetNwSrc; -import org.opendaylight.controller.sal.action.SetNwTos; -import org.opendaylight.controller.sal.action.SetTpDst; -import org.opendaylight.controller.sal.action.SetTpSrc; -import org.opendaylight.controller.sal.action.SetVlanId; -import org.opendaylight.controller.sal.action.SwPath; -import org.opendaylight.controller.sal.core.Node; -import org.opendaylight.controller.sal.core.NodeConnector; -import org.opendaylight.controller.sal.flowprogrammer.Flow; -import org.opendaylight.controller.sal.match.Match; -import org.opendaylight.controller.sal.match.MatchType; -import org.opendaylight.controller.sal.utils.EtherTypes; -import org.opendaylight.controller.sal.utils.IPProtocols; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; -import org.opendaylight.controller.sal.utils.NodeCreator; - -public class FlowProgrammerServiceTest { - - @Test - public void testSALtoOFFlowConverter() throws UnknownHostException { - Node node = NodeCreator.createOFNode(1000l); - NodeConnector port = NodeConnectorCreator.createNodeConnector( - (short) 24, node); - NodeConnector oport = NodeConnectorCreator.createNodeConnector( - (short) 30, node); - byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, - (byte) 0x9a, (byte) 0xbc }; - byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, - (byte) 0x5e, (byte) 0x6f }; - InetAddress srcIP = InetAddress.getByName("172.28.30.50"); - InetAddress dstIP = InetAddress.getByName("171.71.9.52"); - InetAddress ipMask = InetAddress.getByName("255.255.255.0"); - short ethertype = EtherTypes.IPv4.shortValue(); - short vlan = (short) 27; - byte vlanPr = 3; - Byte tos = 4; - byte proto = IPProtocols.TCP.byteValue(); - short src = (short) 55000; - short dst = 80; - - /* - * Create a SAL Flow aFlow - */ - Match match = new Match(); - match.setField(MatchType.IN_PORT, port); - match.setField(MatchType.DL_SRC, srcMac); - match.setField(MatchType.DL_DST, dstMac); - match.setField(MatchType.DL_TYPE, ethertype); - match.setField(MatchType.DL_VLAN, vlan); - match.setField(MatchType.DL_VLAN_PR, vlanPr); - match.setField(MatchType.NW_SRC, srcIP, ipMask); - match.setField(MatchType.NW_DST, dstIP, ipMask); - match.setField(MatchType.NW_TOS, tos); - match.setField(MatchType.NW_PROTO, proto); - match.setField(MatchType.TP_SRC, src); - match.setField(MatchType.TP_DST, dst); - - Assert.assertTrue(match.isIPv4()); - - List actions = new ArrayList(); - // Setting all the actions supported by of - actions.add(new PopVlan()); - actions.add(new Output(oport)); - actions.add(new Flood()); - actions.add(new FloodAll()); - actions.add(new SwPath()); - actions.add(new HwPath()); - actions.add(new Loopback()); - byte mac[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 }; - actions.add(new SetDlSrc(mac)); - actions.add(new SetDlDst(mac)); - actions.add(new SetNwSrc(dstIP)); - actions.add(new SetNwDst(srcIP)); - actions.add(new SetNwTos(3)); - actions.add(new SetTpSrc(10)); - actions.add(new SetTpDst(20)); - actions.add(new SetVlanId(200)); - - Flow aFlow = new Flow(match, actions); - - /* - * Convert the SAL aFlow to OF Flow - */ - FlowConverter salToOF = new FlowConverter(aFlow); - OFMatch ofMatch = salToOF.getOFMatch(); - List ofActions = salToOF.getOFActions(); - - /* - * Convert the OF Flow to SAL Flow bFlow - */ - FlowConverter ofToSal = new FlowConverter(ofMatch, ofActions); - Flow bFlow = ofToSal.getFlow(node); - Match bMatch = bFlow.getMatch(); - List bActions = bFlow.getActions(); - - /* - * Verify the converted SAL flow bFlow is equivalent to the original SAL Flow - */ - Assert.assertTrue(((NodeConnector) match.getField(MatchType.IN_PORT) - .getValue()).equals(((NodeConnector) bMatch.getField( - MatchType.IN_PORT).getValue()))); - Assert.assertTrue(Arrays.equals((byte[]) match.getField( - MatchType.DL_SRC).getValue(), (byte[]) bMatch.getField( - MatchType.DL_SRC).getValue())); - Assert.assertTrue(Arrays.equals((byte[]) match.getField( - MatchType.DL_DST).getValue(), (byte[]) bMatch.getField( - MatchType.DL_DST).getValue())); - Assert - .assertTrue(((Short) match.getField(MatchType.DL_TYPE) - .getValue()).equals((Short) bMatch.getField( - MatchType.DL_TYPE).getValue())); - Assert - .assertTrue(((Short) match.getField(MatchType.DL_VLAN) - .getValue()).equals((Short) bMatch.getField( - MatchType.DL_VLAN).getValue())); - Assert.assertTrue(((Byte) match.getField(MatchType.DL_VLAN_PR) - .getValue()).equals((Byte) bMatch - .getField(MatchType.DL_VLAN_PR).getValue())); - Assert.assertTrue(((InetAddress) match.getField(MatchType.NW_SRC) - .getValue()).equals((InetAddress) bMatch.getField( - MatchType.NW_SRC).getValue())); - Assert.assertTrue(((InetAddress) match.getField(MatchType.NW_SRC) - .getMask()).equals((InetAddress) bMatch.getField( - MatchType.NW_SRC).getMask())); - Assert.assertTrue(((InetAddress) match.getField(MatchType.NW_DST) - .getValue()).equals((InetAddress) bMatch.getField( - MatchType.NW_DST).getValue())); - Assert.assertTrue(((InetAddress) match.getField(MatchType.NW_DST) - .getMask()).equals((InetAddress) bMatch.getField( - MatchType.NW_DST).getMask())); - Assert - .assertTrue(((Byte) match.getField(MatchType.NW_PROTO) - .getValue()).equals((Byte) bMatch.getField( - MatchType.NW_PROTO).getValue())); - Assert.assertTrue(((Byte) match.getField(MatchType.NW_TOS).getValue()) - .equals((Byte) bMatch.getField(MatchType.NW_TOS).getValue())); - Assert.assertTrue(((Short) match.getField(MatchType.TP_SRC).getValue()) - .equals((Short) bMatch.getField(MatchType.TP_SRC).getValue())); - Assert.assertTrue(((Short) match.getField(MatchType.TP_DST).getValue()) - .equals((Short) bMatch.getField(MatchType.TP_DST).getValue())); - - // FlowConverter parses and sets the actions in the same order for sal match and of match - for (short i = 0; i < actions.size(); i++) { - Assert.assertTrue(actions.get(i).equals(bActions.get(i))); - } - } - - - @Ignore - public void testV6toSALFlowConversion() throws Exception { - Node node = NodeCreator.createOFNode(12l); - NodeConnector port = NodeConnectorCreator.createNodeConnector( - (short) 34, node); - NodeConnector oport = NodeConnectorCreator.createNodeConnector( - (short) 30, node); - byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, - (byte) 0x9a, (byte) 0xbc }; - byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, - (byte) 0x5e, (byte) 0x6f }; - InetAddress srcIP = InetAddress - .getByName("2001:420:281:1004:407a:57f4:4d15:c355"); - InetAddress dstIP = InetAddress - .getByName("2001:420:281:1004:e123:e688:d655:a1b0"); - InetAddress ipMask = InetAddress - .getByName("ffff:ffff:ffff:ffff:0:0:0:0"); - short ethertype = EtherTypes.IPv6.shortValue(); - short vlan = (short) 27; - byte vlanPr = 3; - Byte tos = 4; - byte proto = IPProtocols.TCP.byteValue(); - short src = (short) 55000; - short dst = 80; - - /* - * Create a SAL Flow aFlow - */ - Match aMatch = new Match(); - - aMatch.setField(MatchType.IN_PORT, port); - aMatch.setField(MatchType.DL_SRC, srcMac); - aMatch.setField(MatchType.DL_DST, dstMac); - aMatch.setField(MatchType.DL_TYPE, ethertype); - aMatch.setField(MatchType.DL_VLAN, vlan); - aMatch.setField(MatchType.DL_VLAN_PR, vlanPr); - aMatch.setField(MatchType.NW_SRC, srcIP, ipMask); - aMatch.setField(MatchType.NW_DST, dstIP, ipMask); - aMatch.setField(MatchType.NW_TOS, tos); - aMatch.setField(MatchType.NW_PROTO, proto); - aMatch.setField(MatchType.TP_SRC, src); - aMatch.setField(MatchType.TP_DST, dst); - - Assert.assertTrue(aMatch.isIPv6()); - - List actions = new ArrayList(); - // Setting all the actions supported by of for v6 - actions.add(new PopVlan()); - actions.add(new Output(oport)); - actions.add(new Flood()); - actions.add(new FloodAll()); - actions.add(new SwPath()); - actions.add(new HwPath()); - actions.add(new Loopback()); - byte mac[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 }; - actions.add(new SetDlSrc(mac)); - actions.add(new SetDlDst(mac)); - //actions.add(new SetNwSrc(dstIP)); Nicira extensions do not provide IPv6 match addresses change - //actions.add(new SetNwDst(srcIP)); - actions.add(new SetNwTos(3)); - actions.add(new SetTpSrc(10)); - actions.add(new SetTpDst(65535)); - actions.add(new SetVlanId(200)); - - Flow aFlow = new Flow(aMatch, actions); - - /* - * Convert the SAL aFlow to OF Flow - */ - FlowConverter salToOF = new FlowConverter(aFlow); - V6Match v6Match = (V6Match) salToOF.getOFMatch(); - List ofActions = salToOF.getOFActions(); - - /* - * Convert the OF Flow to SAL Flow bFlow - */ - FlowConverter ofToSal = new FlowConverter(v6Match, ofActions); - Flow bFlow = ofToSal.getFlow(node); - Match bMatch = bFlow.getMatch(); - List bActions = bFlow.getActions(); - - /* - * Verify the converted SAL flow bFlow is equivalent to the original SAL Flow - */ - Assert.assertTrue(((NodeConnector) aMatch.getField(MatchType.IN_PORT) - .getValue()).equals(((NodeConnector) bMatch.getField( - MatchType.IN_PORT).getValue()))); - Assert.assertTrue(Arrays.equals((byte[]) aMatch.getField( - MatchType.DL_SRC).getValue(), (byte[]) bMatch.getField( - MatchType.DL_SRC).getValue())); - Assert.assertTrue(Arrays.equals((byte[]) aMatch.getField( - MatchType.DL_DST).getValue(), (byte[]) bMatch.getField( - MatchType.DL_DST).getValue())); - Assert.assertTrue(((Short) aMatch.getField(MatchType.DL_TYPE) - .getValue()).equals((Short) bMatch.getField(MatchType.DL_TYPE) - .getValue())); - Assert.assertTrue(((Short) aMatch.getField(MatchType.DL_VLAN) - .getValue()).equals((Short) bMatch.getField(MatchType.DL_VLAN) - .getValue())); - Assert.assertTrue(((Byte) aMatch.getField(MatchType.DL_VLAN_PR) - .getValue()).equals((Byte) bMatch - .getField(MatchType.DL_VLAN_PR).getValue())); - Assert.assertTrue(((InetAddress) aMatch.getField(MatchType.NW_SRC) - .getValue()).equals((InetAddress) bMatch.getField( - MatchType.NW_SRC).getValue())); - Assert.assertTrue(((InetAddress) aMatch.getField(MatchType.NW_SRC) - .getMask()).equals((InetAddress) bMatch.getField( - MatchType.NW_SRC).getMask())); - Assert.assertTrue(((InetAddress) aMatch.getField(MatchType.NW_DST) - .getValue()).equals((InetAddress) bMatch.getField( - MatchType.NW_DST).getValue())); - Assert.assertTrue(((InetAddress) aMatch.getField(MatchType.NW_DST) - .getMask()).equals((InetAddress) bMatch.getField( - MatchType.NW_DST).getMask())); - Assert.assertTrue(((Byte) aMatch.getField(MatchType.NW_PROTO) - .getValue()).equals((Byte) bMatch.getField(MatchType.NW_PROTO) - .getValue())); - Assert.assertTrue(((Byte) aMatch.getField(MatchType.NW_TOS).getValue()) - .equals((Byte) bMatch.getField(MatchType.NW_TOS).getValue())); - Assert - .assertTrue(((Short) aMatch.getField(MatchType.TP_SRC) - .getValue()).equals((Short) bMatch.getField( - MatchType.TP_SRC).getValue())); - Assert - .assertTrue(((Short) aMatch.getField(MatchType.TP_DST) - .getValue()).equals((Short) bMatch.getField( - MatchType.TP_DST).getValue())); - - // FlowConverter parses and sets the actions in the same order for sal match and of match - for (short i = 0; i < actions.size(); i++) { - Assert.assertTrue(actions.get(i).equals(bActions.get(i))); - } - } - - - @Ignore - public void testV6MatchToSALMatchToV6MatchConversion() - throws UnknownHostException { - NodeConnector port = NodeConnectorCreator.createNodeConnector( - (short) 24, NodeCreator.createOFNode(6l)); - byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, - (byte) 0x9a, (byte) 0xbc }; - byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, - (byte) 0x5e, (byte) 0x6f }; - InetAddress srcIP = InetAddress - .getByName("2001:420:281:1004:407a:57f4:4d15:c355"); - InetAddress dstIP = InetAddress - .getByName("2001:420:281:1004:e123:e688:d655:a1b0"); - InetAddress ipMask = null;//InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0"); - short ethertype = EtherTypes.IPv6.shortValue(); - short vlan = (short) 27; - byte vlanPr = 3; - Byte tos = 4; - byte proto = IPProtocols.TCP.byteValue(); - short src = (short) 55000; - short dst = 80; - - /* - * Create a SAL Flow aFlow - */ - Match aMatch = new Match(); - - aMatch.setField(MatchType.IN_PORT, port); - aMatch.setField(MatchType.DL_SRC, srcMac); - aMatch.setField(MatchType.DL_DST, dstMac); - aMatch.setField(MatchType.DL_TYPE, ethertype); - aMatch.setField(MatchType.DL_VLAN, vlan); - aMatch.setField(MatchType.DL_VLAN_PR, vlanPr); - aMatch.setField(MatchType.NW_SRC, srcIP, ipMask); - aMatch.setField(MatchType.NW_DST, dstIP, ipMask); - aMatch.setField(MatchType.NW_TOS, tos); - aMatch.setField(MatchType.NW_PROTO, proto); - aMatch.setField(MatchType.TP_SRC, src); - aMatch.setField(MatchType.TP_DST, dst); - - Assert.assertTrue(aMatch.isIPv6()); - - } -} diff --git a/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6ExtensionTest.java b/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6ExtensionTest.java deleted file mode 100644 index 17e33629bf..0000000000 --- a/opendaylight/protocol_plugins/openflow_netty/src/test/java/org/opendaylight/controller/protocol_plugin/openflow/vendorextension/v6extension/V6ExtensionTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension; - -import static org.junit.Assert.fail; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; -import org.openflow.protocol.OFMatch; - -public class V6ExtensionTest { - - /* - @Test - public void testFromString() throws UnknownHostException { - - // This tests creating V6Match using fromString and OFMatch by comparing - // the results to each other - V6Match match = new V6Match(); - V6Match match2 = new V6Match(); - - OFMatch ofm = new OFMatch(); - V6Match match4 = new V6Match(ofm); - - match.fromString(""); - Assert.assertTrue(match.equals(match2)); - match.fromString("any"); - Assert.assertTrue(match.equals(match2)); - Assert.assertTrue(match.equals(match4)); - try { - match.fromString("invalidArgument"); - - fail("Did not throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // passed test for throwing exception. - } - try { - match.fromString("invalidParameter=abcdefg"); - fail("Did not throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // passed test for throwing exception. - } - - match.fromString("input_port=1"); - match.fromString("dl_dst=20:A0:11:10:00:99"); - match.fromString("dl_src=00:10:08:22:12:75"); - - match.fromString("ip_src=10.1.1.1"); - match.fromString("ip_dst=1.2.3.4"); - match.fromString("eth_type=0x800"); - match.fromString("dl_vlan=10"); - match.fromString("dl_vpcp=1"); - match.fromString("nw_proto=6"); - match.fromString("nw_tos=100"); - match.fromString("tp_dst=8080"); - match.fromString("tp_src=60"); - - Assert.assertTrue(match.getInputPort() == 1); - // Assert.assertTrue(match.getIPv6MatchLen()==6); - - ofm.setInputPort((short) 1); - // V6Match is meant for IPv6, but if using OFMatch, it will be set to - // IPv4 values, as OF1.0 doesn't support IPv6. - InetAddress addr = InetAddress.getByName("10.1.1.1"); - int ipsrc = ByteBuffer.wrap(addr.getAddress()).getInt(); - ofm.setNetworkSource(ipsrc); - - addr = InetAddress.getByName("1.2.3.4"); - int ipdst = ByteBuffer.wrap(addr.getAddress()).getInt(); - ofm.setNetworkDestination(ipdst); - - byte[] macSrc = { 0x00, 0x10, 0x08, 0x22, 0x12, 0x75 }; - ofm.setDataLayerSource(macSrc); - byte[] macDst = { 0x20, (byte) 0xA0, 0x11, 0x10, 0x00, (byte) 0x99 }; - ofm.setDataLayerDestination(macDst); - ofm.setDataLayerType((short) 0x800); - ofm.setDataLayerVirtualLan((short) 10); - ofm.setDataLayerVirtualLanPriorityCodePoint((byte) 1); - ofm.setNetworkProtocol((byte) 6); - ofm.setNetworkTypeOfService((byte) 100); - ofm.setTransportSource((short) 60); - ofm.setTransportDestination((short) 8080); - - V6Match match3 = new V6Match(ofm); - - Assert.assertTrue(match.getInputPort() == match3.getInputPort()); - Assert.assertTrue(Arrays.equals(match.getDataLayerSource(), - match3.getDataLayerSource())); - Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(), - match3.getDataLayerDestination())); - Assert.assertTrue(match.getNetworkSrc().equals(match3.getNetworkSrc())); - Assert.assertTrue(match.getNetworkDest() - .equals(match3.getNetworkDest())); - Assert.assertTrue(match.getDataLayerVirtualLan() == match3 - .getDataLayerVirtualLan()); - Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match3 - .getDataLayerVirtualLanPriorityCodePoint()); - Assert.assertTrue(match.getNetworkProtocol() == match3 - .getNetworkProtocol()); - Assert.assertTrue(match.getNetworkTypeOfService() == match3 - .getNetworkTypeOfService()); - Assert.assertTrue(match.getTransportSource() == match3 - .getTransportSource()); - Assert.assertTrue(match.getTransportDestination() == match3 - .getTransportDestination()); - Assert.assertTrue(match.getWildcards() == match3.getWildcards()); - - } - - @Test - public void testReadWriteBuffer() { - V6Match match = new V6Match(); - match.fromString("input_port=1"); - match.fromString("dl_dst=20:A0:11:10:00:99"); - match.fromString("dl_src=00:10:08:22:12:75"); - // writeTo(ByteBuffer) will only write IPv6 - match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333/64"); - match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222/64"); - match.fromString("dl_vlan=10"); - match.fromString("nw_proto=6"); - match.fromString("nw_tos=100"); - match.fromString("tp_dst=8080"); - match.fromString("tp_src=60"); - match.fromString("dl_type=0x800"); - - ByteBuffer data = ByteBuffer.allocateDirect(10000); - match.writeTo(data); - data.flip(); - V6Match match2 = new V6Match(); - match2.readFrom(data); - Assert.assertTrue(match.getInputPort() == match2.getInputPort()); - Assert.assertTrue(Arrays.equals(match.getDataLayerSource(), - match2.getDataLayerSource())); - Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(), - match2.getDataLayerDestination())); - - Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc())); - Assert.assertTrue(match.getNetworkDest() - .equals(match2.getNetworkDest())); - - Assert.assertTrue(match.getDataLayerVirtualLan() == match2 - .getDataLayerVirtualLan()); - // vlan pcp isn't part of write/read buffer - Assert.assertTrue(match.getNetworkProtocol() == match2 - .getNetworkProtocol()); - Assert.assertTrue(match.getNetworkTypeOfService() == match2 - .getNetworkTypeOfService()); - Assert.assertTrue(match.getTransportSource() == match2 - .getTransportSource()); - Assert.assertTrue(match.getTransportDestination() == match2 - .getTransportDestination()); - - } - - @Test - public void testClone() { - V6Match match = new V6Match(); - match.fromString("input_port=1"); - match.fromString("dl_dst=20:A0:11:10:00:99"); - match.fromString("dl_src=00:10:08:22:12:75"); - match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333/64"); - match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222/64"); - match.fromString("dl_vlan=10"); - match.fromString("dl_vpcp=1"); - match.fromString("nw_proto=6"); - match.fromString("nw_tos=100"); - match.fromString("tp_dst=8080"); - match.fromString("tp_src=60"); - match.fromString("dl_type=0x800"); - - V6Match match2 = match.clone(); - Assert.assertTrue(match.getInputPort() == match2.getInputPort()); - Assert.assertTrue(Arrays.equals(match.getDataLayerSource(), - match2.getDataLayerSource())); - Assert.assertTrue(Arrays.equals(match.getDataLayerDestination(), - match2.getDataLayerDestination())); - Assert.assertTrue(match.getNetworkSrc().equals(match2.getNetworkSrc())); - Assert.assertTrue(match.getNetworkDest() - .equals(match2.getNetworkDest())); - Assert.assertTrue(match.getDataLayerVirtualLan() == match2 - .getDataLayerVirtualLan()); - Assert.assertTrue(match.getDataLayerVirtualLanPriorityCodePoint() == match2 - .getDataLayerVirtualLanPriorityCodePoint()); - Assert.assertTrue(match.getNetworkProtocol() == match2 - .getNetworkProtocol()); - Assert.assertTrue(match.getNetworkTypeOfService() == match2 - .getNetworkTypeOfService()); - Assert.assertTrue(match.getTransportSource() == match2 - .getTransportSource()); - Assert.assertTrue(match.getTransportDestination() == match2 - .getTransportDestination()); - Assert.assertTrue(match.getWildcards() == match2.getWildcards()); - } - - @Test - public void testPadding() { - // testing that matchlen+pad keeps the 8byte alignment - V6Match match = new V6Match(); - - match.fromString("input_port=1"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("dl_dst=20:A0:11:10:00:99"); - match.fromString("dl_src=00:10:08:22:12:75"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("ip_src=2001:ddd:3e1:1234:0000:1111:2222:3333"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("ip_dst=2001:123:222:abc:111:aaa:1111:2222"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("dl_vlan=10"); - match.fromString("dl_vpcp=1"); - match.fromString("nw_proto=6"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("nw_tos=100"); - match.fromString("tp_dst=8080"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - match.fromString("tp_src=60"); - Assert.assertTrue((match.getPadSize() + match.getIPv6MatchLen()) % 8 == 0); - } - */ - -} diff --git a/third-party/openflowj_netty/pom.xml b/third-party/openflowj_netty/pom.xml index 176b6f8f01..79073642bb 100644 --- a/third-party/openflowj_netty/pom.xml +++ b/third-party/openflowj_netty/pom.xml @@ -88,36 +88,8 @@ org.jboss.netty.* - org.openflow.example;version="1.0.1"; - uses:="org.openflow.example.cli, - org.openflow.protocol, - org.openflow.io, - org.openflow.protocol.factory", - org.openflow.io;version="1.0.1"; - uses:="org.openflow.protocol, - org.openflow.protocol.factory", - org.openflow.protocol;version="1.0.1"; - uses:="org.openflow.protocol.statistics, - org.openflow.protocol, - org.openflow.protocol.factory", - org.openflow.protocol.action;version="1.0.1"; - uses:="org.openflow.protocol", - org.openflow.protocol.factory;version="1.0.1"; - uses:="org.openflow.protocol.statistics, - org.openflow.protocol, - org.openflow.protocol.action, - org.openflow.protocol.queue", - org.openflow.protocol.queue;version="1.0.2"; - uses:="org.openflow.protocol, - org.openflow.protocol.factory", - org.openflow.protocol.statistics;version="1.0.1"; - uses:="org.openflow.protocol, - org.openflow.protocol.factory", - org.openflow.util;version="1.0.1" + org.openflow.* - - org.jboss.netty;type=!pom;inline=false - @@ -139,11 +111,10 @@ 4.8.1 test - + org.jboss.netty netty 3.2.6.Final -