2 * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.utils.mdsal.openflow;
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfEthDst;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtZoneKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg1Key;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg3Key;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg4Key;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg5Key;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg7Key;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpDstKey;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfTcpSrcKey;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpDstKey;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmOfUdpSrcKey;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNspKey;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNsiKey;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsi.grouping.NxmNxNsiBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.dst.grouping.NxmOfEthDstBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.src.grouping.NxmOfTcpSrcBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.tcp.dst.grouping.NxmOfTcpDstBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.dst.grouping.NxmOfUdpDstBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.udp.src.grouping.NxmOfUdpSrcBuilder;
88 import org.slf4j.Logger;
89 import org.slf4j.LoggerFactory;
91 import com.google.common.collect.ImmutableList;
92 import com.google.common.collect.Lists;
94 public class MatchUtils {
95 private static final Logger LOG = LoggerFactory.getLogger(MatchUtils.class);
96 public static final short ICMP_SHORT = 1;
97 public static final short TCP_SHORT = 6;
98 public static final short UDP_SHORT = 17;
99 public static final String TCP = "tcp";
100 public static final String UDP = "udp";
101 private static final int TCP_SYN = 0x0002;
102 public static final String ICMP = "icmp";
103 public static final String ICMPV6 = "icmpv6";
104 public static final short ALL_ICMP = -1;
107 * Create Ingress Port Match dpidLong, inPort
109 * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
110 * @param dpidLong Long the datapath ID of a switch/node
111 * @param inPort Long ingress port on a switch
112 * @return matchBuilder Map MatchBuilder Object with a match
114 public static MatchBuilder createInPortMatch(MatchBuilder matchBuilder, Long dpidLong, Long inPort) {
116 NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + inPort);
117 LOG.debug("createInPortMatch() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, inPort);
118 matchBuilder.setInPort(NodeConnectorId.getDefaultInstance(ncid.getValue()));
119 matchBuilder.setInPort(ncid);
124 public static MatchBuilder createInPortReservedMatch(MatchBuilder matchBuilder, Long dpidLong, String inPort) {
126 NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + inPort);
127 LOG.debug("createInPortResrevedMatch() Node Connector ID is - Type=openflow: DPID={} inPort={} ",
129 matchBuilder.setInPort(NodeConnectorId.getDefaultInstance(ncid.getValue()));
130 matchBuilder.setInPort(ncid);
136 * Create EtherType Match
138 * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
139 * @param etherType Long EtherType
140 * @return matchBuilder Map MatchBuilder Object with a match
142 public static MatchBuilder createEtherTypeMatch(MatchBuilder matchBuilder, EtherType etherType) {
144 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
145 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
146 ethTypeBuilder.setType(new EtherType(etherType));
147 ethernetMatch.setEthernetType(ethTypeBuilder.build());
148 matchBuilder.setEthernetMatch(ethernetMatch.build());
154 * Create Ethernet Source Match
156 * @param matchBuilder MatchBuilder Object without a match yet
157 * @param sMacAddr String representing a source MAC
158 * @return matchBuilder Map MatchBuilder Object with a match
160 public static MatchBuilder createEthSrcMatch(MatchBuilder matchBuilder, MacAddress sMacAddr) {
162 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
163 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
164 ethSourceBuilder.setAddress(new MacAddress(sMacAddr));
165 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
166 matchBuilder.setEthernetMatch(ethernetMatch.build());
172 * Create Ethernet Destination Match
174 * @param matchBuilder MatchBuilder Object without a match yet
175 * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
176 * @return matchBuilder Map MatchBuilder Object with a match
178 public static MatchBuilder createVlanIdMatch(MatchBuilder matchBuilder, VlanId vlanId, boolean present) {
179 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
180 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
181 vlanIdBuilder.setVlanId(new VlanId(vlanId));
182 vlanIdBuilder.setVlanIdPresent(present);
183 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
184 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
190 * Create Ethernet Destination Match
192 * @param matchBuilder MatchBuilder Object without a match yet
193 * @param dMacAddr String representing a destination MAC
194 * @return matchBuilder Map MatchBuilder Object with a match
196 public static MatchBuilder createDestEthMatch(MatchBuilder matchBuilder, MacAddress dMacAddr, MacAddress mask) {
198 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
199 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
200 ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
202 ethDestinationBuilder.setMask(mask);
204 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
205 matchBuilder.setEthernetMatch(ethernetMatch.build());
211 * Tunnel ID Match Builder
213 * @param matchBuilder MatchBuilder Object without a match yet
214 * @param tunnelId BigInteger representing a tunnel ID
215 * @return matchBuilder Map MatchBuilder Object with a match
217 public static MatchBuilder createTunnelIDMatch(MatchBuilder matchBuilder, BigInteger tunnelId) {
219 TunnelBuilder tunnelBuilder = new TunnelBuilder();
220 tunnelBuilder.setTunnelId(tunnelId);
221 matchBuilder.setTunnel(tunnelBuilder.build());
227 * Match ICMP code and type
229 * @param matchBuilder MatchBuilder Object
230 * @param type short representing an ICMP type
231 * @param code short representing an ICMP code
232 * @return matchBuilder Map MatchBuilder Object with a match
234 public static MatchBuilder createICMPv4Match(MatchBuilder matchBuilder, short type, short code) {
236 // Build the IPv4 Match requied per OVS Syntax
237 IpMatchBuilder ipmatch = new IpMatchBuilder();
238 ipmatch.setIpProtocol((short) 1);
239 matchBuilder.setIpMatch(ipmatch.build());
241 // Build the ICMPv4 Match
242 Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
243 if (type != ALL_ICMP) {
244 icmpv4match.setIcmpv4Type(type);
246 if (code != ALL_ICMP) {
247 icmpv4match.setIcmpv4Code(code);
249 matchBuilder.setIcmpv4Match(icmpv4match.build());
255 * Match ICMPv6 code and type
257 * @param matchBuilder MatchBuilder Object
258 * @param type short representing an ICMP type
259 * @param code short representing an ICMP code
260 * @return matchBuilder Map MatchBuilder Object with a match
262 public static MatchBuilder createICMPv6Match(MatchBuilder matchBuilder, short type, short code) {
264 // Build the IPv6 Match required per OVS Syntax
265 IpMatchBuilder ipmatch = new IpMatchBuilder();
266 ipmatch.setIpProtocol((short) 58);
267 matchBuilder.setIpMatch(ipmatch.build());
269 // Build the ICMPv6 Match
270 Icmpv6MatchBuilder icmpv6match = new Icmpv6MatchBuilder();
271 if (type != ALL_ICMP || code != ALL_ICMP) {
272 icmpv6match.setIcmpv6Type(type);
273 icmpv6match.setIcmpv6Code(code);
275 matchBuilder.setIcmpv6Match(icmpv6match.build());
281 * @param matchBuilder MatchBuilder Object without a match yet
282 * @param dstip String containing an IPv4 prefix
283 * @return matchBuilder Map Object with a match
285 public static MatchBuilder createDstL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
287 EthernetMatchBuilder eth = new EthernetMatchBuilder();
288 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
289 ethTypeBuilder.setType(new EtherType(0x0800L));
290 eth.setEthernetType(ethTypeBuilder.build());
291 matchBuilder.setEthernetMatch(eth.build());
293 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
294 ipv4match.setIpv4Destination(dstip);
296 matchBuilder.setLayer3Match(ipv4match.build());
303 * @param matchBuilder MatchBuilder Object without a match yet
304 * @param dstip String containing an IPv4 prefix
305 * @return matchBuilder Map Object with a match
307 public static MatchBuilder createArpDstIpv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
308 ArpMatchBuilder arpDstMatch = new ArpMatchBuilder();
309 arpDstMatch.setArpTargetTransportAddress(dstip)
310 .setArpOp(FlowUtils.ARP_OP_REQUEST);
311 matchBuilder.setLayer3Match(arpDstMatch.build());
317 * @param matchBuilder MatchBuilder Object without a match yet
318 * @param srcip String containing an IPv4 prefix
319 * @return matchBuilder Map Object with a match
321 public static MatchBuilder createSrcL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix srcip) {
323 EthernetMatchBuilder eth = new EthernetMatchBuilder();
324 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
325 ethTypeBuilder.setType(new EtherType(0x0800L));
326 eth.setEthernetType(ethTypeBuilder.build());
327 matchBuilder.setEthernetMatch(eth.build());
329 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
330 ipv4match.setIpv4Source(srcip);
331 matchBuilder.setLayer3Match(ipv4match.build());
338 * Create Source TCP Port Match
340 * @param matchBuilder MatchBuilder Object without a match yet
341 * @param tcpport Integer representing a source TCP port
342 * @return matchBuilder Map MatchBuilder Object with a match
344 public static MatchBuilder createSetSrcTcpMatch(MatchBuilder matchBuilder, PortNumber tcpport) {
346 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
347 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
348 ethTypeBuilder.setType(new EtherType(0x0800L));
349 ethType.setEthernetType(ethTypeBuilder.build());
350 matchBuilder.setEthernetMatch(ethType.build());
352 IpMatchBuilder ipmatch = new IpMatchBuilder();
353 ipmatch.setIpProtocol((short) 6);
354 matchBuilder.setIpMatch(ipmatch.build());
356 TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
357 tcpmatch.setTcpSourcePort(tcpport);
358 matchBuilder.setLayer4Match(tcpmatch.build());
365 * Create Destination TCP Port Match
367 * @param matchBuilder MatchBuilder Object without a match yet
368 * @param tcpDstPort Integer representing a destination TCP port
369 * @return matchBuilder Map MatchBuilder Object with a match
371 public static MatchBuilder createSetDstTcpMatch(MatchBuilder matchBuilder, PortNumber tcpDstPort) {
373 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
374 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
375 ethTypeBuilder.setType(new EtherType(0x0800L));
376 ethType.setEthernetType(ethTypeBuilder.build());
377 matchBuilder.setEthernetMatch(ethType.build());
379 IpMatchBuilder ipmatch = new IpMatchBuilder();
380 ipmatch.setIpProtocol((short) 6);
381 matchBuilder.setIpMatch(ipmatch.build());
383 TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
384 tcpmatch.setTcpDestinationPort(tcpDstPort);
385 matchBuilder.setLayer4Match(tcpmatch.build());
391 * Test match for TCP_Flags
393 * @param matchBuilder MatchBuilder Object without a match yet
394 * @param tcpPort PortNumber representing a destination TCP port
395 * @param tcpFlag int representing a tcp_flag
396 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN)
398 * Defined TCP Flag values in OVS v2.1+
399 * TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
400 * TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
401 * TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS 0x100
403 public static MatchBuilder createTcpFlagMatch(MatchBuilder matchBuilder, PortNumber tcpPort, int tcpFlag) {
406 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
407 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
408 ethTypeBuilder.setType(new EtherType(0x0800L));
409 ethernetType.setEthernetType(ethTypeBuilder.build());
410 matchBuilder.setEthernetMatch(ethernetType.build());
412 // TCP Protocol Match
413 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
414 ipMatch.setIpProtocol((short) 6);
415 matchBuilder.setIpMatch(ipMatch.build());
418 PortNumber dstPort = new PortNumber(tcpPort);
419 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
420 tcpMatch.setTcpDestinationPort(dstPort);
421 matchBuilder.setLayer4Match(tcpMatch.build());
423 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
424 tcpFlagMatch.setTcpFlag(tcpFlag);
425 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
430 * @return MatchBuilder containing the metadata match values
432 public static MatchBuilder createMetadataMatch(MatchBuilder matchBuilder, BigInteger metaData, BigInteger metaDataMask) {
434 // metadata matchbuilder
435 MetadataBuilder metadata = new MetadataBuilder();
436 metadata.setMetadata(metaData);
437 // Optional metadata mask
438 if (metaDataMask != null) {
439 metadata.setMetadataMask(metaDataMask);
441 matchBuilder.setMetadata(metadata.build());
447 * Create TCP Port Match
449 * @param matchBuilder MatchBuilder Object without a match yet
450 * @param ipProtocol Integer representing the IP protocol
451 * @return matchBuilder Map MatchBuilder Object with a match
453 public static MatchBuilder createIpProtocolMatch(MatchBuilder matchBuilder, short ipProtocol) {
455 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
456 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
457 ethTypeBuilder.setType(new EtherType(0x0800L));
458 ethType.setEthernetType(ethTypeBuilder.build());
459 matchBuilder.setEthernetMatch(ethType.build());
461 IpMatchBuilder ipMmatch = new IpMatchBuilder();
462 if (ipProtocol == TCP_SHORT) {
463 ipMmatch.setIpProtocol(TCP_SHORT);
465 else if (ipProtocol == UDP_SHORT) {
466 ipMmatch.setIpProtocol(UDP_SHORT);
468 else if (ipProtocol == ICMP_SHORT) {
469 ipMmatch.setIpProtocol(ICMP_SHORT);
471 matchBuilder.setIpMatch(ipMmatch.build());
476 * Create TCP Port Match
478 * @param matchBuilder MatchBuilder Object without a match yet
479 * @param ipProtocol Integer representing the IP protocol
480 * @return matchBuilder Map MatchBuilder Object with a match
482 public static MatchBuilder createIpv6ProtocolMatch(MatchBuilder matchBuilder, short ipProtocol) {
484 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
485 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
486 ethTypeBuilder.setType(new EtherType(0x86DDL));
487 ethType.setEthernetType(ethTypeBuilder.build());
488 matchBuilder.setEthernetMatch(ethType.build());
490 IpMatchBuilder ipMmatch = new IpMatchBuilder();
491 if (ipProtocol == TCP_SHORT) {
492 ipMmatch.setIpProtocol(TCP_SHORT);
494 else if (ipProtocol == UDP_SHORT) {
495 ipMmatch.setIpProtocol(UDP_SHORT);
497 else if (ipProtocol == ICMP_SHORT) {
498 ipMmatch.setIpProtocol(ICMP_SHORT);
500 matchBuilder.setIpMatch(ipMmatch.build());
505 * Create tcp syn with proto match.
507 * @param matchBuilder the match builder
508 * @return matchBuilder match builder
510 public static MatchBuilder createTcpSynWithProtoMatch(MatchBuilder matchBuilder) {
513 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
514 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
515 ethTypeBuilder.setType(new EtherType(0x0800L));
516 ethernetType.setEthernetType(ethTypeBuilder.build());
517 matchBuilder.setEthernetMatch(ethernetType.build());
519 // TCP Protocol Match
520 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
521 ipMatch.setIpProtocol((short) 6);
522 matchBuilder.setIpMatch(ipMatch.build());
524 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
525 tcpFlagMatch.setTcpFlag(TCP_SYN);
526 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
531 * Create tcp proto syn match.
533 * @param matchBuilder the match builder
534 * @return matchBuilder match builder
536 public static MatchBuilder createTcpProtoSynMatch(MatchBuilder matchBuilder) {
538 // TCP Protocol Match
539 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
540 ipMatch.setIpProtocol((short) 6);
541 matchBuilder.setIpMatch(ipMatch.build());
543 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
544 tcpFlagMatch.setTcpFlag(TCP_SYN);
545 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
550 * Create dmac tcp port with flag match.
552 * @param matchBuilder the match builder
553 * @param attachedMac the attached mac
554 * @param tcpFlag the tcp flag
555 * @param tunnelID the tunnel iD
556 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN)
558 public static MatchBuilder createDmacTcpPortWithFlagMatch(MatchBuilder matchBuilder,
559 String attachedMac, Integer tcpFlag, String tunnelID) {
560 return createDmacTcpPortIpSaWithFlagMatch(matchBuilder, attachedMac, tcpFlag, null, tunnelID);
564 * Create dmac ipSa match.
566 * @param matchBuilder the match builder
567 * @param attachedMac the attached mac
568 * @param ipPrefix the src ipPrefix
569 * @param tunnelID the tunnel iD
570 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN), Ip Source Address (IPsa)
572 public static MatchBuilder createDmacIpSaMatch(
573 MatchBuilder matchBuilder, String attachedMac, Ipv4Prefix ipPrefix, String tunnelID) {
574 return createDmacTcpPortIpSaWithFlagMatch(matchBuilder, attachedMac, null, ipPrefix, tunnelID);
578 * Create dmac tcp port ipSa with flag match.
580 * @param matchBuilder the match builder
581 * @param attachedMac the attached mac
582 * @param tcpFlag the tcp flag
583 * @param ipPrefix the src ipPrefix
584 * @param tunnelID the tunnel iD
585 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN), Ip Source Address (IPsa)
587 public static MatchBuilder createDmacTcpPortIpSaWithFlagMatch(
588 MatchBuilder matchBuilder, String attachedMac, Integer tcpFlag, Ipv4Prefix ipPrefix, String tunnelID) {
590 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
591 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
592 ethTypeBuilder.setType(new EtherType(0x0800L));
593 ethernetMatch.setEthernetType(ethTypeBuilder.build());
595 if (attachedMac != null) {
596 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
597 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
598 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
599 matchBuilder.setEthernetMatch(ethernetMatch.build());
602 if (tcpFlag != null) {
603 // TCP Protocol Match
604 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
605 ipMatch.setIpProtocol(TCP_SHORT);
606 matchBuilder.setIpMatch(ipMatch.build());
608 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
609 tcpFlagMatch.setTcpFlag(tcpFlag);
610 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
613 if (tunnelID != null) {
614 TunnelBuilder tunnelBuilder = new TunnelBuilder();
615 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
616 matchBuilder.setTunnel(tunnelBuilder.build());
619 if (ipPrefix != null) {
620 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
621 ipv4match.setIpv4Source(ipPrefix);
622 matchBuilder.setLayer3Match(ipv4match.build());
629 * Create dmac tcp syn match.
631 * @param matchBuilder the match builder
632 * @param attachedMac the attached mac
633 * @param tcpPort the tcp port
634 * @param tcpFlag the tcp flag
635 * @param tunnelID the tunnel iD
636 * @return the match builder
638 public static MatchBuilder createDmacTcpSynMatch(MatchBuilder matchBuilder,
639 String attachedMac, PortNumber tcpPort, Integer tcpFlag, String tunnelID) {
641 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
642 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
643 ethTypeBuilder.setType(new EtherType(0x0800L));
644 ethernetMatch.setEthernetType(ethTypeBuilder.build());
646 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
647 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
648 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
649 matchBuilder.setEthernetMatch(ethernetMatch.build());
651 // TCP Protocol Match
652 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
653 ipMatch.setIpProtocol((short) 6);
654 matchBuilder.setIpMatch(ipMatch.build());
657 PortNumber dstPort = new PortNumber(tcpPort);
658 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
659 tcpMatch.setTcpDestinationPort(dstPort);
660 matchBuilder.setLayer4Match(tcpMatch.build());
662 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
663 tcpFlagMatch.setTcpFlag(tcpFlag);
664 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
666 TunnelBuilder tunnelBuilder = new TunnelBuilder();
667 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
668 matchBuilder.setTunnel(tunnelBuilder.build());
674 * Create dmac tcp syn dst ip prefix tcp port.
676 * @param matchBuilder the match builder
677 * @param attachedMac the attached mac
678 * @param tcpPort the tcp port
679 * @param tcpFlag the tcp flag
680 * @param segmentationId the segmentation id
681 * @param dstIp the dst ip
682 * @return the match builder
684 public static MatchBuilder createDmacTcpSynDstIpPrefixTcpPort(MatchBuilder matchBuilder,
685 MacAddress attachedMac, PortNumber tcpPort, Integer tcpFlag, String segmentationId,
688 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
689 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
690 ethTypeBuilder.setType(new EtherType(0x0800L));
691 ethernetMatch.setEthernetType(ethTypeBuilder.build());
693 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
694 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
695 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
697 matchBuilder.setEthernetMatch(ethernetMatch.build());
699 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
700 ipv4match.setIpv4Destination(dstIp);
701 matchBuilder.setLayer3Match(ipv4match.build());
703 // TCP Protocol Match
704 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
705 ipMatch.setIpProtocol(TCP_SHORT);
706 matchBuilder.setIpMatch(ipMatch.build());
709 PortNumber dstPort = new PortNumber(tcpPort);
710 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
711 tcpMatch.setTcpDestinationPort(dstPort);
712 matchBuilder.setLayer4Match(tcpMatch.build());
714 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
715 tcpFlagMatch.setTcpFlag(tcpFlag);
716 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
718 TunnelBuilder tunnelBuilder = new TunnelBuilder();
719 tunnelBuilder.setTunnelId(new BigInteger(segmentationId));
720 matchBuilder.setTunnel(tunnelBuilder.build());
726 * Create dmac ip tcp syn match.
728 * @param matchBuilder the match builder
729 * @param dMacAddr the d mac addr
730 * @param mask the mask
731 * @param ipPrefix the ip prefix
732 * @return MatchBuilder containing the metadata match values
734 public static MatchBuilder createDmacIpTcpSynMatch(MatchBuilder matchBuilder,
735 MacAddress dMacAddr, MacAddress mask, Ipv4Prefix ipPrefix) {
737 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
738 EthernetDestinationBuilder ethDestBuilder = new EthernetDestinationBuilder();
739 ethDestBuilder.setAddress(new MacAddress(dMacAddr));
741 ethDestBuilder.setMask(mask);
743 ethernetMatch.setEthernetDestination(ethDestBuilder.build());
744 matchBuilder.setEthernetMatch(ethernetMatch.build());
746 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
747 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
748 ethTypeBuilder.setType(new EtherType(0x0800L));
749 ethernetType.setEthernetType(ethTypeBuilder.build());
750 matchBuilder.setEthernetMatch(ethernetType.build());
751 if (ipPrefix != null) {
752 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
753 ipv4match.setIpv4Destination(ipPrefix);
754 matchBuilder.setLayer3Match(ipv4match.build());
756 // TCP Protocol Match
757 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
758 ipMatch.setIpProtocol(TCP_SHORT);
759 matchBuilder.setIpMatch(ipMatch.build());
761 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
762 tcpFlagMatch.setTcpFlag(TCP_SYN);
763 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
769 * Create smac tcp syn dst ip prefix tcp port.
771 * @param matchBuilder the match builder
772 * @param attachedMac the attached mac
773 * @param tcpPort the tcp port
774 * @param tcpFlag the tcp flag
775 * @param segmentationId the segmentation id
776 * @param dstIp the dst ip
777 * @return the match builder
779 public static MatchBuilder createSmacTcpSynDstIpPrefixTcpPort(MatchBuilder matchBuilder, MacAddress attachedMac,
780 PortNumber tcpPort, Integer tcpFlag, String segmentationId, Ipv4Prefix dstIp) {
782 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
783 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
784 ethTypeBuilder.setType(new EtherType(0x0800L));
785 ethernetMatch.setEthernetType(ethTypeBuilder.build());
787 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
788 ethSourceBuilder.setAddress(new MacAddress(attachedMac));
789 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
791 matchBuilder.setEthernetMatch(ethernetMatch.build());
793 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
794 ipv4match.setIpv4Destination(dstIp);
795 matchBuilder.setLayer3Match(ipv4match.build());
797 // TCP Protocol Match
798 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
799 ipMatch.setIpProtocol(TCP_SHORT);
800 matchBuilder.setIpMatch(ipMatch.build());
803 PortNumber dstPort = new PortNumber(tcpPort);
804 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
805 tcpMatch.setTcpDestinationPort(dstPort);
806 matchBuilder.setLayer4Match(tcpMatch.build());
808 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
809 tcpFlagMatch.setTcpFlag(tcpFlag);
810 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
812 TunnelBuilder tunnelBuilder = new TunnelBuilder();
813 tunnelBuilder.setTunnelId(new BigInteger(segmentationId));
814 matchBuilder.setTunnel(tunnelBuilder.build());
820 * Create smac tcp port with flag match.
822 * @param matchBuilder the match builder
823 * @param attachedMac the attached mac
824 * @param tcpFlag the tcp flag
825 * @param tunnelID the tunnel iD
826 * @return matchBuilder
828 public static MatchBuilder createSmacTcpPortWithFlagMatch(MatchBuilder matchBuilder, String attachedMac,
829 Integer tcpFlag, String tunnelID) {
831 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
832 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
833 ethTypeBuilder.setType(new EtherType(0x0800L));
834 ethernetMatch.setEthernetType(ethTypeBuilder.build());
836 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
837 ethSrcBuilder.setAddress(new MacAddress(attachedMac));
838 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
839 matchBuilder.setEthernetMatch(ethernetMatch.build());
841 // TCP Protocol Match
842 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
843 ipMatch.setIpProtocol(TCP_SHORT);
844 matchBuilder.setIpMatch(ipMatch.build());
846 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
847 tcpFlagMatch.setTcpFlag(tcpFlag);
848 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
850 TunnelBuilder tunnelBuilder = new TunnelBuilder();
851 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
852 matchBuilder.setTunnel(tunnelBuilder.build());
858 * Create smac ip tcp syn match.
860 * @param matchBuilder the match builder
861 * @param dMacAddr the d mac addr
862 * @param mask the mask
863 * @param ipPrefix the ip prefix
864 * @return MatchBuilder containing the metadata match values
866 public static MatchBuilder createSmacIpTcpSynMatch(MatchBuilder matchBuilder, MacAddress dMacAddr,
867 MacAddress mask, Ipv4Prefix ipPrefix) {
869 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
870 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
871 ethSrcBuilder.setAddress(new MacAddress(dMacAddr));
873 ethSrcBuilder.setMask(mask);
875 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
876 matchBuilder.setEthernetMatch(ethernetMatch.build());
878 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
879 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
880 ethTypeBuilder.setType(new EtherType(0x0800L));
881 ethernetType.setEthernetType(ethTypeBuilder.build());
882 matchBuilder.setEthernetMatch(ethernetType.build());
883 if (ipPrefix != null) {
884 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
885 ipv4match.setIpv4Destination(ipPrefix);
886 matchBuilder.setLayer3Match(ipv4match.build());
888 // TCP Protocol Match
889 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
890 ipMatch.setIpProtocol(TCP_SHORT);
891 matchBuilder.setIpMatch(ipMatch.build());
893 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
894 tcpFlagMatch.setTcpFlag(TCP_SYN);
895 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
901 * Create smac tcp syn.
903 * @param matchBuilder the match builder
904 * @param attachedMac the attached mac
905 * @param tcpPort the tcp port
906 * @param tcpFlag the tcp flag
907 * @param tunnelID the tunnel iD
908 * @return the match builder
910 public static MatchBuilder createSmacTcpSyn(MatchBuilder matchBuilder,
911 String attachedMac, PortNumber tcpPort, Integer tcpFlag, String tunnelID) {
913 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
914 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
915 ethTypeBuilder.setType(new EtherType(0x0800L));
916 ethernetMatch.setEthernetType(ethTypeBuilder.build());
918 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
919 ethSrcBuilder.setAddress(new MacAddress(attachedMac));
920 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
921 matchBuilder.setEthernetMatch(ethernetMatch.build());
923 // TCP Protocol Match
924 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
925 ipMatch.setIpProtocol((short) 6);
926 matchBuilder.setIpMatch(ipMatch.build());
929 PortNumber dstPort = new PortNumber(tcpPort);
930 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
931 tcpMatch.setTcpDestinationPort(dstPort);
932 matchBuilder.setLayer4Match(tcpMatch.build());
935 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
936 tcpFlagMatch.setTcpFlag(tcpFlag);
937 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
939 TunnelBuilder tunnelBuilder = new TunnelBuilder();
940 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
941 matchBuilder.setTunnel(tunnelBuilder.build());
947 * @return MatchBuilder containing the metadata match values
949 public static MatchBuilder createMacSrcIpTcpSynMatch(MatchBuilder matchBuilder,
950 MacAddress dMacAddr, MacAddress mask, Ipv4Prefix ipPrefix) {
952 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
953 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
954 ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
956 ethDestinationBuilder.setMask(mask);
958 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
959 matchBuilder.setEthernetMatch(ethernetMatch.build());
961 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
962 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
963 ethTypeBuilder.setType(new EtherType(0x0800L));
964 ethernetType.setEthernetType(ethTypeBuilder.build());
965 matchBuilder.setEthernetMatch(ethernetType.build());
966 if (ipPrefix != null) {
967 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
968 ipv4match.setIpv4Source(ipPrefix);
969 matchBuilder.setLayer3Match(ipv4match.build());
971 // TCP Protocol Match
972 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
973 ipMatch.setIpProtocol(TCP_SHORT);
974 matchBuilder.setIpMatch(ipMatch.build());
976 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
977 tcpFlagMatch.setTcpFlag(TCP_SYN);
978 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
984 * Create a DHCP match with port provided.
986 * @param matchBuilder the match builder
987 * @param srcPort the source port
988 * @param dstPort the destination port
989 * @return the DHCP match
991 public static MatchBuilder createDhcpMatch(MatchBuilder matchBuilder,
992 int srcPort, int dstPort) {
994 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
995 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
996 ethTypeBuilder.setType(new EtherType(0x0800L));
997 ethernetMatch.setEthernetType(ethTypeBuilder.build());
998 matchBuilder.setEthernetMatch(ethernetMatch.build());
1000 IpMatchBuilder ipmatch = new IpMatchBuilder();
1001 ipmatch.setIpProtocol(UDP_SHORT);
1002 matchBuilder.setIpMatch(ipmatch.build());
1004 UdpMatchBuilder udpmatch = new UdpMatchBuilder();
1005 udpmatch.setUdpSourcePort(new PortNumber(srcPort));
1006 udpmatch.setUdpDestinationPort(new PortNumber(dstPort));
1007 matchBuilder.setLayer4Match(udpmatch.build());
1009 return matchBuilder;
1014 * Create a DHCP match with port provided.
1016 * @param matchBuilder the match builder
1017 * @param srcPort the source port
1018 * @param dstPort the destination port
1019 * @return the DHCP match
1021 public static MatchBuilder createDhcpv6Match(MatchBuilder matchBuilder,
1022 int srcPort, int dstPort) {
1024 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1025 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1026 ethTypeBuilder.setType(new EtherType(0x86DDL));
1027 ethernetMatch.setEthernetType(ethTypeBuilder.build());
1028 matchBuilder.setEthernetMatch(ethernetMatch.build());
1030 IpMatchBuilder ipmatch = new IpMatchBuilder();
1031 ipmatch.setIpProtocol(UDP_SHORT);
1032 matchBuilder.setIpMatch(ipmatch.build());
1034 UdpMatchBuilder udpmatch = new UdpMatchBuilder();
1035 udpmatch.setUdpSourcePort(new PortNumber(srcPort));
1036 udpmatch.setUdpDestinationPort(new PortNumber(dstPort));
1037 matchBuilder.setLayer4Match(udpmatch.build());
1039 return matchBuilder;
1044 * Creates DHCP server packet match with DHCP mac address and port.
1046 * @param matchBuilder the matchbuilder
1047 * @param dhcpServerMac MAc address of the DHCP server of the subnet
1048 * @param srcPort the source port
1049 * @param dstPort the destination port
1050 * @return the DHCP server match
1052 public static MatchBuilder createDhcpServerMatch(MatchBuilder matchBuilder, String dhcpServerMac, int srcPort,
1055 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1056 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1057 ethTypeBuilder.setType(new EtherType(0x0800L));
1058 ethernetMatch.setEthernetType(ethTypeBuilder.build());
1059 matchBuilder.setEthernetMatch(ethernetMatch.build());
1061 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1062 ethSourceBuilder.setAddress(new MacAddress(dhcpServerMac));
1063 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1064 matchBuilder.setEthernetMatch(ethernetMatch.build());
1066 IpMatchBuilder ipmatch = new IpMatchBuilder();
1067 ipmatch.setIpProtocol(UDP_SHORT);
1068 matchBuilder.setIpMatch(ipmatch.build());
1070 UdpMatchBuilder udpmatch = new UdpMatchBuilder();
1071 udpmatch.setUdpSourcePort(new PortNumber(srcPort));
1072 udpmatch.setUdpDestinationPort(new PortNumber(dstPort));
1073 matchBuilder.setLayer4Match(udpmatch.build());
1075 return matchBuilder;
1080 * Creates DHCPv6 server packet match with DHCP mac address and port.
1082 * @param matchBuilder the matchbuilder
1083 * @param dhcpServerMac MAc address of the DHCP server of the subnet
1084 * @param srcPort the source port
1085 * @param dstPort the destination port
1086 * @return the DHCP server match
1088 public static MatchBuilder createDhcpv6ServerMatch(MatchBuilder matchBuilder, String dhcpServerMac, int srcPort,
1091 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
1092 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1093 ethTypeBuilder.setType(new EtherType(0x86DDL));
1094 ethernetMatch.setEthernetType(ethTypeBuilder.build());
1095 matchBuilder.setEthernetMatch(ethernetMatch.build());
1097 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1098 ethSourceBuilder.setAddress(new MacAddress(dhcpServerMac));
1099 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
1100 matchBuilder.setEthernetMatch(ethernetMatch.build());
1102 IpMatchBuilder ipmatch = new IpMatchBuilder();
1103 ipmatch.setIpProtocol(UDP_SHORT);
1104 matchBuilder.setIpMatch(ipmatch.build());
1106 UdpMatchBuilder udpmatch = new UdpMatchBuilder();
1107 udpmatch.setUdpSourcePort(new PortNumber(srcPort));
1108 udpmatch.setUdpDestinationPort(new PortNumber(dstPort));
1109 matchBuilder.setLayer4Match(udpmatch.build());
1111 return matchBuilder;
1116 * Creates a Match with src ip address mac address set.
1117 * @param matchBuilder MatchBuilder Object
1118 * @param srcip String containing an IPv4 prefix
1119 * @param srcMac The source macAddress
1120 * @return matchBuilder Map Object with a match
1122 public static MatchBuilder createSrcL3Ipv4MatchWithMac(MatchBuilder matchBuilder, Ipv4Prefix srcip, MacAddress srcMac) {
1124 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
1125 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(srcip));
1126 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1127 ethTypeBuilder.setType(new EtherType(0x0800L));
1128 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1129 eth.setEthernetType(ethTypeBuilder.build());
1130 eth.setEthernetSource(new EthernetSourceBuilder()
1134 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
1135 matchBuilder.setEthernetMatch(eth.build());
1136 return matchBuilder;
1141 * Creates a Match with src ip address mac address set.
1142 * @param matchBuilder MatchBuilder Object
1143 * @param srcip String containing an IPv6 prefix
1144 * @param srcMac The source macAddress
1145 * @return matchBuilder Map Object with a match
1147 public static MatchBuilder createSrcL3Ipv6MatchWithMac(MatchBuilder matchBuilder, Ipv6Prefix srcip, MacAddress srcMac) {
1149 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
1150 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(srcip));
1151 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1152 ethTypeBuilder.setType(new EtherType(0x86DDL));
1153 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1154 eth.setEthernetType(ethTypeBuilder.build());
1155 eth.setEthernetSource(new EthernetSourceBuilder()
1159 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1160 matchBuilder.setEthernetMatch(eth.build());
1161 return matchBuilder;
1166 * Creates a ether net match with ether type set to 0x0800L.
1167 * @param matchBuilder MatchBuilder Object
1168 * @param srcMac The source macAddress
1169 * @param dstMac The destination mac address
1170 * @return matchBuilder Map Object with a match
1172 public static MatchBuilder createV4EtherMatchWithType(MatchBuilder matchBuilder,String srcMac, String dstMac)
1174 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1175 ethTypeBuilder.setType(new EtherType(0x0800L));
1176 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1177 eth.setEthernetType(ethTypeBuilder.build());
1178 if (null != srcMac) {
1179 eth.setEthernetSource(new EthernetSourceBuilder()
1180 .setAddress(new MacAddress(srcMac)).build());
1182 if (null != dstMac) {
1183 eth.setEthernetDestination(new EthernetDestinationBuilder()
1184 .setAddress(new MacAddress(dstMac)).build());
1186 matchBuilder.setEthernetMatch(eth.build());
1187 return matchBuilder;
1191 * Creates a ether net match with ether type set to 0x86DDL.
1192 * @param matchBuilder MatchBuilder Object
1193 * @param srcMac The source macAddress
1194 * @param dstMac The destination mac address
1195 * @return matchBuilder Map Object with a match
1197 public static MatchBuilder createV6EtherMatchWithType(MatchBuilder matchBuilder,String srcMac, String dstMac)
1199 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1200 ethTypeBuilder.setType(new EtherType(0x86DDL));
1201 EthernetMatchBuilder eth = new EthernetMatchBuilder();
1202 eth.setEthernetType(ethTypeBuilder.build());
1203 if (null != srcMac) {
1204 eth.setEthernetSource(new EthernetSourceBuilder()
1205 .setAddress(new MacAddress(srcMac)).build());
1207 if (null != dstMac) {
1208 eth.setEthernetDestination(new EthernetDestinationBuilder()
1209 .setAddress(new MacAddress(dstMac)).build());
1211 matchBuilder.setEthernetMatch(eth.build());
1212 return matchBuilder;
1216 * Adds remote Ip prefix to existing match.
1217 * @param matchBuilder The match builder
1218 * @param sourceIpPrefix The source IP prefix
1219 * @param destIpPrefix The destination IP prefix
1220 * @return matchBuilder Map Object with a match
1222 public static MatchBuilder addRemoteIpPrefix(MatchBuilder matchBuilder,
1223 Ipv4Prefix sourceIpPrefix,Ipv4Prefix destIpPrefix) {
1224 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
1225 if (null != sourceIpPrefix) {
1226 ipv4match.setIpv4Source(sourceIpPrefix);
1228 if (null != destIpPrefix) {
1229 ipv4match.setIpv4Destination(destIpPrefix);
1231 matchBuilder.setLayer3Match(ipv4match.build());
1233 return matchBuilder;
1237 * Adds remote Ipv6 prefix to existing match.
1238 * @param matchBuilder The match builder
1239 * @param sourceIpPrefix The source IP prefix
1240 * @param destIpPrefix The destination IP prefix
1241 * @return matchBuilder Map Object with a match
1243 public static MatchBuilder addRemoteIpv6Prefix(MatchBuilder matchBuilder,
1244 Ipv6Prefix sourceIpPrefix,Ipv6Prefix destIpPrefix) {
1245 Ipv6MatchBuilder ipv6match = new Ipv6MatchBuilder();
1246 if (null != sourceIpPrefix) {
1247 ipv6match.setIpv6Source(sourceIpPrefix);
1249 if (null != destIpPrefix) {
1250 ipv6match.setIpv6Destination(destIpPrefix);
1252 matchBuilder.setLayer3Match(ipv6match.build());
1254 return matchBuilder;
1258 * Add a layer4 match to an existing match
1260 * @param matchBuilder Map matchBuilder MatchBuilder Object with a match
1261 * @param protocol The layer4 protocol
1262 * @param srcPort The src port
1263 * @param destPort The destination port
1264 * @return matchBuilder Map Object with a match
1266 public static MatchBuilder addLayer4Match(MatchBuilder matchBuilder,
1267 int protocol, int srcPort, int destPort) {
1268 IpMatchBuilder ipmatch = new IpMatchBuilder();
1269 if (TCP_SHORT == protocol) {
1270 ipmatch.setIpProtocol(TCP_SHORT);
1271 TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
1273 tcpmatch.setTcpSourcePort(new PortNumber(srcPort));
1275 if (0 != destPort) {
1276 tcpmatch.setTcpDestinationPort(new PortNumber(destPort));
1278 matchBuilder.setLayer4Match(tcpmatch.build());
1279 } else if (UDP_SHORT == protocol) {
1280 ipmatch.setIpProtocol(UDP_SHORT);
1281 UdpMatchBuilder udpMatch = new UdpMatchBuilder();
1283 udpMatch.setUdpSourcePort(new PortNumber(srcPort));
1285 if (0 != destPort) {
1286 udpMatch.setUdpDestinationPort(new PortNumber(destPort));
1288 matchBuilder.setLayer4Match(udpMatch.build());
1290 matchBuilder.setIpMatch(ipmatch.build());
1292 return matchBuilder;
1296 * Add a layer4 match to an existing match with mask
1298 * @param matchBuilder Map matchBuilder MatchBuilder Object with a match.
1299 * @param protocol The layer4 protocol
1300 * @param srcPort The src port
1301 * @param destPort The destination port
1302 * @param mask the mask for the port
1303 * @return matchBuilder Map Object with a match
1305 public static MatchBuilder addLayer4MatchWithMask(MatchBuilder matchBuilder,
1306 int protocol, int srcPort, int destPort,int mask) {
1308 IpMatchBuilder ipmatch = new IpMatchBuilder();
1310 NxAugMatchNodesNodeTableFlow nxAugMatch = null;
1311 GeneralAugMatchNodesNodeTableFlow genAugMatch = null;
1312 if (protocol == TCP_SHORT) {
1313 ipmatch.setIpProtocol(TCP_SHORT);
1315 NxmOfTcpSrcBuilder tcpSrc = new NxmOfTcpSrcBuilder();
1316 tcpSrc.setPort(new PortNumber(srcPort));
1317 tcpSrc.setMask(mask);
1318 nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfTcpSrc(tcpSrc.build()).build();
1319 genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1320 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmOfTcpSrcKey.class)
1321 .setExtension(new ExtensionBuilder()
1322 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1323 .build()).build())).build();
1324 } else if (0 != destPort) {
1325 NxmOfTcpDstBuilder tcpDst = new NxmOfTcpDstBuilder();
1326 tcpDst.setPort(new PortNumber(destPort));
1327 tcpDst.setMask(mask);
1328 nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
1329 .setNxmOfTcpDst(tcpDst.build())
1331 genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1332 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmOfTcpDstKey.class)
1333 .setExtension(new ExtensionBuilder()
1334 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1335 .build()).build())).build();
1338 } else if (UDP_SHORT == protocol) {
1339 ipmatch.setIpProtocol(UDP_SHORT);
1340 UdpMatchBuilder udpMatch = new UdpMatchBuilder();
1342 NxmOfUdpSrcBuilder udpSrc = new NxmOfUdpSrcBuilder();
1343 udpSrc.setPort(new PortNumber(srcPort));
1344 udpSrc.setMask(mask);
1345 nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder().setNxmOfUdpSrc(udpSrc.build()).build();
1346 genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1347 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmOfUdpSrcKey.class)
1348 .setExtension(new ExtensionBuilder()
1349 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1350 .build()).build())).build();
1351 } else if (0 != destPort) {
1352 NxmOfUdpDstBuilder udpDst = new NxmOfUdpDstBuilder();
1353 udpDst.setPort(new PortNumber(destPort));
1354 udpDst.setMask(mask);
1355 nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
1356 .setNxmOfUdpDst(udpDst.build())
1358 genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1359 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmOfUdpDstKey.class)
1360 .setExtension(new ExtensionBuilder()
1361 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1362 .build()).build())).build();
1365 matchBuilder.setIpMatch(ipmatch.build());
1366 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
1367 return matchBuilder;
1370 public static MatchBuilder addCtState(MatchBuilder matchBuilder,int ct_state, int mask) {
1371 NxmNxCtStateBuilder ctStateBuilder = new NxmNxCtStateBuilder();
1372 ctStateBuilder.setCtState((long)ct_state);
1373 ctStateBuilder.setMask((long)mask);
1374 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
1375 .setNxmNxCtState(ctStateBuilder.build())
1377 GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1378 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmNxCtStateKey.class)
1379 .setExtension(new ExtensionBuilder()
1380 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1381 .build()).build())).build();
1382 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
1383 return matchBuilder;
1386 public static MatchBuilder addCtZone(MatchBuilder matchBuilder,int ct_zone) {
1387 NxmNxCtZoneBuilder ctZoneBuilder = new NxmNxCtZoneBuilder();
1388 ctZoneBuilder.setCtZone(ct_zone);
1389 NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
1390 .setNxmNxCtZone(ctZoneBuilder.build())
1392 GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
1393 .setExtensionList(ImmutableList.of(new ExtensionListBuilder().setExtensionKey(NxmNxCtZoneKey.class)
1394 .setExtension(new ExtensionBuilder()
1395 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
1396 .build()).build())).build();
1397 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
1398 return matchBuilder;
1401 public static class RegMatch {
1402 final Class<? extends NxmNxReg> reg;
1404 public RegMatch(Class<? extends NxmNxReg> reg, Long value) {
1409 public static RegMatch of(Class<? extends NxmNxReg> reg, Long value) {
1410 return new RegMatch(reg, value);
1414 public static MatchBuilder addNxRegMatch(MatchBuilder matchBuilder, RegMatch... matches) {
1415 List<ExtensionList> extensions = new ArrayList<>();
1416 for (RegMatch rm : matches) {
1417 Class<? extends ExtensionKey> key;
1418 if (NxmNxReg0.class.equals(rm.reg)) {
1419 key = NxmNxReg0Key.class;
1420 } else if (NxmNxReg1.class.equals(rm.reg)) {
1421 key = NxmNxReg1Key.class;
1422 } else if (NxmNxReg2.class.equals(rm.reg)) {
1423 key = NxmNxReg2Key.class;
1424 } else if (NxmNxReg3.class.equals(rm.reg)) {
1425 key = NxmNxReg3Key.class;
1426 } else if (NxmNxReg4.class.equals(rm.reg)) {
1427 key = NxmNxReg4Key.class;
1428 } else if (NxmNxReg5.class.equals(rm.reg)) {
1429 key = NxmNxReg5Key.class;
1430 } else if (NxmNxReg6.class.equals(rm.reg)) {
1431 key = NxmNxReg6Key.class;
1433 key = NxmNxReg7Key.class;
1435 NxAugMatchNodesNodeTableFlow am =
1436 new NxAugMatchNodesNodeTableFlowBuilder()
1437 .setNxmNxReg(new NxmNxRegBuilder()
1442 extensions.add(new ExtensionListBuilder()
1443 .setExtensionKey(key)
1444 .setExtension(new ExtensionBuilder()
1445 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
1449 GeneralAugMatchNodesNodeTableFlow m = new GeneralAugMatchNodesNodeTableFlowBuilder()
1450 .setExtensionList(extensions)
1452 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
1453 return matchBuilder;
1456 public static MatchBuilder addNxTunIdMatch(MatchBuilder matchBuilder, int tunId) {
1457 NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
1458 .setNxmNxTunId(new NxmNxTunIdBuilder()
1459 .setValue(BigInteger.valueOf(tunId))
1462 GeneralAugMatchNodesNodeTableFlow m =
1463 new GeneralAugMatchNodesNodeTableFlowBuilder()
1464 .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
1465 .setExtensionKey(NxmNxTunIdKey.class)
1466 .setExtension(new ExtensionBuilder()
1467 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
1471 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
1472 return matchBuilder;
1475 public static MatchBuilder addNxNspMatch(MatchBuilder matchBuilder, long nsp) {
1476 NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
1477 .setNxmNxNsp(new NxmNxNspBuilder()
1481 addExtension(matchBuilder, NxmNxNspKey.class, am);
1482 return matchBuilder;
1485 public static MatchBuilder addNxNsiMatch(MatchBuilder matchBuilder, short nsi) {
1486 NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder()
1487 .setNxmNxNsi(new NxmNxNsiBuilder()
1491 addExtension(matchBuilder, NxmNxNsiKey.class, am);
1492 return matchBuilder;
1495 private static void addExtension(MatchBuilder matchBuilder, Class<? extends ExtensionKey> extensionKey,
1496 NxAugMatchNodesNodeTableFlow am) {
1497 GeneralAugMatchNodesNodeTableFlow existingAugmentations =
1498 matchBuilder.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
1499 List<ExtensionList> extensions = null;
1500 if (existingAugmentations != null ) {
1501 extensions = existingAugmentations.getExtensionList();
1503 if (extensions == null) {
1504 extensions = Lists.newArrayList();
1507 extensions.add(new ExtensionListBuilder()
1508 .setExtensionKey(extensionKey)
1509 .setExtension(new ExtensionBuilder()
1510 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
1514 GeneralAugMatchNodesNodeTableFlow m = new GeneralAugMatchNodesNodeTableFlowBuilder()
1515 .setExtensionList(extensions)
1517 matchBuilder.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
1520 public static EthernetMatch ethernetMatch(MacAddress srcMac,
1523 EthernetMatchBuilder emb = new EthernetMatchBuilder();
1524 if (srcMac != null) {
1525 emb.setEthernetSource(new EthernetSourceBuilder()
1529 if (dstMac != null) {
1530 emb.setEthernetDestination(new EthernetDestinationBuilder()
1534 if (etherType != null) {
1535 emb.setEthernetType(new EthernetTypeBuilder()
1536 .setType(new EtherType(etherType))
1543 * Create ipv4 prefix from ipv4 address, by appending /32 mask
1545 * @param ipv4AddressString the ip address, in string format
1546 * @return Ipv4Prefix with ipv4Address and /32 mask
1548 public static Ipv4Prefix iPv4PrefixFromIPv4Address(String ipv4AddressString) {
1549 return new Ipv4Prefix(ipv4AddressString + "/32");
1553 * Create ipv6 prefix from ipv6 address, by appending /128 mask
1555 * @param ipv6AddressString the ip address, in string format
1556 * @return Ipv6Prefix with ipv6Address and /128 mask
1558 public static Ipv6Prefix iPv6PrefixFromIPv6Address(String ipv6AddressString) {
1559 return new Ipv6Prefix(ipv6AddressString + "/128");
1563 * Converts port range into a set of masked port ranges.
1565 * @param portMin the strating port of the range.
1566 * @param portMax the ending port of the range.
1567 * @return the map contianing the port no and their mask.
1570 public static Map<Integer,Integer> getLayer4MaskForRange(int portMin, int portMax) {
1571 int [] offset = {32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1};
1572 int[] mask = {0x8000,0xC000,0xE000,0xF000,0xF800,0xFC00,0xFE00,0xFF00,
1573 0xFF80,0xFFC0,0xFFE0,0xFFF0,0xFFF8,0xFFFC,0xFFFE,0xFFFF};
1574 int noOfPorts = portMax - portMin + 1;
1575 String binaryNoOfPorts = Integer.toBinaryString(noOfPorts);
1576 int medianOffset = 16 - binaryNoOfPorts.length();
1577 int medianLength = offset[medianOffset];
1579 for (int tempMedian = 0;tempMedian < portMax;) {
1580 tempMedian = medianLength + tempMedian;
1581 if (portMin < tempMedian) {
1582 median = tempMedian;
1586 Map<Integer,Integer> portMap = new HashMap<Integer,Integer>();
1588 int currentMedain = median;
1589 for (int tempMedianOffset = medianOffset;16 > tempMedianOffset;tempMedianOffset++) {
1590 tempMedian = currentMedain - offset[tempMedianOffset];
1591 if (portMin <= tempMedian) {
1592 for (;portMin <= tempMedian;) {
1593 portMap.put(tempMedian, mask[tempMedianOffset]);
1594 currentMedain = tempMedian;
1595 tempMedian = tempMedian - offset[tempMedianOffset];
1599 currentMedain = median;
1600 for (int tempMedianOffset = medianOffset;16 > tempMedianOffset;tempMedianOffset++) {
1601 tempMedian = currentMedain + offset[tempMedianOffset];
1602 if (portMax >= tempMedian - 1) {
1603 for (;portMax >= tempMedian - 1;) {
1604 portMap.put(currentMedain, mask[tempMedianOffset]);
1605 currentMedain = tempMedian;
1606 tempMedian = tempMedian + offset[tempMedianOffset];
1614 * Return Long that represents OF port for strings where OF is explicitly provided
1616 * @param ofPortIdentifier the string with encoded OF port (example format "OFPort|999")
1617 * @return the OFport or null
1619 public static Long parseExplicitOFPort(String ofPortIdentifier) {
1620 if (ofPortIdentifier != null) {
1621 String[] pair = ofPortIdentifier.split("\\|");
1622 if ((pair.length > 1) && (pair[0].equalsIgnoreCase("OFPort"))) {
1623 return new Long(pair[1]);