Fixed ICMPv6 Code augmentation key.
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / MatchConvertor.java
1 /**
2  * Copyright (c) 2013 Ericsson. and others.  All rights reserved.
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 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
10
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetField;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
142 import org.slf4j.Logger;
143 import org.slf4j.LoggerFactory;
144
145 /**
146  * Utility class for converting a MD-SAL Flow into the OF flow mod
147  */
148 public class MatchConvertor {
149     private static final Logger logger = LoggerFactory.getLogger(MatchConvertor.class);
150     private static final String PREFIX_SEPARATOR = "/";
151
152     public static List<MatchEntries> toMatch(
153             org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
154
155         List<MatchEntries> matchEntriesList = new ArrayList<>();
156
157         if (match.getInPort() != null) {
158             matchEntriesList.add(toOfPort(InPort.class, match.getInPort()));
159         }
160
161         if (match.getInPhyPort() != null) {
162             matchEntriesList.add(toOfPort(InPhyPort.class, match.getInPhyPort()));
163         }
164
165         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
166                 .getMetadata();
167         if (metadata != null) {
168             matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
169         }
170
171         EthernetMatch ethernetMatch = match.getEthernetMatch();
172         if (ethernetMatch != null) {
173             EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
174             if (ethernetDestination != null) {
175                 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
176                         ethernetDestination.getMask()));
177             }
178
179             EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
180             if (ethernetSource != null) {
181                 matchEntriesList
182                         .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
183             }
184
185             if (ethernetMatch.getEthernetType() != null) {
186                 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
187             }
188         }
189
190         VlanMatch vlanMatch = match.getVlanMatch();
191         if (vlanMatch != null) {
192             if (vlanMatch.getVlanId() != null) {
193                 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
194             }
195
196             if (vlanMatch.getVlanPcp() != null) {
197                 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
198             }
199         }
200
201         IpMatch ipMatch = match.getIpMatch();
202         if (ipMatch != null) {
203             if (ipMatch.getIpDscp() != null) {
204                 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
205             }
206
207             if (ipMatch.getIpEcn() != null) {
208                 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
209             }
210
211             if (ipMatch.getIpProtocol() != null) {
212                 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
213             }
214
215         }
216
217         Layer4Match layer4Match = match.getLayer4Match();
218         if (layer4Match != null) {
219             if (layer4Match instanceof TcpMatch) {
220                 TcpMatch tcpMatch = (TcpMatch) layer4Match;
221                 if (tcpMatch.getTcpSourcePort() != null) {
222                     matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
223                 }
224
225                 if (tcpMatch.getTcpDestinationPort() != null) {
226                     matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
227                 }
228             } else if (layer4Match instanceof UdpMatch) {
229                 UdpMatch udpMatch = (UdpMatch) layer4Match;
230                 if (udpMatch.getUdpSourcePort() != null) {
231                     matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
232                 }
233
234                 if (udpMatch.getUdpDestinationPort() != null) {
235                     matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
236                 }
237             } else if (layer4Match instanceof SctpMatch) {
238                 SctpMatch sctpMatch = (SctpMatch) layer4Match;
239                 if (sctpMatch.getSctpSourcePort() != null) {
240                     matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
241                 }
242
243                 if (sctpMatch.getSctpDestinationPort() != null) {
244                     matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
245                 }
246             }
247         }
248
249         Icmpv4Match icmpv4Match = match.getIcmpv4Match();
250         if (icmpv4Match != null) {
251             if (icmpv4Match.getIcmpv4Type() != null) {
252                 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
253             }
254
255             if (icmpv4Match.getIcmpv4Code() != null) {
256                 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
257             }
258         }
259
260         Icmpv6Match icmpv6Match = match.getIcmpv6Match();
261         if (icmpv6Match != null) {
262             if (icmpv6Match.getIcmpv6Type() != null) {
263                 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
264             }
265
266             if (icmpv6Match.getIcmpv6Code() != null) {
267                 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
268             }
269         }
270
271         Layer3Match layer3Match = match.getLayer3Match();
272         if (layer3Match != null) {
273             if (layer3Match instanceof Ipv4Match) {
274                 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
275                 if (ipv4Match.getIpv4Source() != null) {
276                     matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
277                 }
278                 if (ipv4Match.getIpv4Destination() != null) {
279                     matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
280                 }
281             } else if (layer3Match instanceof ArpMatch) {
282                 ArpMatch arpMatch = (ArpMatch) layer3Match;
283                 if (arpMatch.getArpOp() != null) {
284                     matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
285                 }
286
287                 if (arpMatch.getArpSourceTransportAddress() != null) {
288                     matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
289                 }
290
291                 if (arpMatch.getArpTargetTransportAddress() != null) {
292                     matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
293                 }
294
295                 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
296                 if (arpSourceHardwareAddress != null) {
297                     matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
298                             arpSourceHardwareAddress.getMask()));
299                 }
300
301                 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
302                 if (arpTargetHardwareAddress != null) {
303                     matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
304                             arpTargetHardwareAddress.getMask()));
305                 }
306             }
307
308             else if (layer3Match instanceof Ipv6Match) {
309                 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
310                 if (ipv6Match.getIpv6Source() != null) {
311                     matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
312                 }
313
314                 if (ipv6Match.getIpv6Destination() != null) {
315                     matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
316                 }
317
318                 if (ipv6Match.getIpv6Label() != null) {
319                     matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
320                 }
321
322                 if (ipv6Match.getIpv6NdTarget() != null) {
323                     matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
324                 }
325
326                 if (ipv6Match.getIpv6NdSll() != null) {
327                     matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
328                 }
329
330                 if (ipv6Match.getIpv6NdTll() != null) {
331                     matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
332                 }
333
334                 if (ipv6Match.getIpv6ExtHeader() != null) {
335                     matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
336                 }
337             }
338         }
339
340         ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
341         if (protocolMatchFields != null) {
342             if (protocolMatchFields.getMplsLabel() != null) {
343                 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
344             }
345
346             if (protocolMatchFields.getMplsBos() != null) {
347                 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
348             }
349
350             if (protocolMatchFields.getMplsTc() != null) {
351                 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
352             }
353
354             if (protocolMatchFields.getPbb() != null) {
355                 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
356             }
357         }
358
359         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
360                 .getTunnel();
361         if (tunnel != null) {
362             matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
363         }
364
365         return matchEntriesList;
366     }
367
368     private static MatchEntries toOfMplsPbb(Pbb pbb) {
369         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
370         boolean hasmask = false;
371         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
372         matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
373         IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
374         isidBuilder.setIsid(pbb.getPbbIsid());
375         matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
376         if (pbb.getPbbMask() != null) {
377             hasmask = true;
378             addMaskAugmentation(matchEntriesBuilder, pbb.getPbbMask());
379         }
380         matchEntriesBuilder.setHasMask(hasmask);
381         return matchEntriesBuilder.build();
382     }
383
384     private static MatchEntries toOfMplsTc(Short mplsTc) {
385         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
386         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
387         matchEntriesBuilder.setHasMask(false);
388         matchEntriesBuilder.setOxmMatchField(MplsTc.class);
389         TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
390         tcBuilder.setTc(mplsTc);
391         matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
392         return matchEntriesBuilder.build();
393     }
394
395     private static MatchEntries toOfMplsBos(Short mplsBos) {
396         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
397         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
398         matchEntriesBuilder.setHasMask(false);
399         matchEntriesBuilder.setOxmMatchField(MplsBos.class);
400         BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
401         if (mplsBos != 0) {
402             bosBuilder.setBos(true);
403         } else {
404             bosBuilder.setBos(false);
405         }
406         matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
407         return matchEntriesBuilder.build();
408     }
409
410     private static MatchEntries toOfMplsLabel(Long mplsLabel) {
411         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
412         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
413         matchEntriesBuilder.setHasMask(false);
414         matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
415         MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
416         mplsLabelBuilder.setMplsLabel(mplsLabel);
417         matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
418         return matchEntriesBuilder.build();
419     }
420
421     private static MatchEntries toOfIpv6ExtHeader(Ipv6ExtHeader ipv6ExtHeader) {
422         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
423         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
424         matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
425         PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
426         Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
427         final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
428         final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
429         final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
430         final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
431         final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
432         final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
433         final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
434         final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
435         final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
436         pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
437         matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
438         if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
439             addMaskAugmentation(matchEntriesBuilder, ipv6ExtHeader.getIpv6ExthdrMask());
440         }
441         matchEntriesBuilder.setHasMask(false);
442         return matchEntriesBuilder.build();
443     }
444
445     private static MatchEntries toOfIpv6FlowLabel(Ipv6Label ipv6Label) {
446         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
447         boolean hasmask = false;
448         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
449         matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
450         Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
451         ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
452         matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
453         if (ipv6Label.getFlabelMask() != null) {
454             hasmask = true;
455             addMaskAugmentation(matchEntriesBuilder, ipv6Label.getFlabelMask());
456         }
457         matchEntriesBuilder.setHasMask(hasmask);
458         return matchEntriesBuilder.build();
459     }
460
461     private static MatchEntries toOfPort(Class<? extends MatchField> field, Long portNumber) {
462         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
463         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
464         matchEntriesBuilder.setHasMask(false);
465         matchEntriesBuilder.setOxmMatchField(field);
466         PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
467         port.setPortNumber(new PortNumber(portNumber));
468         matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
469         return matchEntriesBuilder.build();
470     }
471
472     private static MatchEntries toOfMetadata(Class<? extends MatchField> field, BigInteger metadata, byte[] metadataMask) {
473         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
474         boolean hasmask = false;
475         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
476         matchEntriesBuilder.setOxmMatchField(field);
477         addMetadataAugmentation(matchEntriesBuilder, metadata);
478         if (metadataMask != null) {
479             hasmask = true;
480             addMaskAugmentation(matchEntriesBuilder, metadataMask);
481         }
482         matchEntriesBuilder.setHasMask(hasmask);
483         return matchEntriesBuilder.build();
484     }
485
486     private static MatchEntries toOfMacAddress(Class<? extends MatchField> field,
487             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
488             byte[] mask) {
489         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
490         boolean hasmask = false;
491         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
492         matchEntriesBuilder.setOxmMatchField(field);
493         addMacAddressAugmentation(matchEntriesBuilder, macAddress);
494         if (mask != null) {
495             hasmask = true;
496             addMaskAugmentation(matchEntriesBuilder, mask);
497         }
498         matchEntriesBuilder.setHasMask(hasmask);
499         return matchEntriesBuilder.build();
500     }
501
502     private static MatchEntries toOfEthernetType(EthernetType ethernetType) {
503         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
504         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
505         matchEntriesBuilder.setHasMask(false);
506         matchEntriesBuilder.setOxmMatchField(EthType.class);
507         EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
508         ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
509         matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
510         return matchEntriesBuilder.build();
511     }
512
513     private static MatchEntries toOfLayer3Port(Class<? extends MatchField> field,
514             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
515         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
516         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
517         matchEntriesBuilder.setHasMask(false);
518         matchEntriesBuilder.setOxmMatchField(field);
519         PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
520         portBuilder.setPort(portNumber);
521         matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
522         return matchEntriesBuilder.build();
523     }
524
525     private static MatchEntries toOfIcmpv4Type(Short icmpv4Type) {
526         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
527         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
528         matchEntriesBuilder.setHasMask(false);
529         matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
530         Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
531         icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
532         matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
533         return matchEntriesBuilder.build();
534     }
535
536     private static MatchEntries toOfIcmpv4Code(Short icmpv4Code) {
537         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
538         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
539         matchEntriesBuilder.setHasMask(false);
540         matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
541         Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
542         icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
543         matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
544         return matchEntriesBuilder.build();
545     }
546
547     private static MatchEntries toOfIcmpv6Type(Short icmpv6Type) {
548         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
549         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
550         matchEntriesBuilder.setHasMask(false);
551         matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
552         Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
553         icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
554         matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
555         return matchEntriesBuilder.build();
556     }
557
558     private static MatchEntries toOfIcmpv6Code(Short icmpv6Code) {
559         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
560         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
561         matchEntriesBuilder.setHasMask(false);
562         matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
563         Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
564         icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
565         matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
566         return matchEntriesBuilder.build();
567     }
568
569     private static MatchEntries toOfIpv4Prefix(Class<? extends MatchField> field, Ipv4Prefix ipv4Prefix) {
570         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
571         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
572         matchEntriesBuilder.setOxmMatchField(field);
573         boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
574         matchEntriesBuilder.setHasMask(hasMask);
575         return matchEntriesBuilder.build();
576     }
577
578     private static MatchEntries toOfIpv6Prefix(Class<? extends MatchField> field, Ipv6Prefix ipv6Prefix) {
579         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
580         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
581         matchEntriesBuilder.setOxmMatchField(field);
582         boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
583         matchEntriesBuilder.setHasMask(hasmask);
584         return matchEntriesBuilder.build();
585     }
586
587     private static MatchEntries toOfIpDscp(Dscp ipDscp) {
588         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
589         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
590         matchEntriesBuilder.setHasMask(false);
591         matchEntriesBuilder.setOxmMatchField(IpDscp.class);
592         DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
593         dscpBuilder.setDscp(ipDscp);
594         matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
595         return matchEntriesBuilder.build();
596     }
597
598     private static MatchEntries toOfVlanPcp(
599             org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
600         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
601         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
602         matchEntriesBuilder.setHasMask(false);
603         matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
604         VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
605         vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
606         matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
607         return matchEntriesBuilder.build();
608     }
609
610     private static MatchEntries toOfVlanVid(VlanId vlanId) {
611         // TODO: verify
612         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
613         boolean hasmask = false;
614         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
615         matchEntriesBuilder.setOxmMatchField(VlanVid.class);
616         VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
617         Integer vidEntryValue = vlanId.getVlanId().getValue();
618         vlanVidBuilder.setCfiBit(vidEntryValue != 0);
619         vlanVidBuilder.setVlanVid(vidEntryValue);
620         matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
621         if (vlanId.getMask() != null) {
622             hasmask = true;
623             addMaskAugmentation(matchEntriesBuilder, vlanId.getMask());
624         }
625         matchEntriesBuilder.setHasMask(hasmask);
626         return matchEntriesBuilder.build();
627     }
628
629     private static MatchEntries toOfIpProto(Short ipProtocol) {
630         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
631         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
632         matchEntriesBuilder.setHasMask(false);
633         matchEntriesBuilder.setOxmMatchField(IpProto.class);
634         ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
635         protoNumberBuilder.setProtocolNumber(ipProtocol);
636         matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
637         return matchEntriesBuilder.build();
638     }
639
640     private static MatchEntries toOfIpEcn(Short ipEcn) {
641         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
642         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
643         matchEntriesBuilder.setHasMask(false);
644         matchEntriesBuilder.setOxmMatchField(IpEcn.class);
645         EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
646         ecnBuilder.setEcn(ipEcn);
647         matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
648         return matchEntriesBuilder.build();
649     }
650
651     private static MatchEntries toOfArpOpCode(Integer arpOp) {
652         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
653         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
654         matchEntriesBuilder.setHasMask(false);
655         matchEntriesBuilder.setOxmMatchField(ArpOp.class);
656         OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
657         opcodeBuilder.setOpCode(arpOp);
658         matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
659         return matchEntriesBuilder.build();
660     }
661
662     private static MatchEntries toOfIpv6Address(Ipv6Address address) {
663         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
664         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
665         matchEntriesBuilder.setHasMask(false);
666         matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
667         Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
668         ipv6AddressBuilder.setIpv6Address(address);
669         matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
670         return matchEntriesBuilder.build();
671     }
672
673     private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
674         MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
675         maskBuilder.setMask(mask);
676         builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
677     }
678
679     private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
680         boolean hasMask = false;
681         String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
682         Integer prefix = null;
683         if (addressParts.length == 2) {
684             prefix = Integer.parseInt(addressParts[1]);
685         }
686
687         Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
688         Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
689         ipv6AddressBuilder.setIpv6Address(ipv6Address);
690         builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
691         if (prefix != null) {
692             hasMask = true;
693             addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
694         }
695         return hasMask;
696     }
697
698     private static byte[] convertIpv6PrefixToByteArray(int prefix) {
699         // TODO: Temporary fix. Has performance impacts.
700         byte[] mask = new byte[16];
701         int oneCount = prefix;
702         for (int count = 0; count < 16; count++) {
703             int byteBits = 0;
704             if (oneCount >= 8) {
705                 byteBits = 8;
706                 oneCount = oneCount - 8;
707             } else {
708                 byteBits = oneCount;
709                 oneCount = 0;
710             }
711
712             mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
713         }
714         return mask;
715     }
716
717     private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
718         MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
719         metadataMatchEntry.setMetadata(convertBigIntegerTo64Bit(metadata));
720         builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
721     }
722
723     /**
724      * Utility method to convert BigInteger to 8 element byte array
725      * @param bigInteger
726      * @return byte array containing 64 bits.
727      */
728     public static byte[] convertBigIntegerTo64Bit(BigInteger bigInteger) {
729         if (bigInteger == null) {
730             return null;
731         }
732         byte[] inputArray = bigInteger.toByteArray();
733         byte[] outputArray = new byte[8];
734         if (bigInteger.compareTo(BigInteger.ZERO) < 0) {
735             Arrays.fill(outputArray, (byte) -1);
736         } else {
737             Arrays.fill(outputArray, (byte) 0);
738         }
739         System.arraycopy(inputArray, 0, outputArray, outputArray.length - inputArray.length, inputArray.length);
740         return outputArray;
741     }
742
743     /**
744      * @return true if Ipv4Prefix contains prefix (and it is used in mask),
745      *         false otherwise
746      */
747     private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
748         boolean hasMask = false;
749         String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
750         Integer prefix = null;
751         if (addressParts.length < 2) {
752             prefix = 0;
753         } else {
754             prefix = Integer.parseInt(addressParts[1]);
755         }
756
757         Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
758         Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
759         ipv4AddressBuilder.setIpv4Address(ipv4Address);
760         builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
761         if (prefix != 0) {
762             int mask = 0xffffffff << (32 - prefix);
763             byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
764                     (byte) mask };
765             addMaskAugmentation(builder, maskBytes);
766             hasMask = true;
767         }
768         return hasMask;
769     }
770
771     private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
772         MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
773         macAddress.setMacAddress(address);
774         builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
775     }
776
777     /**
778      * Method converts OF SetField Match to SAL SetFiled matches
779      *
780      * @param action
781      * @return
782      */
783     public static SetField ofToSALSetField(
784             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
785         logger.info("OF SetField match to SAL SetField match converstion begins");
786         SetFieldBuilder setField = new SetFieldBuilder();
787         /*
788          * OxmFieldsAction oxmFields =
789          * action.getAugmentation(OxmFieldsAction.class);
790          *
791          * List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
792          * org.opendaylight
793          * .yang.gen.v1.urn.opendaylight.action.types.rev131112.action
794          * .action.set.field.MatchBuilder match =new
795          * org.opendaylight.yang.gen.v1
796          * .urn.opendaylight.action.types.rev131112.action
797          * .action.set.field.MatchBuilder();
798          *
799          * EthernetMatchBuilder ethernetMatchBuilder = null; VlanMatchBuilder
800          * vlanMatchBuilder = null; IpMatchBuilder ipMatchBuilder = null;
801          * TcpMatchBuilder tcpMatchBuilder = null; UdpMatchBuilder
802          * udpMatchBuilder = null; SctpMatchBuilder sctpMatchBuilder = null;
803          * Icmpv4MatchBuilder icmpv4MatchBuilder = null; Icmpv6MatchBuilder
804          * icmpv6MatchBuilder = null; Ipv4MatchBuilder ipv4MatchBuilder = null;
805          * ArpMatchBuilder arpMatchBuilder = null; Ipv6MatchBuilder
806          * ipv6MatchBuilder = null; ProtocolMatchFieldsBuilder
807          * protocolMatchFieldsBuilder = null;
808          *
809          * for(MatchEntries matchEntry : matchEntries){ if(matchEntry instanceof
810          * InPort){ PortNumberMatchEntry inPort =
811          * matchEntry.getAugmentation(PortNumberMatchEntry.class);
812          * match.setInPort(inPort.getPortNumber().getValue()); }else if
813          * (matchEntry instanceof InPhyPort){ PortNumberMatchEntry phyPort =
814          * matchEntry.getAugmentation(PortNumberMatchEntry.class);
815          * match.setInPhyPort(phyPort.getPortNumber().getValue()); }else if
816          * (matchEntry instanceof Metadata){ MetadataMatchEntry metadataMatch =
817          * matchEntry.getAugmentation(MetadataMatchEntry.class); MetadataBuilder
818          * metadataBuilder = new MetadataBuilder();
819          * metadataBuilder.setMetadata(new
820          * BigInteger(metadataMatch.getMetadata())); MaskMatchEntry maskMatch =
821          * matchEntry.getAugmentation(MaskMatchEntry.class); if (maskMatch !=
822          * null){ metadataBuilder.setMetadataMask(maskMatch.getMask()); }
823          * match.setMetadata(metadataBuilder.build()); }else if (matchEntry
824          * instanceof EthDst){
825          *
826          * if(ethernetMatchBuilder == null) ethernetMatchBuilder = new
827          * EthernetMatchBuilder();
828          *
829          * MacAddressMatchEntry macAddressMatch =
830          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
831          * MaskMatchEntry maskMatch =
832          * matchEntry.getAugmentation(MaskMatchEntry.class);
833          * EthernetDestinationBuilder ethernetDestination = new
834          * EthernetDestinationBuilder();
835          * ethernetDestination.setAddress(macAddressMatch.getMacAddress());
836          * if(maskMatch != null){
837          * ethernetDestination.setMask(maskMatch.getMask()); }
838          * ethernetMatchBuilder
839          * .setEthernetDestination(ethernetDestination.build()); }else if
840          * (matchEntry instanceof EthSrc){ if(ethernetMatchBuilder == null)
841          * ethernetMatchBuilder = new EthernetMatchBuilder();
842          *
843          * MacAddressMatchEntry macAddressMatch =
844          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
845          * MaskMatchEntry maskMatch =
846          * matchEntry.getAugmentation(MaskMatchEntry.class);
847          * EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
848          * ethernetSource.setAddress(macAddressMatch.getMacAddress());
849          * if(maskMatch != null){ ethernetSource.setMask(maskMatch.getMask()); }
850          * ethernetMatchBuilder.setEthernetSource(ethernetSource.build()); }else
851          * if (matchEntry instanceof EthType){ if(ethernetMatchBuilder == null)
852          * ethernetMatchBuilder = new EthernetMatchBuilder();
853          *
854          * EthTypeMatchEntry etherTypeMatch =
855          * matchEntry.getAugmentation(EthTypeMatchEntry.class);
856          * EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
857          * org.opendaylight
858          * .yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType etherType
859          * = new
860          * org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827
861          * .EtherType((long)etherTypeMatch.getEthType().getValue());
862          * ethernetType.setType(etherType);
863          * ethernetMatchBuilder.setEthernetType(ethernetType.build()); }else if
864          * (matchEntry instanceof VlanVid){ if(vlanMatchBuilder == null)
865          * vlanMatchBuilder = new VlanMatchBuilder();
866          *
867          * VlanVidMatchEntry vlanVidMatch =
868          * matchEntry.getAugmentation(VlanVidMatchEntry.class); MaskMatchEntry
869          * maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
870          *
871          * VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
872          * vlanIdBuilder.setVlanId( new
873          * org.opendaylight.yang.gen.v1.urn.opendaylight
874          * .l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid())); if(maskMatch
875          * != null){ vlanIdBuilder.setMask(maskMatch.getMask()); }
876          * vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
877          *
878          * }else if (matchEntry instanceof VlanPcp){ if(vlanMatchBuilder ==
879          * null) vlanMatchBuilder = new VlanMatchBuilder();
880          *
881          * VlanPcpMatchEntry vlanPcpMatch =
882          * matchEntry.getAugmentation(VlanPcpMatchEntry.class);
883          * vlanMatchBuilder.setVlanPcp( new
884          * org.opendaylight.yang.gen.v1.urn.opendaylight
885          * .l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp())); }else if
886          * (matchEntry instanceof IpDscp){ if(ipMatchBuilder == null)
887          * ipMatchBuilder = new IpMatchBuilder();
888          *
889          * DscpMatchEntry dscpMatchEntry =
890          * matchEntry.getAugmentation(DscpMatchEntry.class);
891          * ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
892          *
893          * }else if (matchEntry instanceof IpEcn){ if(ipMatchBuilder == null)
894          * ipMatchBuilder = new IpMatchBuilder();
895          *
896          * EcnMatchEntry ecnMatchEntry =
897          * matchEntry.getAugmentation(EcnMatchEntry.class);
898          * ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
899          *
900          * }else if (matchEntry instanceof IpProto){ if(ipMatchBuilder == null)
901          * ipMatchBuilder = new IpMatchBuilder();
902          *
903          * ProtocolNumberMatchEntry protocolNumberMatch =
904          * matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
905          * ipMatchBuilder
906          * .setIpProtocol(protocolNumberMatch.getProtocolNumber()); }else if
907          * (matchEntry instanceof TcpSrc){ if(tcpMatchBuilder == null)
908          * tcpMatchBuilder = new TcpMatchBuilder();
909          *
910          * PortMatchEntry portMatchEntry =
911          * matchEntry.getAugmentation(PortMatchEntry.class);
912          * tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
913          *
914          * }else if (matchEntry instanceof TcpDst){ if(tcpMatchBuilder == null)
915          * tcpMatchBuilder = new TcpMatchBuilder();
916          *
917          * PortMatchEntry portMatchEntry =
918          * matchEntry.getAugmentation(PortMatchEntry.class);
919          * tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
920          *
921          * }else if (matchEntry instanceof UdpSrc){ if(udpMatchBuilder == null)
922          * udpMatchBuilder = new UdpMatchBuilder();
923          *
924          * PortMatchEntry portMatchEntry =
925          * matchEntry.getAugmentation(PortMatchEntry.class);
926          * udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
927          *
928          *
929          * }else if (matchEntry instanceof UdpDst){ if(udpMatchBuilder == null)
930          * udpMatchBuilder = new UdpMatchBuilder();
931          *
932          * PortMatchEntry portMatchEntry =
933          * matchEntry.getAugmentation(PortMatchEntry.class);
934          * udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
935          * }else if (matchEntry instanceof SctpSrc){ if(sctpMatchBuilder ==
936          * null) sctpMatchBuilder = new SctpMatchBuilder();
937          *
938          * PortMatchEntry portMatchEntry =
939          * matchEntry.getAugmentation(PortMatchEntry.class);
940          * sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
941          *
942          * }else if (matchEntry instanceof SctpDst){ if(sctpMatchBuilder ==
943          * null) sctpMatchBuilder = new SctpMatchBuilder();
944          *
945          * PortMatchEntry portMatchEntry =
946          * matchEntry.getAugmentation(PortMatchEntry.class);
947          * sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
948          * }else if (matchEntry instanceof Icmpv4Type){ if(icmpv4MatchBuilder ==
949          * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
950          *
951          * Icmpv4TypeMatchEntry icmpv4TypeMatchEntry =
952          * matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
953          * icmpv4MatchBuilder
954          * .setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
955          *
956          * }else if (matchEntry instanceof Icmpv4Code){ if(icmpv4MatchBuilder ==
957          * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
958          *
959          * Icmpv4CodeMatchEntry icmpv4CodeMatchEntry =
960          * matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
961          * icmpv4MatchBuilder
962          * .setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
963          *
964          * }else if (matchEntry instanceof Icmpv6Type){ if(icmpv6MatchBuilder ==
965          * null) icmpv6MatchBuilder = new Icmpv6MatchBuilder();
966          *
967          * Icmpv6TypeMatchEntry icmpv6TypeMatchEntry =
968          * matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
969          * icmpv6MatchBuilder
970          * .setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type()); }else if
971          * (matchEntry instanceof Icmpv6Code){ if(icmpv6MatchBuilder == null)
972          * icmpv6MatchBuilder = new Icmpv6MatchBuilder();
973          *
974          * Icmpv6CodeMatchEntry icmpv6CodeMatchEntry =
975          * matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
976          * icmpv6MatchBuilder
977          * .setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code()); }else if
978          * (matchEntry instanceof Ipv4Src){ if(ipv4MatchBuilder == null)
979          * ipv4MatchBuilder = new Ipv4MatchBuilder();
980          *
981          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
982          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
983          * MaskMatchEntry maskMatchEntry =
984          * matchEntry.getAugmentation(MaskMatchEntry.class);
985          * ipv4MatchBuilder.setIpv4Source( new
986          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
987          * String(maskMatchEntry.getMask())));
988          *
989          * }else if (matchEntry instanceof Ipv4Dst){ if(ipv4MatchBuilder ==
990          * null) ipv4MatchBuilder = new Ipv4MatchBuilder();
991          *
992          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
993          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
994          * MaskMatchEntry maskMatchEntry =
995          * matchEntry.getAugmentation(MaskMatchEntry.class);
996          * ipv4MatchBuilder.setIpv4Destination( new
997          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
998          * String(maskMatchEntry.getMask()))); }else if (matchEntry instanceof
999          * ArpOp){ if(arpMatchBuilder == null) arpMatchBuilder = new
1000          * ArpMatchBuilder();
1001          *
1002          * OpCodeMatchEntry opCodeMatchEntry =
1003          * matchEntry.getAugmentation(OpCodeMatchEntry.class);
1004          * arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
1005          *
1006          * }else if (matchEntry instanceof ArpSpa){ if(arpMatchBuilder == null)
1007          * arpMatchBuilder = new ArpMatchBuilder();
1008          *
1009          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1010          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1011          * MaskMatchEntry maskMatchEntry =
1012          * matchEntry.getAugmentation(MaskMatchEntry.class);
1013          * arpMatchBuilder.setArpSourceTransportAddress( new
1014          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1015          * String(maskMatchEntry.getMask())));
1016          *
1017          * }else if (matchEntry instanceof ArpTpa){ if(arpMatchBuilder == null)
1018          * arpMatchBuilder = new ArpMatchBuilder();
1019          *
1020          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1021          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1022          * MaskMatchEntry maskMatchEntry =
1023          * matchEntry.getAugmentation(MaskMatchEntry.class);
1024          * arpMatchBuilder.setArpTargetTransportAddress( new
1025          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1026          * String(maskMatchEntry.getMask())));
1027          *
1028          * }else if (matchEntry instanceof ArpSha){ if(arpMatchBuilder == null)
1029          * arpMatchBuilder = new ArpMatchBuilder();
1030          *
1031          * MacAddressMatchEntry macAddressMatchEntry =
1032          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1033          * MaskMatchEntry maskMatchEntry =
1034          * matchEntry.getAugmentation(MaskMatchEntry.class);
1035          * ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new
1036          * ArpSourceHardwareAddressBuilder();
1037          * arpSourceHardwareAddressBuilder.setAddress
1038          * (macAddressMatchEntry.getMacAddress());
1039          * arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1040          * arpMatchBuilder
1041          * .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
1042          * .build());
1043          *
1044          * }else if (matchEntry instanceof ArpTha){ if(arpMatchBuilder == null)
1045          * arpMatchBuilder = new ArpMatchBuilder();
1046          *
1047          * MacAddressMatchEntry macAddressMatchEntry =
1048          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1049          * MaskMatchEntry maskMatchEntry =
1050          * matchEntry.getAugmentation(MaskMatchEntry.class);
1051          * ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new
1052          * ArpTargetHardwareAddressBuilder();
1053          * arpTargetHardwareAddressBuilder.setAddress
1054          * (macAddressMatchEntry.getMacAddress());
1055          * arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1056          * arpMatchBuilder
1057          * .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
1058          * .build()); }else if (matchEntry instanceof Ipv6Src){
1059          * if(ipv6MatchBuilder == null) ipv6MatchBuilder = new
1060          * Ipv6MatchBuilder();
1061          *
1062          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1063          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1064          * MaskMatchEntry maskMatchEntry =
1065          * matchEntry.getAugmentation(MaskMatchEntry.class);
1066          * ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix
1067          * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1068          * String(maskMatchEntry.getMask())));
1069          *
1070          * }else if (matchEntry instanceof Ipv6Dst){ if(ipv6MatchBuilder ==
1071          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1072          *
1073          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1074          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1075          * MaskMatchEntry maskMatchEntry =
1076          * matchEntry.getAugmentation(MaskMatchEntry.class);
1077          * ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix
1078          * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1079          * String(maskMatchEntry.getMask())));
1080          *
1081          * }else if (matchEntry instanceof Ipv6Flabel){ if(ipv6MatchBuilder ==
1082          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1083          *
1084          * Ipv6FlabelMatchEntry ipv6FlabelMatchEntry =
1085          * matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
1086          * MaskMatchEntry maskMatchEntry =
1087          * matchEntry.getAugmentation(MaskMatchEntry.class); Ipv6LabelBuilder
1088          * ipv6LabelBuilder = new Ipv6LabelBuilder();
1089          * ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
1090          * ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
1091          * ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1092          *
1093          * }else if (matchEntry instanceof Ipv6NdTarget){ if(ipv6MatchBuilder ==
1094          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1095          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1096          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1097          * ipv6MatchBuilder
1098          * .setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
1099          *
1100          * }else if (matchEntry instanceof Ipv6NdSll){ if(ipv6MatchBuilder ==
1101          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1102          *
1103          * MacAddressMatchEntry macAddressMatchEntry =
1104          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1105          * ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
1106          * }else if (matchEntry instanceof Ipv6NdTll){ if(ipv6MatchBuilder ==
1107          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1108          *
1109          * MacAddressMatchEntry macAddressMatchEntry =
1110          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1111          * ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
1112          *
1113          * }else if (matchEntry instanceof Ipv6Exthdr){ if(ipv6MatchBuilder ==
1114          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1115          *
1116          * PseudoFieldMatchEntry pseudoFieldMatchEntry =
1117          * matchEntry.getAugmentation(PseudoFieldMatchEntry.class); PseudoField
1118          * pseudoField = pseudoFieldMatchEntry.getPseudoField(); int
1119          * pseudoFieldInt = 0; pseudoFieldInt |= pseudoField.isNonext()?(1 <<
1120          * 0):~(1 << 0); pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 <<
1121          * 1); pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
1122          * pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
1123          * pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
1124          * pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
1125          * pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
1126          * pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
1127          * pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
1128          *
1129          * ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt); }else if (matchEntry
1130          * instanceof MplsLabel){ if(protocolMatchFieldsBuilder == null)
1131          * protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1132          *
1133          * MplsLabelMatchEntry MplsLabelMatchEntry =
1134          * matchEntry.getAugmentation(MplsLabelMatchEntry.class);
1135          * protocolMatchFieldsBuilder
1136          * .setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
1137          *
1138          * }else if (matchEntry instanceof MplsBos){
1139          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1140          * new ProtocolMatchFieldsBuilder();
1141          *
1142          * BosMatchEntry bosMatchEntry =
1143          * matchEntry.getAugmentation(BosMatchEntry.class);
1144          * protocolMatchFieldsBuilder
1145          * .setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
1146          *
1147          * }else if (matchEntry instanceof MplsTc) {
1148          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1149          * new ProtocolMatchFieldsBuilder();
1150          *
1151          * TcMatchEntry tcMatchEntry =
1152          * matchEntry.getAugmentation(TcMatchEntry.class);
1153          * protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
1154          *
1155          * }else if (matchEntry instanceof PbbIsid){
1156          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1157          * new ProtocolMatchFieldsBuilder();
1158          *
1159          * IsidMatchEntry isidMatchEntry =
1160          * matchEntry.getAugmentation(IsidMatchEntry.class); PbbBuilder
1161          * pbbBuilder = new PbbBuilder();
1162          * pbbBuilder.setPbbIsid(isidMatchEntry.getIsid()); MaskMatchEntry
1163          * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1164          * if(maskMatchEntry != null)
1165          * pbbBuilder.setPbbMask(maskMatchEntry.getMask());
1166          *
1167          * protocolMatchFieldsBuilder.setPbb(pbbBuilder.build()); }else if
1168          * (matchEntry instanceof TunnelId){ MetadataMatchEntry
1169          * metadataMatchEntry =
1170          * matchEntry.getAugmentation(MetadataMatchEntry.class); MaskMatchEntry
1171          * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1172          * TunnelBuilder tunnelBuilder = new TunnelBuilder();
1173          * tunnelBuilder.setTunnelId(new
1174          * BigInteger(metadataMatchEntry.getMetadata()));
1175          * tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
1176          * match.setTunnel(tunnelBuilder.build()); } } if(ethernetMatchBuilder
1177          * != null){ match.setEthernetMatch(ethernetMatchBuilder.build()); } if
1178          * (vlanMatchBuilder != null){
1179          * match.setVlanMatch(vlanMatchBuilder.build()); } if(ipMatchBuilder !=
1180          * null){ match.setIpMatch(ipMatchBuilder.build()); } if(tcpMatchBuilder
1181          * != null){ match.setLayer4Match(tcpMatchBuilder.build()); }
1182          * if(udpMatchBuilder != null){
1183          * match.setLayer4Match(udpMatchBuilder.build()); } if(sctpMatchBuilder
1184          * != null){ match.setLayer4Match(sctpMatchBuilder.build()); }
1185          * if(icmpv4MatchBuilder != null){
1186          * match.setIcmpv4Match(icmpv4MatchBuilder.build()); }
1187          * if(icmpv6MatchBuilder != null){
1188          * match.setIcmpv6Match(icmpv6MatchBuilder.build()); }
1189          * if(ipv4MatchBuilder != null){
1190          * match.setLayer3Match(ipv4MatchBuilder.build()); } if(arpMatchBuilder
1191          * != null){ match.setLayer3Match(arpMatchBuilder.build()); }
1192          * if(ipv6MatchBuilder != null){
1193          * match.setLayer3Match(ipv6MatchBuilder.build()); }
1194          * if(protocolMatchFieldsBuilder != null){
1195          * match.setProtocolMatchFields(protocolMatchFieldsBuilder.build()); }
1196          * setField.setMatch(match.build());
1197          */return setField.build();
1198     }
1199
1200 }