- introduced simple test for PacketReceivedTranslator
- fixed asterix in inports
Change-Id: I172d7b2db82a552140e5fd3822d080df9cbb97f9
Signed-off-by: Timotej Kubas <tkubas@cisco.com>
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.*;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceReplyProcessor;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.api.openflow.device.XidGenerator;
import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.impl.device.translator.PortUpdateTranslator;
import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.openflowplugin.impl.device.translator.PortUpdateTranslator;
import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures;
import org.opendaylight.yangtools.yang.binding.ChildOf;
*/
package org.opendaylight.openflowplugin.impl.device.translator;
*/
package org.opendaylight.openflowplugin.impl.device.translator;
+import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
// extract the port number
Long port = null;
// extract the port number
Long port = null;
- if(input.getVersion() == OpenflowVersion.OF10.getVersion()) {
+ if(input.getVersion() == OFConstants.OFP_VERSION_1_0 && input.getInPort() != null) {
port = input.getInPort().longValue();
port = input.getInPort().longValue();
- } else if (input.getVersion() == OpenflowVersion.OF13.getVersion()) {
+ } else if (input.getVersion() == OFConstants.OFP_VERSION_1_3) {
if (input.getMatch() != null && input.getMatch().getMatchEntry() != null) {
port = getPortNumberFromMatch(input.getMatch().getMatchEntry());
}
if (input.getMatch() != null && input.getMatch().getMatchEntry() != null) {
port = getPortNumberFromMatch(input.getMatch().getMatchEntry());
}
//TODO connection cookie from connection distinguisher
// packetReceivedBuilder.setConnectionCookie(new ConnectionCookie(input.getCookie().longValue()));
packetReceivedBuilder.setPayload(input.getData());
//TODO connection cookie from connection distinguisher
// packetReceivedBuilder.setConnectionCookie(new ConnectionCookie(input.getCookie().longValue()));
packetReceivedBuilder.setPayload(input.getData());
- packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
- packetReceivedBuilder.setIngress(InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(datapathId, port, OpenflowVersion.get(input.getVersion())));
-
+ // get the Cookie if it exists
+ if (input.getCookie() != null) {
+ packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
+ }
+ if(port != null) {
+ packetReceivedBuilder.setIngress(InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(datapathId, port, OpenflowVersion.get(input.getVersion())));
+ }
packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
- packetReceivedBuilder.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId(input.getTableId().getValue().shortValue()));
+ if(input.getTableId() != null) {
+ packetReceivedBuilder.setTableId(new org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId(input.getTableId().getValue().shortValue()));
+ }
- org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
- packetReceivedBuilder.setMatch(packetInMatch);
+ if(input.getMatch() != null) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
+ packetReceivedBuilder.setMatch(packetInMatch);
+ }
return packetReceivedBuilder.build();
}
return packetReceivedBuilder.build();
}
*/
package org.opendaylight.openflowplugin.impl.device.translator;
*/
package org.opendaylight.openflowplugin.impl.device.translator;
+import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
// TODO Auto-generated method stub
FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
//OF1.0
// TODO Auto-generated method stub
FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
//OF1.0
- if(input.getVersion() == OpenflowVersion.OF10.getVersion()) {
+ if(input.getVersion() == OFConstants.OFP_VERSION_1_0) {
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
- } else if (input.getVersion() == OpenflowVersion.OF13.getVersion()) {
+ } else if (input.getVersion() == OFConstants.OFP_VERSION_1_3) {
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
package org.opendaylight.openflowplugin.impl.device.translator;
package org.opendaylight.openflowplugin.impl.device.translator;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
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.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+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.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.impl.device.DeviceContextImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
import org.opendaylight.openflowplugin.impl.device.DeviceContextImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
+import java.math.BigInteger;
/**
* Created by tkubas on 4/1/15.
/**
* Created by tkubas on 4/1/15.
@RunWith(MockitoJUnitRunner.class)
public class PacketReceivedTranslatorTest {
@RunWith(MockitoJUnitRunner.class)
public class PacketReceivedTranslatorTest {
+ @Mock
+ ConnectionContext connectionContext;
+ @Mock
+ FeaturesReply featuresReply;
+ @Mock
+ DeviceState deviceState;
+ @Mock
+ DataBroker dataBroker;
@Mock
DeviceContext deviceContext;
@Mock
DeviceContext deviceContext;
+ String data = "Test_Data";
@Before
public void setUp() throws Exception {
@Before
public void setUp() throws Exception {
+ Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
+ Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply);
+ Mockito.when(featuresReply.getDatapathId()).thenReturn(BigInteger.TEN);
}
@Test
public void testTranslate() throws Exception {
PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator();
}
@Test
public void testTranslate() throws Exception {
PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator();
-// packetReceivedTranslator.translate()
+ PacketInMessage packetInMessage = createPacketInMessage(data.getBytes(), 5);
+ PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceContext, null);
+ Assert.assertArrayEquals(packetInMessage.getData(), packetReceived.getPayload());
+ Assert.assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController",
+ packetReceived.getPacketInReason().getName());
}
private static PacketInMessage createPacketInMessage(final byte[] data,
final java.lang.Integer port) {
PacketInReason reason = PacketInReason.OFPRACTION;
return new PacketInMessageBuilder()
}
private static PacketInMessage createPacketInMessage(final byte[] data,
final java.lang.Integer port) {
PacketInReason reason = PacketInReason.OFPRACTION;
return new PacketInMessageBuilder()
- .setVersion((short) EncodeConstants.OF10_VERSION_ID)
- .setInPort(port).setData(data).setReason(reason).build();
+ .setVersion((short) OFConstants.OFP_VERSION_1_0)
+ .setData(data).setReason(reason).build();
}
}
\ No newline at end of file
}
}
\ No newline at end of file