Search in sources :

Example 16 with MplsLabel

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel in project openflowplugin by opendaylight.

the class PacketInMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    // Buffer id - irrelevant
    buffer.writeInt(EncodeConstants.EMPTY_VALUE);
    // Total len - irrelevant
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeByte(REASON);
    buffer.writeByte(TABLE_ID);
    buffer.writeLong(FLOW_COOKIE);
    // Match header
    int matchStartIndex = buffer.writerIndex();
    buffer.writeShort(OXM_MATCH_TYPE_CODE);
    int matchLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    // MplsLabel match
    buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
    buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
    buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    buffer.writeInt(MPLS_LABEL);
    // Match footer
    int matchLength = buffer.writerIndex() - matchStartIndex;
    buffer.setShort(matchLengthIndex, matchLength);
    int paddingRemainder = matchLength % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    buffer.writeZero(PADDING_IN_PACKET_IN_HEADER);
    buffer.writeBytes(PAYLOAD);
    final PacketInMessage message = (PacketInMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(XID, message.getXid().intValue());
    assertEquals(PacketInUtil.getMdSalPacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason.forValue(REASON)), message.getPacketInReason());
    assertEquals(TABLE_ID, message.getTableId().getValue().shortValue());
    assertEquals(FLOW_COOKIE, message.getFlowCookie().getValue().longValue());
    assertEquals(MPLS_LABEL, message.getMatch().getProtocolMatchFields().getMplsLabel().intValue());
    assertArrayEquals(PAYLOAD, message.getPayload());
    assertEquals(buffer.readableBytes(), 0);
}
Also used : PacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Example 17 with MplsLabel

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel in project openflowplugin by opendaylight.

the class MplsLabelEntryDeserializer method deserializeEntry.

@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
    processHeader(message);
    final long mplsLabel = message.readUnsignedInt();
    if (Objects.isNull(builder.getProtocolMatchFields())) {
        builder.setProtocolMatchFields(new ProtocolMatchFieldsBuilder().setMplsLabel(mplsLabel).build());
    } else if (Objects.isNull(builder.getProtocolMatchFields().getMplsLabel())) {
        builder.setProtocolMatchFields(new ProtocolMatchFieldsBuilder(builder.getProtocolMatchFields()).setMplsLabel(mplsLabel).build());
    } else {
        throwErrorOnMalformed(builder, "protocolMatchFields", "mplsLabel");
    }
}
Also used : ProtocolMatchFieldsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder)

Example 18 with MplsLabel

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel in project openflowplugin by opendaylight.

the class FlowMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Flow header
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeLong(COOKIE);
    buffer.writeLong(COOKIE_MASK);
    buffer.writeByte(TABLE_ID);
    buffer.writeByte(COMMAND.getIntValue());
    buffer.writeShort(IDLE_TIMEOUT);
    buffer.writeShort(HARD_TIMEOUT);
    buffer.writeShort(PRIORITY);
    buffer.writeInt(BUFFER_ID);
    buffer.writeInt(OUT_PORT);
    buffer.writeInt(OUT_GROUP);
    buffer.writeShort(ByteBufUtils.fillBitMask(0, FLAGS.isSENDFLOWREM(), FLAGS.isCHECKOVERLAP(), FLAGS.isRESETCOUNTS(), FLAGS.isNOPKTCOUNTS(), FLAGS.isNOBYTCOUNTS()));
    buffer.writeZero(PADDING);
    // Match header
    int matchStartIndex = buffer.writerIndex();
    buffer.writeShort(OXM_MATCH_TYPE_CODE);
    int matchLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    // MplsLabel match
    buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
    buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
    buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    buffer.writeInt(MPLS_LABEL);
    // Match footer
    int matchLength = buffer.writerIndex() - matchStartIndex;
    buffer.setShort(matchLengthIndex, matchLength);
    int paddingRemainder = matchLength % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    // Instructions header
    int instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.APPLY_ACTIONS_TYPE);
    int instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instructions
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    // Deserialize and check everything
    final FlowMessage message = (FlowMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(XID, message.getXid().intValue());
    assertEquals(COMMAND.getIntValue(), message.getCommand().getIntValue());
    assertEquals(MPLS_LABEL, message.getMatch().getProtocolMatchFields().getMplsLabel().intValue());
    assertEquals(1, message.getInstructions().getInstruction().size());
    final Instruction instruction = message.getInstructions().getInstruction().get(0).getInstruction();
    assertEquals(ApplyActionsCase.class, instruction.getImplementedInterface());
    final ApplyActionsCase applyActions = ApplyActionsCase.class.cast(instruction);
    assertEquals(1, applyActions.getApplyActions().getAction().size());
    assertEquals(PopPbbActionCase.class, applyActions.getApplyActions().getAction().get(0).getAction().getImplementedInterface());
}
Also used : FlowMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Example 19 with MplsLabel

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel in project openflowplugin by opendaylight.

the class MatchConvertor method toOfMplsLabel.

private static MatchEntry toOfMplsLabel(final Long mplsLabel) {
    MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
    matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
    matchEntryBuilder.setHasMask(false);
    matchEntryBuilder.setOxmMatchField(MplsLabel.class);
    MplsLabelCaseBuilder mplsLabelCaseBuilder = new MplsLabelCaseBuilder();
    MplsLabelBuilder mplsLabelBuilder = new MplsLabelBuilder();
    mplsLabelBuilder.setMplsLabel(mplsLabel);
    mplsLabelCaseBuilder.setMplsLabel(mplsLabelBuilder.build());
    matchEntryBuilder.setMatchEntryValue(mplsLabelCaseBuilder.build());
    return matchEntryBuilder.build();
}
Also used : MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) MplsLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabelBuilder) MplsLabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsLabelCaseBuilder)

