Search in sources :

Example 11 with EthernetMatch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch 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 12 with EthernetMatch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch 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 13 with EthernetMatch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.

the class FlowUtils method createDirectMacToMacFlow.

/**
 * Returns a {@link FlowBuilder} forwarding all packets to controller port.
 */
public static FlowBuilder createDirectMacToMacFlow(final Short tableId, final int priority, final MacAddress srcMac, final MacAddress dstMac, final NodeConnectorRef dstPort) {
    FlowBuilder macToMacFlow = new FlowBuilder().setTableId(tableId).setFlowName("mac2mac");
    macToMacFlow.setId(new FlowId(Long.toString(macToMacFlow.hashCode())));
    EthernetMatch ethernetMatch = new EthernetMatchBuilder().setEthernetSource(new EthernetSourceBuilder().setAddress(srcMac).build()).setEthernetDestination(new EthernetDestinationBuilder().setAddress(dstMac).build()).build();
    MatchBuilder match = new MatchBuilder();
    match.setEthernetMatch(ethernetMatch);
    Uri outputPort = dstPort.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();
    Action outputToControllerAction = new ActionBuilder().setOrder(0).setAction(new OutputActionCaseBuilder().setOutputAction(new OutputActionBuilder().setMaxLength(Integer.valueOf(0xffff)).setOutputNodeConnector(outputPort).build()).build()).build();
    // Create an Apply Action
    ApplyActions applyActions = new ApplyActionsBuilder().setAction(ImmutableList.of(outputToControllerAction)).build();
    // Wrap our Apply Action in an Instruction
    Instruction applyActionsInstruction = new InstructionBuilder().setOrder(0).setInstruction(new ApplyActionsCaseBuilder().setApplyActions(applyActions).build()).build();
    // Put our Instruction in a list of Instructions
    macToMacFlow.setMatch(new MatchBuilder().setEthernetMatch(ethernetMatch).build()).setInstructions(new InstructionsBuilder().setInstruction(ImmutableList.of(applyActionsInstruction)).build()).setPriority(priority).setBufferId(OFConstants.OFP_NO_BUFFER).setHardTimeout(0).setIdleTimeout(0).setFlags(new FlowModFlags(false, false, false, false, false));
    return macToMacFlow;
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) 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) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) EthernetDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) EthernetSourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) ApplyActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions)

Example 14 with EthernetMatch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.

the class MatchConvertor method convert.

@Override
public List<MatchEntry> convert(final Match source, final VersionConvertorData data) {
    List<MatchEntry> result = new ArrayList<>();
    if (source == null) {
        return result;
    }
    final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
    inPortMatch(result, source.getInPort());
    inPhyPortMatch(result, source.getInPhyPort());
    metadataMatch(result, source.getMetadata());
    ethernetMatch(result, source.getEthernetMatch());
    vlanMatch(result, source.getVlanMatch());
    ipMatch(result, source.getIpMatch());
    layer4Match(result, source.getLayer4Match(), getConvertorExecutor(), extensionConvertorProvider);
    icmpv4Match(result, source.getIcmpv4Match());
    icmpv6Match(result, source.getIcmpv6Match());
    layer3Match(result, source.getLayer3Match(), getConvertorExecutor(), extensionConvertorProvider);
    protocolMatchFields(result, source.getProtocolMatchFields());
    tunnelMatch(result, source.getTunnel());
    tcpFlagsMatch(result, source.getTcpFlagsMatch());
    /*
         * TODO: EXTENSION PROPOSAL (source, MD-SAL to OFJava)
         * - we might need version for conversion and for key
         */
    Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(source);
    if (extensionListOpt.isPresent()) {
        List<ExtensionList> extensionListList = extensionListOpt.get().getExtensionList();
        for (ExtensionList extensionItem : extensionListList) {
            // TODO: get real version
            ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
            ConvertorToOFJava<MatchEntry> convertor = extensionConvertorProvider.getConverter(key);
            if (convertor == null) {
                throw new IllegalStateException("No converter found for key: " + key.toString());
            }
            MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
            result.add(ofMatch);
        }
    }
    return result;
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) ExtensionConverterProvider(org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider) ExtensionList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList) ArrayList(java.util.ArrayList) GeneralExtensionListGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping) ConverterExtensionKey(org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey)

Example 15 with EthernetMatch

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.

the class MatchResponseConvertorTest method checkDefault.

private static void checkDefault(final MatchBuilder builder) {
    EthernetMatch ethMatch = builder.getEthernetMatch();
    assertEquals(MAC_SRC, ethMatch.getEthernetSource().getAddress());
    assertEquals(null, ethMatch.getEthernetSource().getMask());
    assertEquals(MAC_DST, ethMatch.getEthernetDestination().getAddress());
    assertEquals(null, ethMatch.getEthernetDestination().getMask());
    assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().getValue().intValue());
    NodeConnectorId inPort = builder.getInPort();
    assertEquals(URI_IN_PORT, inPort.getValue());
}
Also used : EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)

Aggregations

EthernetMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch)15 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)12 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)11 Test (org.junit.Test)9 EthernetSourceBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder)8 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 IpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch)7 MatchesBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder)6 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)6 AceIpBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder)5 TcpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch)5 UdpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch)5 AceIpv4Builder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder)4 EtherType (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType)4 EthernetDestinationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder)4 EthernetTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder)4 Icmpv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match)4 FlowWildcardsV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10)4 MatchV10Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder)4 BigInteger (java.math.BigInteger)3