X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Finternal%2FReadServiceFilter.java;h=bcb01b1392ac8661f2ee6aeb3db5e34c47362a41;hp=1b71c3bec34f70b382af55c094e7acb7f86f0fdf;hb=refs%2Fchanges%2F18%2F418%2F6;hpb=0f846fcbc207a4213ac133e1d08a305fc72168ba diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java index 1b71c3bec3..bcb01b1392 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/ReadServiceFilter.java @@ -33,6 +33,7 @@ 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.NodeTable; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.flowprogrammer.Flow; import org.opendaylight.controller.sal.match.Match; @@ -40,10 +41,12 @@ 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.reader.NodeTableStatistics; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.NodeConnectorCreator; import org.opendaylight.controller.sal.utils.NodeCreator; - +import org.opendaylight.controller.sal.utils.NodeTableCreator; +import org.openflow.protocol.statistics.OFTableStatistics; /** * Read Service shim layer which is in charge of filtering the flow statistics * based on container. It is a Global instance. @@ -58,6 +61,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, private IController controller = null; private IOFStatisticsManager statsMgr = null; private Map> containerToNc; + private Map> containerToNt; public void setController(IController core) { this.controller = core; @@ -76,6 +80,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, */ void init() { containerToNc = new HashMap>(); + containerToNt = new HashMap>(); } /** @@ -174,9 +179,9 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, long sid = (Long) node.getID(); List ofList = (cached == true) ? statsMgr .getOFDescStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.DESC, null); + OFStatisticsType.DESC, null); - return new DescStatisticsConverter(ofList).getHwDescription(); + return new DescStatisticsConverter(ofList).getHwDescription(); } /** @@ -235,6 +240,28 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, return newList; } + + public List filterTableListPerContainer( + String container, long switchId, List list) { + if (list == null) { + return null; + } + + // Create new filtered list of node tables + List newList = new ArrayList(); + + for (OFStatistics stat : list) { + OFTableStatistics target = (OFTableStatistics) stat; + NodeTable nt = NodeTableCreator.createOFNodeTable( + target.getTableId(), NodeCreator.createOFNode(switchId)); + if (containerOwnsNodeTable(container, nt)) { + newList.add(target); + } + } + + return newList; + } + /** * Returns whether the specified flow (flow match + actions) * belongs to the container @@ -251,7 +278,7 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, } return (flowPortsBelongToContainer(container, node, flow) && flowVlanBelongsToContainer(container, node, flow) && flowSpecAllowsFlow( - container, flow.getMatch())); + container, flow.getMatch())); } /** @@ -270,6 +297,22 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, return (portSet == null) ? false : portSet.contains(p); } + /** + * Returns whether the passed NodeConnector belongs to the container + * + * @param container container name + * @param table node table to test + * @return true if belongs false otherwise + */ + public boolean containerOwnsNodeTable(String container, NodeTable table) { + // All node table belong to the default container + if (container.equals(GlobalConstants.DEFAULT.toString())) { + return true; + } + Set tableSet = containerToNt.get(container); + return (tableSet == null) ? false : tableSet.contains(table); + } + /** * Returns whether the container flowspec allows the passed flow * @@ -382,11 +425,11 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, short portId = (Short) connector.getID(); List ofList = (cached == true) ? statsMgr .getOFPortStatistics(sid, portId) : statsMgr.queryStatistics( - sid, OFStatisticsType.PORT, portId); + sid, OFStatisticsType.PORT, portId); - List ncStatistics = new PortStatisticsConverter( - sid, ofList).getNodeConnectorStatsList(); - return (ncStatistics.isEmpty()) ? new NodeConnectorStatistics() + List ncStatistics = new PortStatisticsConverter( + sid, ofList).getNodeConnectorStatsList(); + return (ncStatistics.isEmpty()) ? new NodeConnectorStatistics() : ncStatistics.get(0); } @@ -397,12 +440,12 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, long sid = (Long) node.getID(); List ofList = (cached == true) ? statsMgr .getOFPortStatistics(sid) : statsMgr.queryStatistics(sid, - OFStatisticsType.FLOW, null); + OFStatisticsType.FLOW, null); - List filteredList = filterPortListPerContainer( - containerName, sid, ofList); + List filteredList = filterPortListPerContainer( + containerName, sid, ofList); - return new PortStatisticsConverter(sid, filteredList) + return new PortStatisticsConverter(sid, filteredList) .getNodeConnectorStatsList(); } @@ -418,4 +461,39 @@ public class ReadServiceFilter implements IPluginReadServiceFilter, return statsMgr.getTransmitRate(switchId, port); } + @Override + public NodeTableStatistics readNodeTable(String containerName, + NodeTable table, boolean cached) { + if (!containerOwnsNodeTable(containerName, table)) { + return null; + } + Node node = table.getNode(); + long sid = (Long) node.getID(); + Byte tableId = (Byte) table.getID(); + List ofList = (cached == true) ? statsMgr + .getOFTableStatistics(sid, tableId) : statsMgr.queryStatistics( + sid, OFStatisticsType.TABLE, tableId); + + List ntStatistics = new TableStatisticsConverter( + sid, ofList).getNodeTableStatsList(); + + return (ntStatistics.isEmpty()) ? new NodeTableStatistics() + : ntStatistics.get(0); + } + + @Override + public List readAllNodeTable(String containerName, + Node node, boolean cached) { + long sid = (Long) node.getID(); + List ofList = (cached == true) ? statsMgr + .getOFTableStatistics(sid) : statsMgr.queryStatistics(sid, + OFStatisticsType.FLOW, null); + + List filteredList = filterTableListPerContainer( + containerName, sid, ofList); + + return new TableStatisticsConverter(sid, filteredList) + .getNodeTableStatsList(); + } + }