--- /dev/null
+/*
+ *
+ * * Copyright (c) 2015 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.impl.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class DeviceStateUtilTest {
+
+ @Mock
+ private DeviceState mockedDeviceState;
+
+ @After
+ public void tearDown() {
+ Mockito.verifyNoMoreInteractions(mockedDeviceState);
+ }
+
+ @Test
+ public void setDeviceStateBasedOnV13CapabilitiesTest() {
+ final Capabilities dummyCapabilities = new Capabilities(false,false,false,false,false,false,false);
+
+ DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(mockedDeviceState, dummyCapabilities);
+
+ verify(mockedDeviceState).setFlowStatisticsAvailable(false);
+ verify(mockedDeviceState).setTableStatisticsAvailable(false);
+ verify(mockedDeviceState).setPortStatisticsAvailable(false);
+ verify(mockedDeviceState).setQueueStatisticsAvailable(false);
+ verify(mockedDeviceState).setGroupAvailable(false);
+ }
+
+ @Test
+ public void setDeviceStateBasedOnV10CapabilitiesTest() {
+ CapabilitiesV10 dummyCapabilitiesV10 = new CapabilitiesV10(false, false, false, false, false, false, false, false);
+
+ DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(mockedDeviceState, dummyCapabilitiesV10);
+ verify(mockedDeviceState).setFlowStatisticsAvailable(false);
+ verify(mockedDeviceState).setTableStatisticsAvailable(false);
+ verify(mockedDeviceState).setPortStatisticsAvailable(false);
+ verify(mockedDeviceState).setQueueStatisticsAvailable(false);
+ }
+
+ @Test
+ public void createNodeInstanceIdentifierTest() {
+ final NodeId nodeId = new NodeId("dummyId");
+ final KeyedInstanceIdentifier<Node, NodeKey> expectedII = InstanceIdentifier.create(Nodes.class).child(Node
+ .class, new NodeKey(nodeId));
+
+ final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil
+ .createNodeInstanceIdentifier(nodeId);
+ assertEquals(expectedII, nodeInstanceIdentifier);
+ }
+}
--- /dev/null
+/*
+ *
+ * * Copyright (c) 2015 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.impl.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
+
+public class MatchUtilTest {
+
+ private static final MacAddress ZERO_MAC_ADDRESS = new MacAddress("00:00:00:00:00:00");
+ private static final Ipv4Address ZERO_IPV4_ADDRESS = new Ipv4Address("0.0.0.0");
+
+ @Test
+ public void createEmptyV10MatchTest() {
+ MatchV10Builder expectedV10Match = expectedV10Match();
+ MatchV10Builder emptyV10Match = MatchUtil.createEmptyV10Match();
+ assertEquals(expectedV10Match.build(),emptyV10Match.build());
+ }
+
+ private MatchV10Builder expectedV10Match() {
+ Short zeroShort = Short.valueOf("0");
+ Integer zeroInteger = Integer.valueOf(0);
+ MatchV10Builder matchV10Builder = new MatchV10Builder();
+ matchV10Builder.setDlDst( ZERO_MAC_ADDRESS);
+ matchV10Builder.setDlSrc(ZERO_MAC_ADDRESS);
+ matchV10Builder.setDlType(zeroInteger);
+ matchV10Builder.setDlVlan(zeroInteger);
+ matchV10Builder.setDlVlanPcp(zeroShort);
+ matchV10Builder.setInPort(zeroInteger);
+ matchV10Builder.setNwDst(ZERO_IPV4_ADDRESS);
+ matchV10Builder.setNwDstMask(zeroShort);
+ matchV10Builder.setNwProto(zeroShort);
+ matchV10Builder.setNwSrc(ZERO_IPV4_ADDRESS);
+ matchV10Builder.setNwSrcMask(zeroShort);
+ matchV10Builder.setNwTos(zeroShort);
+ matchV10Builder.setTpDst(zeroInteger);
+ matchV10Builder.setTpSrc(zeroInteger);
+ FlowWildcardsV10 flowWildcardsV10 = new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true);
+ matchV10Builder.setWildcards(flowWildcardsV10);
+ return matchV10Builder;
+ }
+}
--- /dev/null
+/*
+ *
+ * * Copyright (c) 2015 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.impl.util;
+
+
+import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.*;
+
+import java.math.BigInteger;
+import org.junit.Test;
+
+import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+public class MdSalRegistratorUtilsTest {
+
+ /**
+ * Number of currently registrated services (can be changed) in {@link MdSalRegistratorUtils#registerServices
+ * (RpcContext, DeviceContext)}
+ */
+ private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 9;
+
+ @Test
+ public void registerServiceTest() {
+
+ final RpcContext mockedRpcContext = mock(RpcContext.class);
+ final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
+ final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
+
+ final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
+ when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
+
+ final BigInteger mockedDataPathId = mock(BigInteger.class);
+ when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
+
+ when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
+ MdSalRegistratorUtils.registerServices(mockedRpcContext,mockedDeviceContext);
+ verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation(any
+ (RpcService.class.getClass()), any(RpcService.class));
+ }
+
+}
--- /dev/null
+/*
+ *
+ * * Copyright (c) 2015 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.impl.util;
+
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_0;
+import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_3;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
+import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
+import org.opendaylight.openflowplugin.impl.translator.TranslatorKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
+
+public class TranslatorLibratyUtilTest {
+
+ private static class TranslatorLibrarianTestImpl implements TranslatorLibrarian {
+
+ private TranslatorLibrary translatorLibrary;
+
+ @Override
+ public TranslatorLibrary oook() {
+ return translatorLibrary;
+ }
+
+ @Override
+ public void setTranslatorLibrary(TranslatorLibrary translatorLibrary) {
+ this.translatorLibrary = translatorLibrary;
+ }
+ }
+
+ private TranslatorLibrarianTestImpl translatorLibrarian;
+
+ @Before
+ public void setUp() {
+ translatorLibrarian = new TranslatorLibrarianTestImpl();
+ }
+
+ @Test
+ public void setBasicTranslatorLibraryTest() {
+ TranslatorLibraryUtil.setBasicTranslatorLibrary(translatorLibrarian);
+ TranslatorLibrary translatorLibrary = translatorLibrarian.oook();
+
+ TranslatorKeyFactory of13TranslatorKeyFactory = new TranslatorKeyFactory(OFP_VERSION_1_3);
+ TranslatorKeyFactory of10TranslatorKeyFactory = new TranslatorKeyFactory(OFP_VERSION_1_0);
+
+ MessageTranslator<Object, Object> translator;
+ translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory
+ .createTranslatorKey(PacketIn.class));
+ assertNotNull(translator);
+
+ translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory.createTranslatorKey(PortGrouping
+ .class));
+ assertNotNull(translator);
+
+ translator = translatorLibrary.lookupTranslator(of13TranslatorKeyFactory.createTranslatorKey
+ (MultipartReplyAggregateCase
+ .class));
+ assertNotNull(translator);
+
+ translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(PacketIn.class));
+ assertNotNull(translator);
+
+ translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(PortGrouping.class));
+ assertNotNull(translator);
+
+ translator = translatorLibrary.lookupTranslator(of10TranslatorKeyFactory.createTranslatorKey(MultipartReplyAggregateCase
+ .class));
+ assertNotNull(translator);
+ }
+
+}