X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Ftranslator%2FPacketReceivedTranslatorTest.java;h=d5487950efca87b0baf1c8580a5ccb15d7b77a4e;hb=cfe3a97837951ebbedb337dc988027f10c49f714;hp=8df7184a4db121753bb618b03b027dca74428bf6;hpb=32adb449e18b7ba45574dd1e05e26eef64a95db2;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/PacketReceivedTranslatorTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/PacketReceivedTranslatorTest.java index 8df7184a4d..d5487950ef 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/PacketReceivedTranslatorTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/PacketReceivedTranslatorTest.java @@ -1,27 +1,34 @@ +/* + * 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.translator; import com.google.common.collect.Lists; import java.math.BigInteger; -import java.util.Arrays; +import java.util.Collections; import java.util.List; - import org.junit.Assert; import org.junit.Before; 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.controller.md.sal.binding.api.DataBroker; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; -import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; 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.node.NodeConnector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; @@ -43,10 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.Pa import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -/** - * Created by tkubas on 4/1/15. - */ - @RunWith(MockitoJUnitRunner.class) public class PacketReceivedTranslatorTest { @@ -63,32 +66,23 @@ public class PacketReceivedTranslatorTest { @Mock DeviceContext deviceContext; @Mock - List phyPorts; + DeviceInfo deviceInfo; @Mock PhyPort phyPort; - static final Long PORT_NO = 5l; - static final Long PORT_NO_DS = 6l; - static final String DATA = "Test_Data"; - static final Long PORT_NUM_VALUE = 11l; + ConvertorManager convertorManager; - public PacketReceivedTranslatorTest() { - OpenflowPortsUtil.init(); - } + static final Long PORT_NO = 5L; + static final Long PORT_NO_DS = 6L; + static final String DATA = "Test_Data"; + static final Long PORT_NUM_VALUE = 11L; @Before public void setUp() throws Exception { - final List phyPorts = Arrays.asList(phyPort); - - Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); - Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply); - Mockito.when(featuresReply.getDatapathId()).thenReturn(BigInteger.TEN); - Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); - Mockito.when(deviceState.getFeatures()).thenReturn(getFeaturesOutput); - Mockito.when(getFeaturesOutput.getDatapathId()).thenReturn(BigInteger.TEN); - Mockito.when(getFeaturesOutput.getPhyPort()).thenReturn(phyPorts); - Mockito.when(phyPort.getPortNo()).thenReturn(PORT_NO_DS); + final List phyPorts = Collections.singletonList(phyPort); + convertorManager = ConvertorManagerFactory.createDefaultManager(); + + Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN); } @Test @@ -96,18 +90,16 @@ public class PacketReceivedTranslatorTest { final KeyedInstanceIdentifier nodePath = KeyedInstanceIdentifier .create(Nodes.class) .child(Node.class, new NodeKey(new NodeId("openflow:10"))); - final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(); + final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(convertorManager); final PacketInMessage packetInMessage = createPacketInMessage(DATA.getBytes(), PORT_NO); - Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath); - final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceContext, null); + final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceInfo, null); Assert.assertArrayEquals(packetInMessage.getData(), packetReceived.getPayload()); Assert.assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController", packetReceived.getPacketInReason().getName()); Assert.assertEquals("openflow:10:" + PORT_NO, - packetReceived.getIngress().getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class) - .getId().getValue()); + packetReceived.getIngress().getValue().firstKeyOf(NodeConnector.class).getId().getValue()); Assert.assertEquals(0L, packetReceived.getFlowCookie().getValue().longValue()); Assert.assertEquals(42L, packetReceived.getTableId().getValue().longValue()); } @@ -141,7 +133,8 @@ public class PacketReceivedTranslatorTest { .setVersion(OFConstants.OFP_VERSION_1_3); BigInteger dpid = BigInteger.TEN; - final Match packetInMatch = PacketReceivedTranslator.getPacketInMatch(inputBld.build(), dpid); + final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(convertorManager); + final Match packetInMatch = packetReceivedTranslator.getPacketInMatch(inputBld.build(), dpid); Assert.assertNotNull(packetInMatch.getInPort()); Assert.assertEquals("openflow:10:" + PORT_NUM_VALUE, packetInMatch.getInPort().getValue()); @@ -163,4 +156,4 @@ public class PacketReceivedTranslatorTest { builder.setHasMask(hasMask); return builder; } -} \ No newline at end of file +}