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