Search in sources :

Example 16 with VersionDatapathIdConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData in project openflowplugin by opendaylight.

the class FlowConvertorTest method testInstructionsTranslation.

/**
 * Tests {@link FlowConvertor#convert(Flow, VersionDatapathIdConvertorData)} }.
 */
@Test
public void testInstructionsTranslation() {
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    GoToTableCaseBuilder goToCaseBuilder = new GoToTableCaseBuilder();
    GoToTableBuilder goToBuilder = new GoToTableBuilder();
    goToBuilder.setTableId((short) 1);
    goToCaseBuilder.setGoToTable(goToBuilder.build());
    instructionBuilder.setInstruction(goToCaseBuilder.build());
    instructionBuilder.setOrder(0);
    List<Instruction> instructions = new ArrayList<>();
    instructions.add(instructionBuilder.build());
    instructionBuilder = new InstructionBuilder();
    WriteMetadataCaseBuilder metaCaseBuilder = new WriteMetadataCaseBuilder();
    WriteMetadataBuilder metaBuilder = new WriteMetadataBuilder();
    metaBuilder.setMetadata(new BigInteger("2"));
    metaBuilder.setMetadataMask(new BigInteger("3"));
    metaCaseBuilder.setWriteMetadata(metaBuilder.build());
    instructionBuilder.setInstruction(metaCaseBuilder.build());
    instructionBuilder.setOrder(1);
    instructions.add(instructionBuilder.build());
    instructionBuilder = new InstructionBuilder();
    WriteActionsCaseBuilder writeCaseBuilder = new WriteActionsCaseBuilder();
    WriteActionsBuilder writeBuilder = new WriteActionsBuilder();
    List<Action> actions = new ArrayList<>();
    writeBuilder.setAction(actions);
    writeCaseBuilder.setWriteActions(writeBuilder.build());
    instructionBuilder.setInstruction(writeCaseBuilder.build());
    instructionBuilder.setOrder(2);
    instructions.add(instructionBuilder.build());
    instructionBuilder = new InstructionBuilder();
    ApplyActionsCaseBuilder applyCaseBuilder = new ApplyActionsCaseBuilder();
    ApplyActionsBuilder applyBuilder = new ApplyActionsBuilder();
    actions = new ArrayList<>();
    applyBuilder.setAction(actions);
    applyCaseBuilder.setApplyActions(applyBuilder.build());
    instructionBuilder.setInstruction(applyCaseBuilder.build());
    instructionBuilder.setOrder(3);
    instructions.add(instructionBuilder.build());
    instructionBuilder = new InstructionBuilder();
    ClearActionsCaseBuilder clearCaseBuilder = new ClearActionsCaseBuilder();
    ClearActionsBuilder clearBuilder = new ClearActionsBuilder();
    actions = new ArrayList<>();
    clearBuilder.setAction(actions);
    clearCaseBuilder.setClearActions(clearBuilder.build());
    instructionBuilder.setInstruction(clearCaseBuilder.build());
    instructionBuilder.setOrder(4);
    instructions.add(instructionBuilder.build());
    instructionBuilder = new InstructionBuilder();
    MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
    MeterBuilder meterBuilder = new MeterBuilder();
    meterBuilder.setMeterId(new MeterId(5L));
    meterCaseBuilder.setMeter(meterBuilder.build());
    instructionBuilder.setInstruction(meterCaseBuilder.build());
    instructionBuilder.setOrder(5);
    instructions.add(instructionBuilder.build());
    InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
    instructionsBuilder.setInstruction(instructions);
    AddFlowInputBuilder flowBuilder = new AddFlowInputBuilder();
    flowBuilder.setInstructions(instructionsBuilder.build());
    AddFlowInput flow = flowBuilder.build();
    VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
    data.setDatapathId(new BigInteger("42"));
    List<FlowModInputBuilder> flowMod = convert(flow, data);
    Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());
    Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());
    Assert.assertEquals("Wrong instructions size", 6, flowMod.get(0).getInstruction().size());
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction instruction = flowMod.get(0).getInstruction().get(0);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    GotoTableCase gotoTableCase = (GotoTableCase) instruction.getInstructionChoice();
    Assert.assertEquals("Wrong table id", 1, gotoTableCase.getGotoTable().getTableId().intValue());
    instruction = flowMod.get(0).getInstruction().get(1);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    WriteMetadataCase writeMetadataCase = (WriteMetadataCase) instruction.getInstructionChoice();
    Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, writeMetadataCase.getWriteMetadata().getMetadata());
    Assert.assertArrayEquals("Wrong metadata mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, writeMetadataCase.getWriteMetadata().getMetadataMask());
    instruction = flowMod.get(0).getInstruction().get(2);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstructionChoice();
    Assert.assertEquals("Wrong actions size", 0, writeActionsCase.getWriteActions().getAction().size());
    instruction = flowMod.get(0).getInstruction().get(3);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstructionChoice();
    Assert.assertEquals("Wrong actions size", 0, applyActionsCase.getApplyActions().getAction().size());
    instruction = flowMod.get(0).getInstruction().get(4);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    instruction = flowMod.get(0).getInstruction().get(5);
    Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.MeterCase", instruction.getInstructionChoice().getImplementedInterface().getName());
    MeterCase meterCase = (MeterCase) instruction.getInstructionChoice();
    Assert.assertEquals("Wrong meter id", 5, meterCase.getMeter().getMeterId().intValue());
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder) InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) WriteMetadataCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase) MeterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase) ArrayList(java.util.ArrayList) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) WriteMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) ClearActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder) GoToTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder) MeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder) GotoTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder) ClearActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.clear.actions._case.ClearActionsBuilder) GoToTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder) FlowModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder) BigInteger(java.math.BigInteger) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase) Test(org.junit.Test)

