Utility method in net-virt-providers to set a NSP match.
[ovsdb.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / providers / mdsalopenflow13 / OF13MdSalMatch.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  */
9
10 package org.opendaylight.ovsdb.openstack.netvirt.providers.mdsalopenflow13;
11
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14
15 import org.opendaylight.ovsdb.openstack.netvirt.providers.OF13Provider;
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.TcpFlagMatchBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg2;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg0Key;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg1Key;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg2Key;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg3Key;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg4Key;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg5Key;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg6Key;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxReg7Key;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.reg.grouping.NxmNxRegBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.match.rev140714.NxmNxNspKey;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68 import com.google.common.collect.ImmutableList;
69
70 public class OF13MdSalMatch extends OF13Provider {
71     private static final Logger logger = LoggerFactory.getLogger(OF13MdSalMatch.class);
72
73     /**
74      * Create Ingress Port Match dpidLong, inPort
75      *
76      * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
77      * @param dpidLong     Long the datapath ID of a switch/node
78      * @param inPort       Long ingress port on a switch
79      * @return matchBuilder Map MatchBuilder Object with a match
80      */
81     public static MatchBuilder createInPortMatch(MatchBuilder matchBuilder, Long dpidLong, Long inPort) {
82
83         NodeConnectorId ncid = new NodeConnectorId("openflow:" + dpidLong + ":" + inPort);
84         logger.debug("createInPortMatch() Node Connector ID is - Type=openflow: DPID={} inPort={} ", dpidLong, inPort);
85         matchBuilder.setInPort(NodeConnectorId.getDefaultInstance(ncid.getValue()));
86         matchBuilder.setInPort(ncid);
87
88         return matchBuilder;
89     }
90
91     /**
92      * Create EtherType Match
93      *
94      * @param matchBuilder Map matchBuilder MatchBuilder Object without a match
95      * @param etherType    Long EtherType
96      * @return matchBuilder Map MatchBuilder Object with a match
97      */
98     public static MatchBuilder createEtherTypeMatch(MatchBuilder matchBuilder, EtherType etherType) {
99
100         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
101         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
102         ethTypeBuilder.setType(new EtherType(etherType));
103         ethernetMatch.setEthernetType(ethTypeBuilder.build());
104         matchBuilder.setEthernetMatch(ethernetMatch.build());
105
106         return matchBuilder;
107     }
108
109     /**
110      * Create Ethernet Source Match
111      *
112      * @param matchBuilder MatchBuilder Object without a match yet
113      * @param sMacAddr     String representing a source MAC
114      * @return matchBuilder Map MatchBuilder Object with a match
115      */
116     public static MatchBuilder createEthSrcMatch(MatchBuilder matchBuilder, MacAddress sMacAddr) {
117
118         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
119         EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
120         ethSourceBuilder.setAddress(new MacAddress(sMacAddr));
121         ethernetMatch.setEthernetSource(ethSourceBuilder.build());
122         matchBuilder.setEthernetMatch(ethernetMatch.build());
123
124         return matchBuilder;
125     }
126
127     /**
128      * Create Ethernet Destination Match
129      *
130      * @param matchBuilder MatchBuilder Object without a match yet
131      * @param vlanId       Integer representing a VLAN ID Integer representing a VLAN ID
132      * @return matchBuilder Map MatchBuilder Object with a match
133      */
134     public static MatchBuilder createVlanIdMatch(MatchBuilder matchBuilder, VlanId vlanId) {
135         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
136         VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
137         vlanIdBuilder.setVlanId(new VlanId(vlanId));
138         vlanIdBuilder.setVlanIdPresent(true);
139         vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
140         matchBuilder.setVlanMatch(vlanMatchBuilder.build());
141
142         return matchBuilder;
143     }
144
145     /**
146      * Create Ethernet Destination Match
147      *
148      * @param matchBuilder MatchBuilder Object without a match yet
149      * @param dMacAddr     String representing a destination MAC
150      * @return matchBuilder Map MatchBuilder Object with a match
151      */
152     public static MatchBuilder createDestEthMatch(MatchBuilder matchBuilder, MacAddress dMacAddr, MacAddress mask) {
153
154         EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
155         EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
156         ethDestinationBuilder.setAddress(new MacAddress(dMacAddr));
157         if (mask != null) {
158             ethDestinationBuilder.setMask(mask);
159         }
160         ethernetMatch.setEthernetDestination(ethDestinationBuilder.build());
161         matchBuilder.setEthernetMatch(ethernetMatch.build());
162
163         return matchBuilder;
164     }
165
166     /**
167      * Tunnel ID Match Builder
168      *
169      * @param matchBuilder MatchBuilder Object without a match yet
170      * @param tunnelId     BigInteger representing a tunnel ID
171      * @return matchBuilder Map MatchBuilder Object with a match
172      */
173     public static MatchBuilder createTunnelIDMatch(MatchBuilder matchBuilder, BigInteger tunnelId) {
174
175         TunnelBuilder tunnelBuilder = new TunnelBuilder();
176         tunnelBuilder.setTunnelId(tunnelId);
177         matchBuilder.setTunnel(tunnelBuilder.build());
178
179         return matchBuilder;
180     }
181
182     /**
183      * Match ICMP code and type
184      *
185      * @param matchBuilder MatchBuilder Object without a match yet
186      * @param type         short representing an ICMP type
187      * @param code         short representing an ICMP code
188      * @return matchBuilder Map MatchBuilder Object with a match
189      */
190     public static MatchBuilder createICMPv4Match(MatchBuilder matchBuilder, short type, short code) {
191
192         EthernetMatchBuilder eth = new EthernetMatchBuilder();
193         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
194         ethTypeBuilder.setType(new EtherType(0x0800L));
195         eth.setEthernetType(ethTypeBuilder.build());
196         matchBuilder.setEthernetMatch(eth.build());
197
198         // Build the IPv4 Match requied per OVS Syntax
199         IpMatchBuilder ipmatch = new IpMatchBuilder();
200         ipmatch.setIpProtocol((short) 1);
201         matchBuilder.setIpMatch(ipmatch.build());
202
203         // Build the ICMPv4 Match
204         Icmpv4MatchBuilder icmpv4match = new Icmpv4MatchBuilder();
205         icmpv4match.setIcmpv4Type(type);
206         icmpv4match.setIcmpv4Code(code);
207         matchBuilder.setIcmpv4Match(icmpv4match.build());
208
209         return matchBuilder;
210     }
211
212     /**
213      * @param matchBuilder MatchBuilder Object without a match yet
214      * @param dstip        String containing an IPv4 prefix
215      * @return matchBuilder Map Object with a match
216      */
217     public static MatchBuilder createDstL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix dstip) {
218
219         EthernetMatchBuilder eth = new EthernetMatchBuilder();
220         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
221         ethTypeBuilder.setType(new EtherType(0x0800L));
222         eth.setEthernetType(ethTypeBuilder.build());
223         matchBuilder.setEthernetMatch(eth.build());
224
225         Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
226         ipv4match.setIpv4Destination(dstip);
227
228         matchBuilder.setLayer3Match(ipv4match.build());
229
230         return matchBuilder;
231
232     }
233
234     /**
235      * @param matchBuilder MatchBuilder Object without a match yet
236      * @param srcip        String containing an IPv4 prefix
237      * @return matchBuilder Map Object with a match
238      */
239     public static MatchBuilder createSrcL3IPv4Match(MatchBuilder matchBuilder, Ipv4Prefix srcip) {
240
241         EthernetMatchBuilder eth = new EthernetMatchBuilder();
242         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
243         ethTypeBuilder.setType(new EtherType(0x0800L));
244         eth.setEthernetType(ethTypeBuilder.build());
245         matchBuilder.setEthernetMatch(eth.build());
246
247         Ipv4MatchBuilder ipv4match = new Ipv4MatchBuilder();
248         ipv4match.setIpv4Source(srcip);
249         matchBuilder.setLayer3Match(ipv4match.build());
250
251         return matchBuilder;
252
253     }
254
255     /**
256      * Create Source TCP Port Match
257      *
258      * @param matchBuilder @param matchbuilder MatchBuilder Object without a match yet
259      * @param tcpport      Integer representing a source TCP port
260      * @return matchBuilder Map MatchBuilder Object with a match
261      */
262     public static MatchBuilder createSetSrcTcpMatch(MatchBuilder matchBuilder, PortNumber tcpport) {
263
264         EthernetMatchBuilder ethType = new EthernetMatchBuilder();
265         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
266         ethTypeBuilder.setType(new EtherType(0x0800L));
267         ethType.setEthernetType(ethTypeBuilder.build());
268         matchBuilder.setEthernetMatch(ethType.build());
269
270         IpMatchBuilder ipmatch = new IpMatchBuilder();
271         ipmatch.setIpProtocol((short) 6);
272         matchBuilder.setIpMatch(ipmatch.build());
273
274         TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
275         tcpmatch.setTcpSourcePort(tcpport);
276         matchBuilder.setLayer4Match(tcpmatch.build());
277
278         return matchBuilder;
279
280     }
281
282     /**
283      * Create Destination TCP Port Match
284      *
285      * @param matchBuilder MatchBuilder Object without a match yet
286      * @param tcpDstPort   Integer representing a destination TCP port
287      * @return matchBuilder Map MatchBuilder Object with a match
288      */
289     public static MatchBuilder createSetDstTcpMatch(MatchBuilder matchBuilder, PortNumber tcpDstPort) {
290
291         EthernetMatchBuilder ethType = new EthernetMatchBuilder();
292         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
293         ethTypeBuilder.setType(new EtherType(0x0800L));
294         ethType.setEthernetType(ethTypeBuilder.build());
295         matchBuilder.setEthernetMatch(ethType.build());
296
297         IpMatchBuilder ipmatch = new IpMatchBuilder();
298         ipmatch.setIpProtocol((short) 6);
299         matchBuilder.setIpMatch(ipmatch.build());
300
301         TcpMatchBuilder tcpmatch = new TcpMatchBuilder();
302         tcpmatch.setTcpDestinationPort(tcpDstPort);
303         matchBuilder.setLayer4Match(tcpmatch.build());
304
305         return matchBuilder;
306     }
307
308     /**
309      * Test match for TCP_Flags
310      *
311      * @return match containing TCP_Flag (), IP Protocol (TCP), TCP_Flag (SYN)
312      * <p/>
313      * Defined TCP Flag values in OVS v2.1+
314      * TCP_FIN 0x001 / TCP_SYN 0x002 / TCP_RST 0x004
315      * TCP_PSH 0x008 / TCP_ACK 0x010 / TCP_URG 0x020
316      * TCP_ECE 0x040 / TCP_CWR 0x080 / TCP_NS  0x100
317      */
318     public static MatchBuilder createTcpFlagMatch(MatchBuilder matchBuilder, int tcpFlag) {
319
320         // Ethertype match
321         EthernetMatchBuilder ethernetType = new EthernetMatchBuilder();
322         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
323         ethTypeBuilder.setType(new EtherType(0x0800L));
324         ethernetType.setEthernetType(ethTypeBuilder.build());
325         matchBuilder.setEthernetMatch(ethernetType.build());
326
327         // TCP Protocol Match
328         IpMatchBuilder ipMatch = new IpMatchBuilder(); // ipv4 version
329         ipMatch.setIpProtocol((short) 6);
330         matchBuilder.setIpMatch(ipMatch.build());
331
332         // TCP Port Match
333         PortNumber dstPort = new PortNumber(80);
334         TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
335         tcpMatch.setTcpDestinationPort(dstPort);
336         matchBuilder.setLayer4Match(tcpMatch.build());
337
338         TcpFlagMatchBuilder tcpFlagMatch = new TcpFlagMatchBuilder();
339         tcpFlagMatch.setTcpFlag(0x002);
340         matchBuilder.setTcpFlagMatch(tcpFlagMatch.build());
341         return matchBuilder;
342     }
343
344
345     public static class RegMatch {
346         final Class<? extends NxmNxReg> reg;
347         final Long value;
348         public RegMatch(Class<? extends NxmNxReg> reg, Long value) {
349             super();
350             this.reg = reg;
351             this.value = value;
352         }
353         public static RegMatch of(Class<? extends NxmNxReg> reg, Long value) {
354             return new RegMatch(reg, value);
355         }
356     }
357
358     public static void addNxRegMatch(MatchBuilder match,
359                                      RegMatch... matches) {
360         ArrayList<ExtensionList> extensions = new ArrayList<>();
361         for (RegMatch rm : matches) {
362             Class<? extends ExtensionKey> key;
363             if (NxmNxReg0.class.equals(rm.reg)) {
364                 key = NxmNxReg0Key.class;
365             } else if (NxmNxReg1.class.equals(rm.reg)) {
366                 key = NxmNxReg1Key.class;
367             } else if (NxmNxReg2.class.equals(rm.reg)) {
368                 key = NxmNxReg2Key.class;
369             } else if (NxmNxReg3.class.equals(rm.reg)) {
370                 key = NxmNxReg3Key.class;
371             } else if (NxmNxReg4.class.equals(rm.reg)) {
372                 key = NxmNxReg4Key.class;
373             } else if (NxmNxReg5.class.equals(rm.reg)) {
374                 key = NxmNxReg5Key.class;
375             } else if (NxmNxReg6.class.equals(rm.reg)) {
376                 key = NxmNxReg6Key.class;
377             } else {
378                 key = NxmNxReg7Key.class;
379             }
380             NxAugMatchNodesNodeTableFlow am =
381                     new NxAugMatchNodesNodeTableFlowBuilder()
382                 .setNxmNxReg(new NxmNxRegBuilder()
383                     .setReg(rm.reg)
384                     .setValue(rm.value)
385                     .build())
386                 .build();
387             extensions.add(new ExtensionListBuilder()
388                 .setExtensionKey(key)
389                 .setExtension(new ExtensionBuilder()
390                      .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
391                      .build())
392                 .build());
393         }
394         GeneralAugMatchNodesNodeTableFlow m =
395                 new GeneralAugMatchNodesNodeTableFlowBuilder()
396             .setExtensionList(extensions)
397             .build();
398         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
399     }
400
401     public static void addNxTunIdMatch(MatchBuilder match,
402                                        int tunId) {
403         NxAugMatchNodesNodeTableFlow am =
404                new NxAugMatchNodesNodeTableFlowBuilder()
405                    .setNxmNxTunId(new NxmNxTunIdBuilder()
406                        .setValue(BigInteger.valueOf(tunId))
407                        .build())
408                    .build();
409         GeneralAugMatchNodesNodeTableFlow m =
410                 new GeneralAugMatchNodesNodeTableFlowBuilder()
411             .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
412                 .setExtensionKey(NxmNxTunIdKey.class)
413                 .setExtension(new ExtensionBuilder()
414                     .addAugmentation(NxAugMatchNodesNodeTableFlow.class, am)
415                     .build())
416                 .build()))
417             .build();
418         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
419     }
420
421     public static void addNxNsp(MatchBuilder match, long nsp) {
422         org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.match.rev140714.NxAugMatchNodesNodeTableFlow am =
423                 new org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder()
424                 .setNxmNxNsp(new NxmNxNspBuilder()
425                 .setValue(nsp)
426                 .build())
427                 .build();
428
429         GeneralAugMatchNodesNodeTableFlow m =
430                 new GeneralAugMatchNodesNodeTableFlowBuilder()
431                 .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
432                 .setExtensionKey(NxmNxNspKey.class)
433                 .setExtension(new ExtensionBuilder()
434                 .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.sal.match.rev140714.NxAugMatchNodesNodeTableFlow.class, am)
435                 .build())
436                 .build()))
437                 .build();
438         match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, m);
439     }
440
441     public static EthernetMatch ethernetMatch(MacAddress srcMac,
442                                               MacAddress dstMac,
443                                               Long etherType) {
444         EthernetMatchBuilder emb = new  EthernetMatchBuilder();
445         if (srcMac != null)
446             emb.setEthernetSource(new EthernetSourceBuilder()
447                 .setAddress(srcMac)
448                 .build());
449         if (dstMac != null)
450             emb.setEthernetDestination(new EthernetDestinationBuilder()
451                 .setAddress(dstMac)
452                 .build());
453         if (etherType != null)
454             emb.setEthernetType(new EthernetTypeBuilder()
455                 .setType(new EtherType(etherType))
456                 .build());
457         return emb.build();
458     }
459 }