updated method nodeAdded in SalRegistrationManager to store switch features in NodeUpdated
do not merge before: http://git.opendaylight.org/gerrit/3681
Change-Id: I4ddf9097185914abe1575bf54e3c3d7d72ccdec6
Signed-off-by: Juraj Sebin <jsebin@cisco.com>
public static final short OFPP_ALL = ((short)0xfffc);
public static final short OFPP_LOCAL = ((short)0xfffe);
+
}
--- /dev/null
+/**
+ * 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.openflowplugin.openflow.md.core.sal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FeatureCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityArpMatchIp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityIpReasm;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityPortStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityQueueStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityReserved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityStp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityTableStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeaturesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+
+/**
+ * SwitchFeature builder for OF 1.0
+ *
+ * @author jsebin
+ *
+ */
+public class BuildSwitchCapabilitiesOF10 implements BuildSwitchFeatures {
+
+ private static BuildSwitchCapabilitiesOF10 instance = new BuildSwitchCapabilitiesOF10();
+
+ private BuildSwitchCapabilitiesOF10() {}
+
+ /**
+ * Get singleton instance
+ *
+ * @return instance
+ */
+ public static BuildSwitchCapabilitiesOF10 getInstance() {
+ return instance;
+ }
+
+ @Override
+ public SwitchFeatures build(GetFeaturesOutput features) {
+
+ SwitchFeaturesBuilder builderSwFeatures = new SwitchFeaturesBuilder();
+ builderSwFeatures.setMaxBuffers(features.getBuffers());
+ builderSwFeatures.setMaxTables(features.getTables());
+
+ List<Class<? extends FeatureCapability>> capabilities = new ArrayList<>();
+
+ if(features.getCapabilitiesV10().isOFPCARPMATCHIP()) {
+ capabilities.add(FlowFeatureCapabilityArpMatchIp.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCFLOWSTATS()) {
+ capabilities.add(FlowFeatureCapabilityFlowStats.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCIPREASM()) {
+ capabilities.add(FlowFeatureCapabilityIpReasm.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCPORTSTATS()) {
+ capabilities.add(FlowFeatureCapabilityPortStats.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCQUEUESTATS()) {
+ capabilities.add(FlowFeatureCapabilityQueueStats.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCRESERVED()) {
+ capabilities.add(FlowFeatureCapabilityReserved.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCSTP()) {
+ capabilities.add(FlowFeatureCapabilityStp.class);
+ }
+ if(features.getCapabilitiesV10().isOFPCTABLESTATS()) {
+ capabilities.add(FlowFeatureCapabilityTableStats.class);
+ }
+
+ builderSwFeatures.setCapabilities(capabilities);
+
+ return builderSwFeatures.build();
+ }
+
+
+}
--- /dev/null
+/**
+ * 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.openflowplugin.openflow.md.core.sal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FeatureCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityFlowStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityGroupStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityIpReasm;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityPortBlocked;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityPortStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityQueueStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityTableStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeaturesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+
+/**
+ * SwitchFeature builder for OF 1.3
+ *
+ * @author jsebin
+ *
+ */
+public class BuildSwitchCapabilitiesOF13 implements BuildSwitchFeatures {
+
+private static BuildSwitchCapabilitiesOF13 instance = new BuildSwitchCapabilitiesOF13();
+
+ private BuildSwitchCapabilitiesOF13() {}
+
+ /**
+ * Get singleton instance
+ *
+ * @return instance
+ */
+ public static BuildSwitchCapabilitiesOF13 getInstance() {
+ return instance;
+ }
+
+ @Override
+ public SwitchFeatures build(GetFeaturesOutput features) {
+
+ SwitchFeaturesBuilder builderSwFeatures = new SwitchFeaturesBuilder();
+ builderSwFeatures.setMaxBuffers(features.getBuffers());
+ builderSwFeatures.setMaxTables(features.getTables());
+
+ List<Class<? extends FeatureCapability>> capabilities = new ArrayList<>();
+
+ if(features.getCapabilities().isOFPCFLOWSTATS()) {
+ capabilities.add(FlowFeatureCapabilityFlowStats.class);
+ }
+ if(features.getCapabilities().isOFPCGROUPSTATS()) {
+ capabilities.add(FlowFeatureCapabilityGroupStats.class);
+ }
+ if(features.getCapabilities().isOFPCIPREASM()) {
+ capabilities.add(FlowFeatureCapabilityIpReasm.class);
+ }
+ if(features.getCapabilities().isOFPCPORTBLOCKED()) {
+ capabilities.add(FlowFeatureCapabilityPortBlocked.class);
+ }
+ if(features.getCapabilities().isOFPCPORTSTATS()) {
+ capabilities.add(FlowFeatureCapabilityPortStats.class);
+ }
+ if(features.getCapabilities().isOFPCQUEUESTATS()) {
+ capabilities.add(FlowFeatureCapabilityQueueStats.class);
+ }
+ if(features.getCapabilities().isOFPCTABLESTATS()) {
+ capabilities.add(FlowFeatureCapabilityTableStats.class);
+ }
+
+ builderSwFeatures.setCapabilities(capabilities);
+
+ return builderSwFeatures.build();
+ }
+
+}
--- /dev/null
+/**
+ * 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.openflowplugin.openflow.md.core.sal;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+
+/**
+ * Common interface for SwitchFeatures builders for different OF versions
+ *
+ * @author jsebin
+ *
+ */
+public interface BuildSwitchFeatures {
+
+ /**
+ *
+ * @param features {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput}
+ * @return {@link org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures}
+ */
+ public SwitchFeatures build(GetFeaturesOutput features);
+
+}
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionListener;
import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
private NotificationProviderService publishService;
private DataProviderService dataService;
+
+ private SwitchFeaturesUtil swFeaturesUtil;
+
+ public SalRegistrationManager() {
+ swFeaturesUtil = SwitchFeaturesUtil.getInstance();
+ }
public NotificationProviderService getPublishService() {
return publishService;
NodeUpdatedBuilder builder = new NodeUpdatedBuilder();
builder.setId(sw.getNodeId());
builder.setNodeRef(nodeRef);
+
+ FlowCapableNodeUpdatedBuilder builder2 = new FlowCapableNodeUpdatedBuilder();
+ builder2.setSwitchFeatures(swFeaturesUtil.buildSwitchFeatures(features));
+ builder.addAugmentation(FlowCapableNodeUpdated.class, builder2.build());
+
return builder.build();
}
--- /dev/null
+/**
+ * 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.openflowplugin.openflow.md.core.sal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author jsebin
+ *
+ */
+public class SwitchFeaturesUtil {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(SwitchFeaturesUtil.class);
+
+ private static SwitchFeaturesUtil instance = new SwitchFeaturesUtil();
+ private Map<Short, BuildSwitchFeatures> swFeaturesBuilders;
+
+ private SwitchFeaturesUtil() {
+ swFeaturesBuilders = new HashMap<>();
+ swFeaturesBuilders.put((short) 1, BuildSwitchCapabilitiesOF10.getInstance());
+ swFeaturesBuilders.put((short) 4, BuildSwitchCapabilitiesOF13.getInstance());
+ }
+
+ /**
+ * Get singleton instance
+ *
+ * @return instance
+ */
+ public static SwitchFeaturesUtil getInstance() {
+ return instance;
+ }
+
+ /**
+ * @param features {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput}
+ * @return switch features
+ */
+ public SwitchFeatures buildSwitchFeatures(GetFeaturesOutput features) {
+
+ if(swFeaturesBuilders.containsKey(features.getVersion()) == true) {
+ LOG.info("map contains version {}", features.getVersion());
+ try {
+ return swFeaturesBuilders.get(features.getVersion()).build(features);
+ } catch (NullPointerException e) {
+ LOG.error("error while building switch features {}", e);
+ }
+ }
+ else {
+ LOG.warn("unknown version: {}", features.getVersion());
+ }
+
+ return null;
+ }
+
+}
--- /dev/null
+/**
+ * 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.openflowplugin.openflow.md.core.sal;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
+
+/**
+ * Tests for setting switch features for different version of OF plugin
+ *
+ * @author jsebin
+ *
+ */
+public class SwitchFeaturesUtilTest {
+
+ private GetFeaturesOutputBuilder featuresOutputBuilder;
+ private SwitchFeaturesUtil swUtil;
+
+
+ /**
+ * initialization of {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder GetFeaturesOutputBuilder}
+ * and {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil SwitchFeaturesUtil}
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ featuresOutputBuilder = new GetFeaturesOutputBuilder();
+ swUtil = SwitchFeaturesUtil.getInstance();
+ }
+
+ /**
+ * @throws Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ featuresOutputBuilder = null;
+ swUtil = null;
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for OF 1.0 version
+ * and switch feature capabilities
+ * .
+ */
+ @Test
+ public void testSwFeaturesCapabilitiesV10() {
+ CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
+ featuresOutputBuilder.setCapabilitiesV10(capabilities).setVersion((short) 1);
+
+ Assert.assertNotNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for OF 1.3 version
+ * and switch feature capabilities
+ * .
+ */
+ @Test
+ public void testSwFeaturesCapabilitiesV13() {
+ Capabilities capabilities = new Capabilities(true, false, true, false, true, false, true);
+ featuresOutputBuilder.setCapabilities(capabilities).setCapabilitiesV10(null).setVersion((short) 4);
+
+ Assert.assertNotNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for malformed switch feature capabilities
+ * - at least one feature is null
+ * .
+ */
+ //@Test TODO:do we need to check if capability is null?
+ public void testSwFeaturesCapabilitiesMalformed() {
+ CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, null);
+ featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 1);
+
+ Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for mismatch between
+ * version and switch feature capabilities
+ * .
+ */
+ @Test
+ public void testSwFeaturesCapabilitiesVersionMismatch() {
+ CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
+ featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 4);
+
+ Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.SwitchFeaturesUtil#buildSwitchFeatures} for nonexisting version
+ * .
+ */
+ @Test
+ public void testSwFeaturesCapabilitiesNonexistingVersion() {
+ CapabilitiesV10 capabilities = new CapabilitiesV10( true, false, true, false, true, false, true, false);
+ featuresOutputBuilder.setCapabilitiesV10(capabilities).setCapabilities(null).setVersion((short) 0);
+
+ Assert.assertNull(swUtil.buildSwitchFeatures(featuresOutputBuilder.build()));
+ }
+}