Example 17 with VersionDatapathIdConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData in project openflowplugin by opendaylight.

the class MatchV10ResponseConvertorTest method testUdpMatch.

/**
 * UDP match test for {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)}.
 */
@Test
public void testUdpMatch() {
    // TP_SRC, TP_DST are wildcarded.
    // NW_PROTO is not wildcarded but null.
    Long dlType = 0x800L;
    FlowWildcardsV10 wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, true);
    MatchV10Builder builder = new MatchV10Builder().setWildcards(wc).setDlType(dlType.intValue());
    MatchV10 match = builder.build();
    BigInteger dpid = BigInteger.valueOf(12345L);
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
    datapathIdConvertorData.setDatapathId(dpid);
    Match salMatch = convert(match, datapathIdConvertorData).build();
    EthernetMatch etherMatch = salMatch.getEthernetMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify UDP protocol.
    Short ipProto = 17;
    match = builder.setNwProto(ipProto).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    IpMatch ipMatch = salMatch.getIpMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // TP_SRC is not wildcarded but null.
    wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, false);
    match = builder.setWildcards(wc).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify UDP source port.
    Integer srcPort = 60000;
    match = builder.setTpSrc(srcPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    UdpMatch udpMatch = (UdpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong UDP src", srcPort, udpMatch.getUdpSourcePort().getValue());
    Assert.assertEquals("Wrong UDP dst", null, udpMatch.getUdpDestinationPort());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // TP_DST is not wildcarded but null.
    wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, false, false);
    match = builder.setWildcards(wc).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    udpMatch = (UdpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong UDP src", srcPort, udpMatch.getUdpSourcePort().getValue());
    Assert.assertEquals("Wrong UDP dst", null, udpMatch.getUdpDestinationPort());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify UDP destination port only.
    Integer dstPort = 6653;
    match = builder.setTpSrc(null).setTpDst(dstPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    udpMatch = (UdpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong UDP src", null, udpMatch.getUdpSourcePort());
    Assert.assertEquals("Wrong UDP dst", dstPort, udpMatch.getUdpDestinationPort().getValue());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify both source and destination port.
    srcPort = 32767;
    dstPort = 9999;
    match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    udpMatch = (UdpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong UDP src", srcPort, udpMatch.getUdpSourcePort().getValue());
    Assert.assertEquals("Wrong UDP dst", dstPort, udpMatch.getUdpDestinationPort().getValue());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
}
Also used : BigInteger(java.math.BigInteger) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) FlowWildcardsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) MatchV10Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) BigInteger(java.math.BigInteger) MatchV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) Icmpv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) Test(org.junit.Test)

Example 18 with VersionDatapathIdConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData in project openflowplugin by opendaylight.

the class MatchV10ResponseConvertorTest method testTcpMatch.

/**
 * TCP match test for {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)}.
 */
