use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.
the class OF13ActionsSerializerTest method testHeaders.
/**
* Testing correct serialization of actions.
*/
@Test
public void testHeaders() {
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
outputBuilder.setPort(new PortNumber(42L));
outputBuilder.setMaxLength(52);
caseBuilder.setOutputAction(outputBuilder.build());
ActionBuilder actionBuilder = new ActionBuilder();
actionBuilder.setActionChoice(caseBuilder.build());
List<Action> actions = new ArrayList<>();
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
MatchEntryBuilder matchBuilder = new MatchEntryBuilder();
matchBuilder.setOxmClass(OpenflowBasicClass.class);
matchBuilder.setOxmMatchField(InPort.class);
matchBuilder.setHasMask(false);
InPortCaseBuilder inPortCaseBuilder = new InPortCaseBuilder();
InPortBuilder inPortBuilder = new InPortBuilder();
inPortBuilder.setPortNumber(new PortNumber(1L));
inPortCaseBuilder.setInPort(inPortBuilder.build());
matchBuilder.setMatchEntryValue(inPortCaseBuilder.build());
List<MatchEntry> entries = new ArrayList<>();
entries.add(matchBuilder.build());
SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
setFieldBuilder.setMatchEntry(entries);
SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
actionBuilder.setActionChoice(setFieldCaseBuilder.build());
actions.add(actionBuilder.build());
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
ListSerializer.serializeHeaderList(actions, TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, out);
Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 4, out.readUnsignedShort());
Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort());
Assert.assertEquals("Wrong action length", 4, out.readUnsignedShort());
Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.
the class OF10FlowModInputMessageFactoryTest method testFlowModInputMessageFactory.
/**
* Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testFlowModInputMessageFactory() throws Exception {
FlowModInputBuilder builder = new FlowModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
MatchV10Builder matchBuilder = new MatchV10Builder();
matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
matchBuilder.setNwSrcMask((short) 0);
matchBuilder.setNwDstMask((short) 0);
matchBuilder.setInPort(58);
matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));
matchBuilder.setDlVlan(18);
matchBuilder.setDlVlanPcp((short) 5);
matchBuilder.setDlType(42);
matchBuilder.setNwTos((short) 4);
matchBuilder.setNwProto((short) 7);
matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));
matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));
matchBuilder.setTpSrc(6653);
matchBuilder.setTpDst(6633);
builder.setMatchV10(matchBuilder.build());
byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
builder.setCookie(new BigInteger(1, cookie));
builder.setCommand(FlowModCommand.forValue(0));
builder.setIdleTimeout(12);
builder.setHardTimeout(16);
builder.setPriority(1);
builder.setBufferId(2L);
builder.setOutPort(new PortNumber(4422L));
builder.setFlagsV10(new FlowModFlagsV10(true, false, true));
final List<Action> actions = new ArrayList<>();
ActionBuilder actionBuilder = new ActionBuilder();
SetNwDstCaseBuilder nwDstCaseBuilder = new SetNwDstCaseBuilder();
SetNwDstActionBuilder nwDstBuilder = new SetNwDstActionBuilder();
nwDstBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));
nwDstCaseBuilder.setSetNwDstAction(nwDstBuilder.build());
actionBuilder.setActionChoice(nwDstCaseBuilder.build());
actions.add(actionBuilder.build());
actionBuilder = new ActionBuilder();
SetTpSrcCaseBuilder tpSrcCaseBuilder = new SetTpSrcCaseBuilder();
SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder();
tpSrcBuilder.setPort(new PortNumber(42L));
tpSrcCaseBuilder.setSetTpSrcAction(tpSrcBuilder.build());
actionBuilder.setActionChoice(tpSrcCaseBuilder.build());
actions.add(actionBuilder.build());
builder.setAction(actions);
FlowModInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
flowModFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 14, 88);
Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
byte[] dlSrc = new byte[6];
out.readBytes(dlSrc);
Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
byte[] dlDst = new byte[6];
out.readBytes(dlDst);
Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());
Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());
out.skipBytes(1);
Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());
Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());
Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());
out.skipBytes(2);
Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());
Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());
Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());
Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());
byte[] cookieRead = new byte[8];
out.readBytes(cookieRead);
Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);
Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());
Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());
Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());
Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());
Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());
Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());
Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());
Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());
Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());
out.skipBytes(2);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.
the class OF10PacketOutInputMessageFactoryTest method testPacketOutInputWithNoData.
/**
* Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testPacketOutInputWithNoData() throws Exception {
PacketOutInputBuilder builder = new PacketOutInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setBufferId(256L);
builder.setInPort(new PortNumber(257L));
List<Action> actions = new ArrayList<>();
builder.setAction(actions);
builder.setData(null);
PacketOutInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
packetOutFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 13, 16);
// skip packet out message to data index
out.skipBytes(8);
Assert.assertTrue("Unread data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.
the class PacketOutInputMessageFactoryTest method testPacketOutInputWithNoData.
/**
* Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO.
*/
@Test
public void testPacketOutInputWithNoData() throws Exception {
PacketOutInputBuilder builder = new PacketOutInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setBufferId(256L);
builder.setInPort(new PortNumber(256L));
List<Action> actions = new ArrayList<>();
builder.setAction(actions);
builder.setData(null);
PacketOutInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
packetOutFactory.serialize(message, out);
BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 24);
// skip packet out message to data index
out.skipBytes(16);
Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber in project openflowplugin by opendaylight.
the class PortTranslatorUtil method translatePort.
public static NodeConnectorUpdated translatePort(final Short version, final BigInteger datapathId, final Long portNumber, final PortGrouping port) {
OpenflowVersion ofVersion = OpenflowVersion.get(version);
final NodeConnectorUpdatedBuilder builder = InventoryDataServiceUtil.nodeConnectorUpdatedBuilderFromDatapathIdPortNo(datapathId, port.getPortNo(), ofVersion);
FlowCapableNodeConnectorUpdatedBuilder fcncub = new FlowCapableNodeConnectorUpdatedBuilder();
if (ofVersion == OpenflowVersion.OF13) {
fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeatures()));
fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfig()));
fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeatures()));
fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeatures()));
fcncub.setState(PortTranslatorUtil.translatePortState(port.getState()));
fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeatures()));
} else if (ofVersion == OpenflowVersion.OF10) {
fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeaturesV10()));
fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfigV10()));
fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeaturesV10()));
fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeaturesV10()));
fcncub.setState(PortTranslatorUtil.translatePortState(port.getStateV10()));
fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeaturesV10()));
}
if (port instanceof PortStatusMessage) {
if (((PortStatusMessage) port).getReason() != null) {
fcncub.setReason(PortReason.forValue(((PortStatusMessage) port).getReason().getIntValue()));
} else {
LOG.debug("PortStatus Message has reason as null");
}
}
fcncub.setCurrentSpeed(port.getCurrSpeed());
fcncub.setHardwareAddress(port.getHwAddr());
fcncub.setMaximumSpeed(port.getMaxSpeed());
fcncub.setName(port.getName());
fcncub.setPortNumber(OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, portNumber));
builder.addAugmentation(FlowCapableNodeConnectorUpdated.class, fcncub.build());
return builder.build();
}
Aggregations