Example 20 with MplsLabel

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel in project openflowplugin by opendaylight.

the class MultipartReplyFlowStatsDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeShort(ITEM_LENGTH);
    buffer.writeByte(TABLE_ID);
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_01);
    buffer.writeInt(SECOND);
    buffer.writeInt(NANOSECOND);
    buffer.writeShort(PRIORITY);
    buffer.writeShort(IDLE_TIMEOUT);
    buffer.writeShort(HARD_TIMEOUT);
    buffer.writeShort(ByteBufUtils.fillBitMask(0, FLAGS.isSENDFLOWREM(), FLAGS.isCHECKOVERLAP(), FLAGS.isRESETCOUNTS(), FLAGS.isNOPKTCOUNTS(), FLAGS.isNOBYTCOUNTS()));
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_02);
    buffer.writeLong(COOKIE);
    buffer.writeLong(PACKET_COUNT);
    buffer.writeLong(BYTE_COUNT);
    // Match header
    int matchStartIndex = buffer.writerIndex();
    buffer.writeShort(OXM_MATCH_TYPE_CODE);
    int matchLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    // MplsLabel match
    buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
    buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
    buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    buffer.writeInt(MPLS_LABEL);
    // Match footer
    int matchLength = buffer.writerIndex() - matchStartIndex;
    buffer.setShort(matchLengthIndex, matchLength);
    int paddingRemainder = matchLength % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    // Instruction POP PBB header
    int instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.APPLY_ACTIONS_TYPE);
    int instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instruction
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    // Instruction POP Vlan header
    instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.WRITE_ACTIONS_TYPE);
    instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP Vlan action
    buffer.writeShort(ActionConstants.POP_VLAN_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instruction
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    final MultipartReplyFlowStats reply = (MultipartReplyFlowStats) deserializeMultipart(buffer);
    final FlowAndStatisticsMapList flowAndStatisticsMapList = reply.getFlowAndStatisticsMapList().get(0);
    assertEquals(TABLE_ID, flowAndStatisticsMapList.getTableId().shortValue());
    assertEquals(SECOND, flowAndStatisticsMapList.getDuration().getSecond().getValue().intValue());
    assertEquals(NANOSECOND, flowAndStatisticsMapList.getDuration().getNanosecond().getValue().intValue());
    assertEquals(PRIORITY, flowAndStatisticsMapList.getPriority().intValue());
    assertEquals(IDLE_TIMEOUT, flowAndStatisticsMapList.getIdleTimeout().intValue());
    assertEquals(HARD_TIMEOUT, flowAndStatisticsMapList.getHardTimeout().intValue());
    assertTrue(flowAndStatisticsMapList.getFlags().equals(FLAGS));
    assertEquals(COOKIE, flowAndStatisticsMapList.getCookie().getValue().longValue());
    assertEquals(BYTE_COUNT, flowAndStatisticsMapList.getByteCount().getValue().longValue());
    assertEquals(PACKET_COUNT, flowAndStatisticsMapList.getPacketCount().getValue().longValue());
    assertEquals(2, flowAndStatisticsMapList.getInstructions().getInstruction().size());
    final Instruction instruction = flowAndStatisticsMapList.getInstructions().getInstruction().get(0).getInstruction();
    assertEquals(ApplyActionsCase.class, instruction.getImplementedInterface());
    final ApplyActionsCase applyActions = ApplyActionsCase.class.cast(instruction);
    assertEquals(1, applyActions.getApplyActions().getAction().size());
    assertEquals(PopPbbActionCase.class, applyActions.getApplyActions().getAction().get(0).getAction().getImplementedInterface());
    final Instruction instruction1 = flowAndStatisticsMapList.getInstructions().getInstruction().get(1).getInstruction();
    assertEquals(WriteActionsCase.class, instruction1.getImplementedInterface());
    final WriteActionsCase writeActions = WriteActionsCase.class.cast(instruction1);
    assertEquals(1, writeActions.getWriteActions().getAction().size());
    assertEquals(PopVlanActionCase.class, writeActions.getWriteActions().getAction().get(0).getAction().getImplementedInterface());
}
Also used : MultipartReplyFlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) Test(org.junit.Test)

Aggregations

MplsLabel (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel)12 Test (org.junit.Test)10 ByteBuf (io.netty.buffer.ByteBuf)9 MplsLabelUtil.byteBufForMplsLabel (org.opendaylight.protocol.util.MplsLabelUtil.byteBufForMplsLabel)5 NlriModelUtil.extractMplsLabel (org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriModelUtil.extractMplsLabel)4 ArrayList (java.util.ArrayList)3 AbstractDeserializerTest (org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)3 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)3 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)3 ProtocolMatchFieldsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder)3 Esi (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.esi.Esi)3 PathBindingTlvParser (org.opendaylight.protocol.pcep.ietf.stateful07.PathBindingTlvParser)2 MplsLabelUtil.mplsLabelForByteBuf (org.opendaylight.protocol.util.MplsLabelUtil.mplsLabelForByteBuf)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)2 MultipartReplyFlowStats (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)2 EthernetTagId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.ethernet.tag.id.EthernetTagId)2 EthernetTagIdBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.ethernet.tag.id.EthernetTagIdBuilder)2 LabelStack (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStack)2