2 * Copyright (C) 2013 Red Hat, Inc.
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
10 package org.opendaylight.ovsdb.utils.mdsal.openflow;
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg1Key;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg3Key;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg4Key;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg5Key;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg7Key;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNspKey;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNsiKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsi.grouping.NxmNxNsiBuilder;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
72 import com.google.common.collect.ImmutableList;
73 import com.google.common.collect.Lists;
75 public class MatchUtils {
76 private static final Logger logger = LoggerFactory.getLogger(MatchUtils.class);
77 public static final short ICMP_SHORT = 1;
78 public static final short TCP_SHORT = 6;
79 public static final short UDP_SHORT = 17;
80 public static final String TCP = "tcp";
81 public static final String UDP = "udp";
82 private static final int TCP_SYN = 0x0002;
85 * Create Ingress Port Match dpidLong, inPort
87 * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
88 * @param dpidLong Long the datapath ID of a switch/node
89 * @param inPort Long ingress port on a switch
90 * @return matchBuilder Map MatchBuilder Object with a match
92 public static MatchBuilder createInPortMatch(MatchBuilder matchBuilder, Long dpidLong, Long inPort) {
94 NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + inPort);
95 logger.debug("createInPortMatch() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, inPort);
96 matchBuilder.setInPort(NodeConnectorId.getDefaultInstance(ncid.getValue()));
97 matchBuilder.setInPort(ncid);
103 * Create EtherType Match
105 * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
106 * @param etherType Long EtherType
107 * @return matchBuilder Map MatchBuilder Object with a match
109 public static MatchBuilder createEtherTypeMatch(MatchBuilder matchBuilder, EtherType etherType) {
111 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
112 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
113 ethTypeBuilder.setType(new EtherType(etherType));
114 ethernetMatch.setEthernetType(ethTypeBuilder.build());
115 matchBuilder.setEthernetMatch(ethernetMatch.build());
121 * Create Ethernet Source Match
123 * @param matchBuilder MatchBuilder Object without a match yet
124 * @param sMacAddr String representing a source MAC
125 * @return matchBuilder Map MatchBuilder Object with a match
127 public static MatchBuilder createEthSrcMatch(MatchBuilder matchBuilder, MacAddress sMacAddr) {
129 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
130 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
131 ethSourceBuilder.setAddress(new MacAddress(sMacAddr));
132 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
133 matchBuilder.setEthernetMatch(ethernetMatch.build());
139 * Create Ethernet Destination Match
141 * @param matchBuilder MatchBuilder Object without a match yet
142 * @param vlanId Integer representing a VLAN ID Integer representing a VLAN ID
143 * @return matchBuilder Map MatchBuilder Object with a match
145 public static MatchBuilder createVlanIdMatch(MatchBuilder matchBuilder, VlanId vlanId, boolean present) {
146 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
147 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
148 vlanIdBuilder.setVlanId(new VlanId(vlanId));
149 vlanIdBuilder.setVlanIdPresent(present);
150 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
151 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
157 * Create Ethernet Destination Match
159 * @param matchBuilder MatchBuilder Object without a match yet
160 * @param dMacAddr String representing a destination MAC
161 * @return matchBuilder Map MatchBuilder Object with a match
163 public static MatchBuilder createDestEthMatch(MatchBuilder matchBuilder, MacAddress dMacAddr, MacAddress mask) {
165 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
166 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
167 ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
169 ethDestinationBuilder.setMask(mask);
171 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
172 matchBuilder.setEthernetMatch(ethernetMatch.build());
178 * Tunnel ID Match Builder
180 * @param matchBuilder MatchBuilder Object without a match yet
181 * @param tunnelId BigInteger representing a tunnel ID
182 * @return matchBuilder Map MatchBuilder Object with a match
184 public static MatchBuilder createTunnelIDMatch(MatchBuilder matchBuilder, BigInteger tunnelId) {
186 TunnelBuilder tunnelBuilder = new TunnelBuilder();
187 tunnelBuilder.setTunnelId(tunnelId);
188 matchBuilder.setTunnel(tunnelBuilder.build());
194 * Match ICMP code and type
196 * @param matchBuilder MatchBuilder Object without a match yet
197 * @param type short representing an ICMP type
198 * @param code short representing an ICMP code
199 * @return matchBuilder Map MatchBuilder Object with a match
201 public static MatchBuilder createICMPv4Match(MatchBuilder matchBuilder, short type, short code) {
203 EthernetMatchBuilder eth = new EthernetMatchBuilder();
204 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
205 ethTypeBuilder.setType(new EtherType(0x0800L));
206 eth.setEthernetType(ethTypeBuilder.build());
207 matchBuilder.setEthernetMatch(eth.build());
209 // Build the IPv4 Match requied per OVS Syntax
210 IpMatchBuilder ipmatch = new IpMatchBuilder();
211 ipmatch.setIpProtocol((short) 1);
212 matchBuilder.setIpMatch(ipmatch.build());
214 // Build the ICMPv4 Match
215 Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
216 icmpv4match.setIcmpv4Type(type);
217 icmpv4match.setIcmpv4Code(code);
218 matchBuilder.setIcmpv4Match(icmpv4match.build());
224 * @param matchBuilder MatchBuilder Object without a match yet
225 * @param dstip String containing an IPv4 prefix
226 * @return matchBuilder Map Object with a match
228 public static MatchBuilder createDstL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
230 EthernetMatchBuilder eth = new EthernetMatchBuilder();
231 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
232 ethTypeBuilder.setType(new EtherType(0x0800L));
233 eth.setEthernetType(ethTypeBuilder.build());
234 matchBuilder.setEthernetMatch(eth.build());
236 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
237 ipv4match.setIpv4Destination(dstip);
239 matchBuilder.setLayer3Match(ipv4match.build());
246 * @param matchBuilder MatchBuilder Object without a match yet
247 * @param dstip String containing an IPv4 prefix
248 * @return matchBuilder Map Object with a match
250 public static MatchBuilder createArpDstIpv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
251 ArpMatchBuilder arpDstMatch = new ArpMatchBuilder();
252 arpDstMatch.setArpTargetTransportAddress(dstip);
253 matchBuilder.setLayer3Match(arpDstMatch.build());
259 * @param matchBuilder MatchBuilder Object without a match yet
260 * @param srcip String containing an IPv4 prefix
261 * @return matchBuilder Map Object with a match
263 public static MatchBuilder createSrcL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix srcip) {
265 EthernetMatchBuilder eth = new EthernetMatchBuilder();
266 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
267 ethTypeBuilder.setType(new EtherType(0x0800L));
268 eth.setEthernetType(ethTypeBuilder.build());
269 matchBuilder.setEthernetMatch(eth.build());
271 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
272 ipv4match.setIpv4Source(srcip);
273 matchBuilder.setLayer3Match(ipv4match.build());
280 * Create Source TCP Port Match
282 * @param matchBuilder MatchBuilder Object without a match yet
283 * @param tcpport Integer representing a source TCP port
284 * @return matchBuilder Map MatchBuilder Object with a match
286 public static MatchBuilder createSetSrcTcpMatch(MatchBuilder matchBuilder, PortNumber tcpport) {
288 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
289 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
290 ethTypeBuilder.setType(new EtherType(0x0800L));
291 ethType.setEthernetType(ethTypeBuilder.build());
292 matchBuilder.setEthernetMatch(ethType.build());
294 IpMatchBuilder ipmatch = new IpMatchBuilder();
295 ipmatch.setIpProtocol((short) 6);
296 matchBuilder.setIpMatch(ipmatch.build());
298 TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
299 tcpmatch.setTcpSourcePort(tcpport);
300 matchBuilder.setLayer4Match(tcpmatch.build());
307 * Create Destination TCP Port Match
309 * @param matchBuilder MatchBuilder Object without a match yet
310 * @param tcpDstPort Integer representing a destination TCP port
311 * @return matchBuilder Map MatchBuilder Object with a match
313 public static MatchBuilder createSetDstTcpMatch(MatchBuilder matchBuilder, PortNumber tcpDstPort) {
315 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
316 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
317 ethTypeBuilder.setType(new EtherType(0x0800L));
318 ethType.setEthernetType(ethTypeBuilder.build());
319 matchBuilder.setEthernetMatch(ethType.build());
321 IpMatchBuilder ipmatch = new IpMatchBuilder();
322 ipmatch.setIpProtocol((short) 6);
323 matchBuilder.setIpMatch(ipmatch.build());
325 TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
326 tcpmatch.setTcpDestinationPort(tcpDstPort);
327 matchBuilder.setLayer4Match(tcpmatch.build());
333 * Test match for TCP_Flags
335 * @param matchBuilder MatchBuilder Object without a match yet
336 * @param tcpPort PortNumber representing a destination TCP port
337 * @param tcpFlag int representing a tcp_flag
338 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN)
340 * Defined TCP Flag values in OVS v2.1+
341 * TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
342 * TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
343 * TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS 0x100
345 public static MatchBuilder createTcpFlagMatch(MatchBuilder matchBuilder, PortNumber tcpPort, int tcpFlag) {
348 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
349 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
350 ethTypeBuilder.setType(new EtherType(0x0800L));
351 ethernetType.setEthernetType(ethTypeBuilder.build());
352 matchBuilder.setEthernetMatch(ethernetType.build());
354 // TCP Protocol Match
355 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
356 ipMatch.setIpProtocol((short) 6);
357 matchBuilder.setIpMatch(ipMatch.build());
360 PortNumber dstPort = new PortNumber(tcpPort);
361 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
362 tcpMatch.setTcpDestinationPort(dstPort);
363 matchBuilder.setLayer4Match(tcpMatch.build());
365 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
366 tcpFlagMatch.setTcpFlag(tcpFlag);
367 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
372 * @return MatchBuilder containing the metadata match values
374 public static MatchBuilder createMetadataMatch(MatchBuilder matchBuilder, BigInteger metaData, BigInteger metaDataMask) {
376 // metadata matchbuilder
377 MetadataBuilder metadata = new MetadataBuilder();
378 metadata.setMetadata(metaData);
379 // Optional metadata mask
380 if (metaDataMask != null) {
381 metadata.setMetadataMask(metaDataMask);
383 matchBuilder.setMetadata(metadata.build());
389 * Create TCP Port Match
391 * @param matchBuilder MatchBuilder Object without a match yet
392 * @param ipProtocol Integer representing the IP protocol
393 * @return matchBuilder Map MatchBuilder Object with a match
395 public static MatchBuilder createIpProtocolMatch(MatchBuilder matchBuilder, short ipProtocol) {
397 EthernetMatchBuilder ethType = new EthernetMatchBuilder();
398 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
399 ethTypeBuilder.setType(new EtherType(0x0800L));
400 ethType.setEthernetType(ethTypeBuilder.build());
401 matchBuilder.setEthernetMatch(ethType.build());
403 IpMatchBuilder ipMmatch = new IpMatchBuilder();
404 if (ipProtocol == TCP_SHORT) {
405 ipMmatch.setIpProtocol(TCP_SHORT);
407 else if (ipProtocol == UDP_SHORT) {
408 ipMmatch.setIpProtocol(UDP_SHORT);
410 else if (ipProtocol == ICMP_SHORT) {
411 ipMmatch.setIpProtocol(ICMP_SHORT);
413 matchBuilder.setIpMatch(ipMmatch.build());
418 * Create tcp syn with proto match.
420 * @param matchBuilder the match builder
421 * @return matchBuilder match builder
423 public static MatchBuilder createTcpSynWithProtoMatch(MatchBuilder matchBuilder) {
426 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
427 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
428 ethTypeBuilder.setType(new EtherType(0x0800L));
429 ethernetType.setEthernetType(ethTypeBuilder.build());
430 matchBuilder.setEthernetMatch(ethernetType.build());
432 // TCP Protocol Match
433 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
434 ipMatch.setIpProtocol((short) 6);
435 matchBuilder.setIpMatch(ipMatch.build());
437 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
438 tcpFlagMatch.setTcpFlag(TCP_SYN);
439 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
444 * Create tcp proto syn match.
446 * @param matchBuilder the match builder
447 * @return matchBuilder match builder
449 public static MatchBuilder createTcpProtoSynMatch(MatchBuilder matchBuilder) {
451 // TCP Protocol Match
452 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
453 ipMatch.setIpProtocol((short) 6);
454 matchBuilder.setIpMatch(ipMatch.build());
456 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
457 tcpFlagMatch.setTcpFlag(TCP_SYN);
458 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
463 * Create dmac tcp port with flag match.
465 * @param matchBuilder the match builder
466 * @param attachedMac the attached mac
467 * @param tcpFlag the tcp flag
468 * @param tunnelID the tunnel iD
469 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN)
471 public static MatchBuilder createDmacTcpPortWithFlagMatch(MatchBuilder matchBuilder,
472 String attachedMac, Integer tcpFlag, String tunnelID) {
473 return createDmacTcpPortIpSaWithFlagMatch(matchBuilder, attachedMac, tcpFlag, null, tunnelID);
477 * Create dmac ipSa match.
479 * @param matchBuilder the match builder
480 * @param attachedMac the attached mac
481 * @param ipPrefix the src ipPrefix
482 * @param tunnelID the tunnel iD
483 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN), Ip Source Address (IPsa)
485 public static MatchBuilder createDmacIpSaMatch(
486 MatchBuilder matchBuilder, String attachedMac, Ipv4Prefix ipPrefix, String tunnelID) {
487 return createDmacTcpPortIpSaWithFlagMatch(matchBuilder, attachedMac, null, ipPrefix, tunnelID);
491 * Create dmac tcp port ipSa with flag match.
493 * @param matchBuilder the match builder
494 * @param attachedMac the attached mac
495 * @param tcpFlag the tcp flag
496 * @param ipPrefix the src ipPrefix
497 * @param tunnelID the tunnel iD
498 * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN), Ip Source Address (IPsa)
500 public static MatchBuilder createDmacTcpPortIpSaWithFlagMatch(
501 MatchBuilder matchBuilder, String attachedMac, Integer tcpFlag, Ipv4Prefix ipPrefix, String tunnelID) {
503 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
504 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
505 ethTypeBuilder.setType(new EtherType(0x0800L));
506 ethernetMatch.setEthernetType(ethTypeBuilder.build());
508 if (attachedMac != null) {
509 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
510 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
511 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
512 matchBuilder.setEthernetMatch(ethernetMatch.build());
515 if (tcpFlag != null) {
516 // TCP Protocol Match
517 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
518 ipMatch.setIpProtocol(TCP_SHORT);
519 matchBuilder.setIpMatch(ipMatch.build());
521 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
522 tcpFlagMatch.setTcpFlag(tcpFlag);
523 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
526 if (tunnelID != null) {
527 TunnelBuilder tunnelBuilder = new TunnelBuilder();
528 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
529 matchBuilder.setTunnel(tunnelBuilder.build());
532 if (ipPrefix != null) {
533 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
534 ipv4match.setIpv4Source(ipPrefix);
535 matchBuilder.setLayer3Match(ipv4match.build());
542 * Create dmac tcp syn match.
544 * @param matchBuilder the match builder
545 * @param attachedMac the attached mac
546 * @param tcpPort the tcp port
547 * @param tcpFlag the tcp flag
548 * @param tunnelID the tunnel iD
549 * @return the match builder
551 public static MatchBuilder createDmacTcpSynMatch(MatchBuilder matchBuilder,
552 String attachedMac, PortNumber tcpPort, Integer tcpFlag, String tunnelID) {
554 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
555 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
556 ethTypeBuilder.setType(new EtherType(0x0800L));
557 ethernetMatch.setEthernetType(ethTypeBuilder.build());
559 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
560 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
561 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
562 matchBuilder.setEthernetMatch(ethernetMatch.build());
564 // TCP Protocol Match
565 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
566 ipMatch.setIpProtocol((short) 6);
567 matchBuilder.setIpMatch(ipMatch.build());
570 PortNumber dstPort = new PortNumber(tcpPort);
571 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
572 tcpMatch.setTcpDestinationPort(dstPort);
573 matchBuilder.setLayer4Match(tcpMatch.build());
575 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
576 tcpFlagMatch.setTcpFlag(tcpFlag);
577 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
579 TunnelBuilder tunnelBuilder = new TunnelBuilder();
580 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
581 matchBuilder.setTunnel(tunnelBuilder.build());
587 * Create dmac tcp syn dst ip prefix tcp port.
589 * @param matchBuilder the match builder
590 * @param attachedMac the attached mac
591 * @param tcpPort the tcp port
592 * @param tcpFlag the tcp flag
593 * @param segmentationId the segmentation id
594 * @param dstIp the dst ip
595 * @return the match builder
597 public static MatchBuilder createDmacTcpSynDstIpPrefixTcpPort(MatchBuilder matchBuilder,
598 MacAddress attachedMac, PortNumber tcpPort, Integer tcpFlag, String segmentationId,
601 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
602 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
603 ethTypeBuilder.setType(new EtherType(0x0800L));
604 ethernetMatch.setEthernetType(ethTypeBuilder.build());
606 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
607 ethDestinationBuilder.setAddress(new MacAddress(attachedMac));
608 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
610 matchBuilder.setEthernetMatch(ethernetMatch.build());
612 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
613 ipv4match.setIpv4Destination(dstIp);
614 matchBuilder.setLayer3Match(ipv4match.build());
616 // TCP Protocol Match
617 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
618 ipMatch.setIpProtocol(TCP_SHORT);
619 matchBuilder.setIpMatch(ipMatch.build());
622 PortNumber dstPort = new PortNumber(tcpPort);
623 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
624 tcpMatch.setTcpDestinationPort(dstPort);
625 matchBuilder.setLayer4Match(tcpMatch.build());
627 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
628 tcpFlagMatch.setTcpFlag(tcpFlag);
629 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
631 TunnelBuilder tunnelBuilder = new TunnelBuilder();
632 tunnelBuilder.setTunnelId(new BigInteger(segmentationId));
633 matchBuilder.setTunnel(tunnelBuilder.build());
639 * Create dmac ip tcp syn match.
641 * @param matchBuilder the match builder
642 * @param dMacAddr the d mac addr
643 * @param mask the mask
644 * @param ipPrefix the ip prefix
645 * @return MatchBuilder containing the metadata match values
647 public static MatchBuilder createDmacIpTcpSynMatch(MatchBuilder matchBuilder,
648 MacAddress dMacAddr, MacAddress mask, Ipv4Prefix ipPrefix) {
650 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
651 EthernetDestinationBuilder ethDestBuilder = new EthernetDestinationBuilder();
652 ethDestBuilder.setAddress(new MacAddress(dMacAddr));
654 ethDestBuilder.setMask(mask);
656 ethernetMatch.setEthernetDestination(ethDestBuilder.build());
657 matchBuilder.setEthernetMatch(ethernetMatch.build());
659 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
660 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
661 ethTypeBuilder.setType(new EtherType(0x0800L));
662 ethernetType.setEthernetType(ethTypeBuilder.build());
663 matchBuilder.setEthernetMatch(ethernetType.build());
664 if (ipPrefix != null) {
665 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
666 ipv4match.setIpv4Destination(ipPrefix);
667 matchBuilder.setLayer3Match(ipv4match.build());
669 // TCP Protocol Match
670 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
671 ipMatch.setIpProtocol(TCP_SHORT);
672 matchBuilder.setIpMatch(ipMatch.build());
674 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
675 tcpFlagMatch.setTcpFlag(TCP_SYN);
676 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
682 * Create smac tcp syn dst ip prefix tcp port.
684 * @param matchBuilder the match builder
685 * @param attachedMac the attached mac
686 * @param tcpPort the tcp port
687 * @param tcpFlag the tcp flag
688 * @param segmentationId the segmentation id
689 * @param dstIp the dst ip
690 * @return the match builder
692 public static MatchBuilder createSmacTcpSynDstIpPrefixTcpPort(MatchBuilder matchBuilder, MacAddress attachedMac,
693 PortNumber tcpPort, Integer tcpFlag, String segmentationId, Ipv4Prefix dstIp) {
695 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
696 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
697 ethTypeBuilder.setType(new EtherType(0x0800L));
698 ethernetMatch.setEthernetType(ethTypeBuilder.build());
700 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
701 ethSourceBuilder.setAddress(new MacAddress(attachedMac));
702 ethernetMatch.setEthernetSource(ethSourceBuilder.build());
704 matchBuilder.setEthernetMatch(ethernetMatch.build());
706 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
707 ipv4match.setIpv4Destination(dstIp);
708 matchBuilder.setLayer3Match(ipv4match.build());
710 // TCP Protocol Match
711 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
712 ipMatch.setIpProtocol(TCP_SHORT);
713 matchBuilder.setIpMatch(ipMatch.build());
716 PortNumber dstPort = new PortNumber(tcpPort);
717 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
718 tcpMatch.setTcpDestinationPort(dstPort);
719 matchBuilder.setLayer4Match(tcpMatch.build());
721 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
722 tcpFlagMatch.setTcpFlag(tcpFlag);
723 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
725 TunnelBuilder tunnelBuilder = new TunnelBuilder();
726 tunnelBuilder.setTunnelId(new BigInteger(segmentationId));
727 matchBuilder.setTunnel(tunnelBuilder.build());
733 * Create smac tcp port with flag match.
735 * @param matchBuilder the match builder
736 * @param attachedMac the attached mac
737 * @param tcpFlag the tcp flag
738 * @param tunnelID the tunnel iD
739 * @return matchBuilder
741 public static MatchBuilder createSmacTcpPortWithFlagMatch(MatchBuilder matchBuilder, String attachedMac,
742 Integer tcpFlag, String tunnelID) {
744 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
745 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
746 ethTypeBuilder.setType(new EtherType(0x0800L));
747 ethernetMatch.setEthernetType(ethTypeBuilder.build());
749 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
750 ethSrcBuilder.setAddress(new MacAddress(attachedMac));
751 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
752 matchBuilder.setEthernetMatch(ethernetMatch.build());
754 // TCP Protocol Match
755 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
756 ipMatch.setIpProtocol(TCP_SHORT);
757 matchBuilder.setIpMatch(ipMatch.build());
759 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
760 tcpFlagMatch.setTcpFlag(tcpFlag);
761 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
763 TunnelBuilder tunnelBuilder = new TunnelBuilder();
764 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
765 matchBuilder.setTunnel(tunnelBuilder.build());
771 * Create smac ip tcp syn match.
773 * @param matchBuilder the match builder
774 * @param dMacAddr the d mac addr
775 * @param mask the mask
776 * @param ipPrefix the ip prefix
777 * @return MatchBuilder containing the metadata match values
779 public static MatchBuilder createSmacIpTcpSynMatch(MatchBuilder matchBuilder, MacAddress dMacAddr,
780 MacAddress mask, Ipv4Prefix ipPrefix) {
782 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
783 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
784 ethSrcBuilder.setAddress(new MacAddress(dMacAddr));
786 ethSrcBuilder.setMask(mask);
788 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
789 matchBuilder.setEthernetMatch(ethernetMatch.build());
791 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
792 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
793 ethTypeBuilder.setType(new EtherType(0x0800L));
794 ethernetType.setEthernetType(ethTypeBuilder.build());
795 matchBuilder.setEthernetMatch(ethernetType.build());
796 if (ipPrefix != null) {
797 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
798 ipv4match.setIpv4Destination(ipPrefix);
799 matchBuilder.setLayer3Match(ipv4match.build());
801 // TCP Protocol Match
802 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
803 ipMatch.setIpProtocol(TCP_SHORT);
804 matchBuilder.setIpMatch(ipMatch.build());
806 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
807 tcpFlagMatch.setTcpFlag(TCP_SYN);
808 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
814 * Create smac tcp syn.
816 * @param matchBuilder the match builder
817 * @param attachedMac the attached mac
818 * @param tcpPort the tcp port
819 * @param tcpFlag the tcp flag
820 * @param tunnelID the tunnel iD
821 * @return the match builder
823 public static MatchBuilder createSmacTcpSyn(MatchBuilder matchBuilder,
824 String attachedMac, PortNumber tcpPort, Integer tcpFlag, String tunnelID) {
826 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
827 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
828 ethTypeBuilder.setType(new EtherType(0x0800L));
829 ethernetMatch.setEthernetType(ethTypeBuilder.build());
831 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
832 ethSrcBuilder.setAddress(new MacAddress(attachedMac));
833 ethernetMatch.setEthernetSource(ethSrcBuilder.build());
834 matchBuilder.setEthernetMatch(ethernetMatch.build());
836 // TCP Protocol Match
837 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
838 ipMatch.setIpProtocol((short) 6);
839 matchBuilder.setIpMatch(ipMatch.build());
842 PortNumber dstPort = new PortNumber(tcpPort);
843 TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
844 tcpMatch.setTcpDestinationPort(dstPort);
845 matchBuilder.setLayer4Match(tcpMatch.build());
848 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
849 tcpFlagMatch.setTcpFlag(tcpFlag);
850 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
852 TunnelBuilder tunnelBuilder = new TunnelBuilder();
853 tunnelBuilder.setTunnelId(new BigInteger(tunnelID));
854 matchBuilder.setTunnel(tunnelBuilder.build());
860 * @return MatchBuilder containing the metadata match values
862 public static MatchBuilder createMacSrcIpTcpSynMatch(MatchBuilder matchBuilder,
863 MacAddress dMacAddr, MacAddress mask, Ipv4Prefix ipPrefix) {
865 EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
866 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
867 ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
869 ethDestinationBuilder.setMask(mask);
871 ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
872 matchBuilder.setEthernetMatch(ethernetMatch.build());
874 EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
875 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
876 ethTypeBuilder.setType(new EtherType(0x0800L));
877 ethernetType.setEthernetType(ethTypeBuilder.build());
878 matchBuilder.setEthernetMatch(ethernetType.build());
879 if (ipPrefix != null) {
880 Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
881 ipv4match.setIpv4Source(ipPrefix);
882 matchBuilder.setLayer3Match(ipv4match.build());
884 // TCP Protocol Match
885 IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
886 ipMatch.setIpProtocol(TCP_SHORT);
887 matchBuilder.setIpMatch(ipMatch.build());
889 TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
890 tcpFlagMatch.setTcpFlag(TCP_SYN);
891 matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
896 public static class RegMatch {
897 final Class<? extends NxmNxReg> reg;
899 public RegMatch(Class<? extends NxmNxReg> reg, Long value) {
904 public static RegMatch of(Class<? extends NxmNxReg> reg, Long value) {
905 return new RegMatch(reg, value);
909 public static void addNxRegMatch(MatchBuilder match,
910 RegMatch... matches) {
911 ArrayList<ExtensionList> extensions = new ArrayList<>();
912 for (RegMatch rm : matches) {
913 Class<? extends ExtensionKey> key;
914 if (NxmNxReg0.class.equals(rm.reg)) {
915 key = NxmNxReg0Key.class;
916 } else if (NxmNxReg1.class.equals(rm.reg)) {
917 key = NxmNxReg1Key.class;
918 } else if (NxmNxReg2.class.equals(rm.reg)) {
919 key = NxmNxReg2Key.class;
920 } else if (NxmNxReg3.class.equals(rm.reg)) {
921 key = NxmNxReg3Key.class;
922 } else if (NxmNxReg4.class.equals(rm.reg)) {
923 key = NxmNxReg4Key.class;
924 } else if (NxmNxReg5.class.equals(rm.reg)) {
925 key = NxmNxReg5Key.class;
926 } else if (NxmNxReg6.class.equals(rm.reg)) {
927 key = NxmNxReg6Key.class;
929 key = NxmNxReg7Key.class;
931 NxAugMatchNodesNodeTableFlow am =
932 new NxAugMatchNodesNodeTableFlowBuilder()
933 .setNxmNxReg(new NxmNxRegBuilder()
938 extensions.add(new ExtensionListBuilder()
939 .setExtensionKey(key)
940 .setExtension(new ExtensionBuilder()
941 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
945 GeneralAugMatchNodesNodeTableFlow m =
946 new GeneralAugMatchNodesNodeTableFlowBuilder()
947 .setExtensionList(extensions)
949 match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
952 public static void addNxTunIdMatch(MatchBuilder match,
954 NxAugMatchNodesNodeTableFlow am =
955 new NxAugMatchNodesNodeTableFlowBuilder()
956 .setNxmNxTunId(new NxmNxTunIdBuilder()
957 .setValue(BigInteger.valueOf(tunId))
960 GeneralAugMatchNodesNodeTableFlow m =
961 new GeneralAugMatchNodesNodeTableFlowBuilder()
962 .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
963 .setExtensionKey(NxmNxTunIdKey.class)
964 .setExtension(new ExtensionBuilder()
965 .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
969 match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
972 public static void addNxNsp(MatchBuilder match, long nsp) {
973 org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow am =
974 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder()
975 .setNxmNxNsp(new NxmNxNspBuilder()
979 addExtension(match, NxmNxNspKey.class, am);
982 public static void addNxNsi(MatchBuilder match, short nsi) {
983 org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow am =
984 new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder()
985 .setNxmNxNsi(new NxmNxNsiBuilder()
989 addExtension(match, NxmNxNsiKey.class, am);
992 private static void addExtension (MatchBuilder match, Class<? extends ExtensionKey> extensionKey, org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow am) {
993 GeneralAugMatchNodesNodeTableFlow existingAugmentations = match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
994 List<ExtensionList> extensions = null;
995 if (existingAugmentations != null ) {
996 extensions = existingAugmentations.getExtensionList();
998 if (extensions == null) {
999 extensions = Lists.newArrayList();
1002 extensions.add(new ExtensionListBuilder()
1003 .setExtensionKey(extensionKey)
1004 .setExtension(new ExtensionBuilder()
1005 .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow.class, am)
1009 GeneralAugMatchNodesNodeTableFlow m = new GeneralAugMatchNodesNodeTableFlowBuilder()
1010 .setExtensionList(extensions)
1012 match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
1015 public static EthernetMatch ethernetMatch(MacAddress srcMac,
1018 EthernetMatchBuilder emb = new EthernetMatchBuilder();
1020 emb.setEthernetSource(new EthernetSourceBuilder()
1024 emb.setEthernetDestination(new EthernetDestinationBuilder()
1027 if (etherType != null)
1028 emb.setEthernetType(new EthernetTypeBuilder()
1029 .setType(new EtherType(etherType))
1035 * Create ipv4 prefix from ipv4 address, by appending /32 mask
1037 * @param ipv4AddressString the ip address, in string format
1038 * @return Ipv4Prefix with ipv4Address and /32 mask
1040 public static Ipv4Prefix iPv4PrefixFromIPv4Address(String ipv4AddressString) {
1041 return new Ipv4Prefix(ipv4AddressString + "/32");
1045 * Return Long that represents OF port for strings where OF is explicitly provided
1047 * @param ofPortIdentifier the string with encoded OF port (example format "OFPort|999")
1048 * @return the OFport or null
1050 public static Long parseExplicitOFPort(String ofPortIdentifier) {
1051 if (ofPortIdentifier != null) {
1052 String[] pair = ofPortIdentifier.split("\\|");
1053 if ((pair.length > 1) && (pair[0].equalsIgnoreCase("OFPort"))) {
1054 return new Long(pair[1]);