use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createTcpFlagMatch.
/**
* Test match for TCP_Flags.
*
* @return match containing Ethertype (0x0800), IP Protocol (TCP), TCP_Flag (SYN)
*/
// FIXME: move to extensible support
private static MatchBuilder createTcpFlagMatch() {
final MatchBuilder match = new MatchBuilder();
// Ethertype match
final EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x0800L));
ethernetType.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(ethernetType.build());
// TCP Protocol Match
// ipv4 version
final IpMatchBuilder ipMatch = new IpMatchBuilder();
ipMatch.setIpProtocol((short) 6);
match.setIpMatch(ipMatch.build());
// TCP Port Match
final PortNumber dstPort = new PortNumber(80);
final TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
tcpMatch.setTcpDestinationPort(dstPort);
match.setLayer4Match(tcpMatch.build());
/**
* Defined TCP Flag values in OVS v2.1+
* TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
* TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
* TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS 0x100
*/
final TcpFlagsMatchBuilder tcpFlagsMatch = new TcpFlagsMatchBuilder();
tcpFlagsMatch.setTcpFlags(0x002);
match.setTcpFlagsMatch(tcpFlagsMatch.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createL4UDPMatch.
private static MatchBuilder createL4UDPMatch() {
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder eth = new EthernetMatchBuilder();
final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x0800L));
eth.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(eth.build());
// ipv4 version
final IpMatchBuilder ipmatch = new IpMatchBuilder();
ipmatch.setIpProtocol((short) 17);
match.setIpMatch(ipmatch.build());
final PortNumber srcport = new PortNumber(1325);
final PortNumber dstport = new PortNumber(42);
// udp match
final UdpMatchBuilder udpmatch = new UdpMatchBuilder();
udpmatch.setUdpDestinationPort(dstport);
udpmatch.setUdpSourcePort(srcport);
match.setLayer4Match(udpmatch.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createICMPv6Match1.
private static MatchBuilder createICMPv6Match1() {
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder eth = new EthernetMatchBuilder();
final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x86ddL));
eth.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(eth.build());
// ipv4 version
final IpMatchBuilder ipmatch = new IpMatchBuilder();
ipmatch.setIpProtocol((short) 256);
match.setIpMatch(ipmatch.build());
// icmpv6
final Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder();
// match
icmpv6match.setIcmpv6Type((short) 135);
icmpv6match.setIcmpv6Code((short) 1);
match.setIcmpv6Match(icmpv6match.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createICMPv4Match.
private static MatchBuilder createICMPv4Match() {
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder eth = new EthernetMatchBuilder();
final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x0800L));
eth.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(eth.build());
// ipv4 version
final IpMatchBuilder ipmatch = new IpMatchBuilder();
ipmatch.setIpProtocol((short) 1);
match.setIpMatch(ipmatch.build());
// icmpv4
final Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
// match
icmpv4match.setIcmpv4Type((short) 8);
icmpv4match.setIcmpv4Code((short) 0);
match.setIcmpv4Match(icmpv4match.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder in project openflowplugin by opendaylight.
the class MatchV10ResponseConvertor method convert.
@Override
public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
BigInteger datapathid = datapathIdConvertorData.getDatapathId();
if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, (long) source.getInPort(), ofVersion));
}
if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(source.getDlSrc());
ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(source.getDlDst());
ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long) source.getDlType()));
ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
int vlanId = source.getDlVlan() == 0xffff ? 0 : source.getDlVlan();
vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
vlanIdBuilder.setVlanIdPresent(vlanId != 0);
vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(source.getDlVlanPcp()));
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
final Ipv4Prefix prefix;
if (source.getNwSrcMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Source(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
final Ipv4Prefix prefix;
if (source.getNwDstMask() != null) {
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
} else {
// Openflow Spec : 1.3.2
// An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
// So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
// statistics response.
prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
}
if (!NO_IP.equals(prefix.getValue())) {
ipv4MatchBuilder.setIpv4Destination(prefix);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
Short nwProto = source.getNwProto();
ipMatchBuilder.setIpProtocol(nwProto);
matchBuilder.setIpMatch(ipMatchBuilder.build());
int proto = nwProto.intValue();
if (proto == PROTO_TCP) {
TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
boolean hasTcp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasTcp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasTcp = true;
}
if (hasTcp) {
matchBuilder.setLayer4Match(tcpMatchBuilder.build());
}
} else if (proto == PROTO_UDP) {
UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
boolean hasUdp = false;
if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
hasUdp = true;
}
if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
hasUdp = true;
}
if (hasUdp) {
matchBuilder.setLayer4Match(udpMatchBuilder.build());
}
} else if (proto == PROTO_ICMPV4) {
Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
boolean hasIcmpv4 = false;
if (!source.getWildcards().isTPSRC()) {
Integer type = source.getTpSrc();
if (type != null) {
icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
hasIcmpv4 = true;
}
}
if (!source.getWildcards().isTPDST()) {
Integer code = source.getTpDst();
if (code != null) {
icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
hasIcmpv4 = true;
}
}
if (hasIcmpv4) {
matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
}
}
}
if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
Short dscp = ActionUtil.tosToDscp(source.getNwTos());
ipMatchBuilder.setIpDscp(new Dscp(dscp));
matchBuilder.setIpMatch(ipMatchBuilder.build());
}
return matchBuilder;
}
Aggregations