@Test
public void testTcpMatch() {
    // TP_SRC, TP_DST are wildcarded.
    // NW_PROTO is not wildcarded but null.
    Long dlType = 0x800L;
    FlowWildcardsV10 wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, true);
    MatchV10Builder builder = new MatchV10Builder().setWildcards(wc).setDlType(dlType.intValue());
    MatchV10 match = builder.build();
    BigInteger dpid = BigInteger.valueOf(12345L);
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
    datapathIdConvertorData.setDatapathId(dpid);
    Match salMatch = convert(match, datapathIdConvertorData).build();
    EthernetMatch etherMatch = salMatch.getEthernetMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong IP match", null, salMatch.getIpMatch());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify TCP protocol.
    Short ipProto = 6;
    match = builder.setNwProto(ipProto).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    IpMatch ipMatch = salMatch.getIpMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // TP_SRC is not wildcarded but null.
    wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, true, false);
    match = builder.setWildcards(wc).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong L4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify TCP source port.
    Integer srcPort = 60000;
    match = builder.setTpSrc(srcPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    TcpMatch tcpMatch = (TcpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong TCP src", srcPort, tcpMatch.getTcpSourcePort().getValue());
    Assert.assertEquals("Wrong TCP dst", null, tcpMatch.getTcpDestinationPort());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // TP_DST is not wildcarded but null.
    wc = new FlowWildcardsV10(true, true, false, true, true, true, false, true, false, false);
    match = builder.setWildcards(wc).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    tcpMatch = (TcpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong TCP src", srcPort, tcpMatch.getTcpSourcePort().getValue());
    Assert.assertEquals("Wrong TCP dst", null, tcpMatch.getTcpDestinationPort());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify TCP destination port only.
    Integer dstPort = 6653;
    match = builder.setTpSrc(null).setTpDst(dstPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    tcpMatch = (TcpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong TCP src", null, tcpMatch.getTcpSourcePort());
    Assert.assertEquals("Wrong TCP dst", dstPort, tcpMatch.getTcpDestinationPort().getValue());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
    // Specify both source and destination port.
    srcPort = 32767;
    dstPort = 9999;
    match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();
    salMatch = convert(match, datapathIdConvertorData).build();
    etherMatch = salMatch.getEthernetMatch();
    ipMatch = salMatch.getIpMatch();
    tcpMatch = (TcpMatch) salMatch.getLayer4Match();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl src", null, etherMatch.getEthernetSource());
    Assert.assertEquals("Wrong dl dst", null, etherMatch.getEthernetDestination());
    Assert.assertEquals("Wrong dl type", dlType, etherMatch.getEthernetType().getType().getValue());
    Assert.assertEquals("Wrong VLAN match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong ip protocol", ipProto, ipMatch.getIpProtocol());
    Assert.assertEquals("Wrong ip proto", null, ipMatch.getIpProto());
    Assert.assertEquals("Wrong ip ecn", null, ipMatch.getIpEcn());
    Assert.assertEquals("Wrong ip dscp", null, ipMatch.getIpDscp());
    Assert.assertEquals("Wrong L3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong TCP src", srcPort, tcpMatch.getTcpSourcePort().getValue());
    Assert.assertEquals("Wrong TCP dst", dstPort, tcpMatch.getTcpDestinationPort().getValue());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
}
Also used : BigInteger(java.math.BigInteger) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) FlowWildcardsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) MatchV10Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder) BigInteger(java.math.BigInteger) MatchV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) Icmpv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) Test(org.junit.Test)

Example 19 with VersionDatapathIdConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData in project openflowplugin by opendaylight.

the class MatchV10ResponseConvertorTest method testWildcardedMatch.

/**
 * Test {@link MatchV10ResponseConvertor#convert(MatchV10, VersionDatapathIdConvertorData)}.
 */
@Test
public void testWildcardedMatch() {
    MatchV10Builder builder = new MatchV10Builder();
    builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
    builder.setNwSrcMask((short) 24);
    builder.setNwDstMask((short) 16);
    builder.setInPort(6653);
    builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));
    builder.setDlDst(new MacAddress("02:02:02:02:02:02"));
    builder.setDlVlan(128);
    builder.setDlVlanPcp((short) 2);
    builder.setDlType(15);
    builder.setNwTos((short) 14);
    builder.setNwProto((short) 6);
    builder.setNwSrc(new Ipv4Address("1.1.1.2"));
    builder.setNwDst(new Ipv4Address("32.16.8.1"));
    builder.setTpSrc(2048);
    builder.setTpDst(4096);
    MatchV10 match = builder.build();
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
    datapathIdConvertorData.setDatapathId(new BigInteger("42"));
    final Match salMatch = convert(match, datapathIdConvertorData).build();
    Assert.assertEquals("Wrong in port", null, salMatch.getInPort());
    Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());
    Assert.assertEquals("Wrong dl vlan match", null, salMatch.getVlanMatch());
    Assert.assertEquals("Wrong layer 3 match", null, salMatch.getLayer3Match());
    Assert.assertEquals("Wrong layer 4 match", null, salMatch.getLayer4Match());
    Assert.assertEquals("Wrong ip match", null, salMatch.getIpMatch());
    Assert.assertEquals("Wrong ICMPv4 match", null, salMatch.getIcmpv4Match());
}
Also used : FlowWildcardsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10) VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) MatchV10Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder) BigInteger(java.math.BigInteger) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) Icmpv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) IpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch) Test(org.junit.Test)

Example 20 with VersionDatapathIdConvertorData

use of org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData in project openflowplugin by opendaylight.

the class FlowRemovedV10Translator method translateMatch.

@Override
protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceInfo deviceInfo) {
    final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(deviceInfo.getVersion());
    datapathIdConvertorData.setDatapathId(deviceInfo.getDatapathId());
    final Optional<MatchBuilder> matchBuilderOptional = getConvertorExecutor().convert(flowRemoved.getMatchV10(), datapathIdConvertorData);
    return matchBuilderOptional.orElse(new MatchBuilder());
}
Also used : VersionDatapathIdConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Aggregations

VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)45 Test (org.junit.Test)39 BigInteger (java.math.BigInteger)32 ArrayList (java.util.ArrayList)25 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)22 UdpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch)22 TcpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch)21 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)20 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)20 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)18 ArpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch)15 Ipv6Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match)15 SctpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch)14 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)13 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)11 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)9 EthernetMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch)9 IpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch)9 MatchV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10)9 MatchV10Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder)9