Merge "Fixed a typo in pom.xml s/includeArtifacIds/includeArtifactIds/"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / match / MatchConvertorImpl.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.match;
10
11 import java.math.BigInteger;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
17 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
171 import org.slf4j.Logger;
172 import org.slf4j.LoggerFactory;
173
174 /**
175  * Utility class for converting a MD-SAL Flow into the OF flow mod
176  */
177 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
178     private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
179     static final String PREFIX_SEPARATOR = "/";
180     private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
181     private static final short PROTO_TCP = 6;
182     private static final short PROTO_UDP = 17;
183     private static final String noIp = "0.0.0.0/0";
184
185     @Override
186     public List<MatchEntries> convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match,BigInteger datapathid) {
187         List<MatchEntries> matchEntriesList = new ArrayList<>();
188
189         if (match.getInPort() != null) {
190             matchEntriesList.add(toOfPort(InPort.class, InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPort())));
191         }
192
193         if (match.getInPhyPort() != null) {
194             matchEntriesList.add(toOfPort(InPhyPort.class, InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPhyPort())));
195         }
196
197         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
198                 .getMetadata();
199         if (metadata != null) {
200             matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
201         }
202
203         EthernetMatch ethernetMatch = match.getEthernetMatch();
204         if (ethernetMatch != null) {
205             EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
206             if (ethernetDestination != null) {
207                 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
208                         ethernetDestination.getMask()));
209             }
210
211             EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
212             if (ethernetSource != null) {
213                 matchEntriesList
214                         .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
215             }
216
217             if (ethernetMatch.getEthernetType() != null) {
218                 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
219             }
220         }
221
222         VlanMatch vlanMatch = match.getVlanMatch();
223         if (vlanMatch != null) {
224             if (vlanMatch.getVlanId() != null) {
225                 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
226             }
227
228             if (vlanMatch.getVlanPcp() != null) {
229                 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
230             }
231         }
232
233         IpMatch ipMatch = match.getIpMatch();
234         if (ipMatch != null) {
235             if (ipMatch.getIpDscp() != null) {
236                 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
237             }
238
239             if (ipMatch.getIpEcn() != null) {
240                 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
241             }
242
243             if (ipMatch.getIpProtocol() != null) {
244                 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
245             }
246
247         }
248
249         Layer4Match layer4Match = match.getLayer4Match();
250         if (layer4Match != null) {
251             if (layer4Match instanceof TcpMatch) {
252                 TcpMatch tcpMatch = (TcpMatch) layer4Match;
253                 if (tcpMatch.getTcpSourcePort() != null) {
254                     matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
255                 }
256
257                 if (tcpMatch.getTcpDestinationPort() != null) {
258                     matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
259                 }
260             } else if (layer4Match instanceof UdpMatch) {
261                 UdpMatch udpMatch = (UdpMatch) layer4Match;
262                 if (udpMatch.getUdpSourcePort() != null) {
263                     matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
264                 }
265
266                 if (udpMatch.getUdpDestinationPort() != null) {
267                     matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
268                 }
269             } else if (layer4Match instanceof SctpMatch) {
270                 SctpMatch sctpMatch = (SctpMatch) layer4Match;
271                 if (sctpMatch.getSctpSourcePort() != null) {
272                     matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
273                 }
274
275                 if (sctpMatch.getSctpDestinationPort() != null) {
276                     matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
277                 }
278             }
279         }
280
281         Icmpv4Match icmpv4Match = match.getIcmpv4Match();
282         if (icmpv4Match != null) {
283             if (icmpv4Match.getIcmpv4Type() != null) {
284                 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
285             }
286
287             if (icmpv4Match.getIcmpv4Code() != null) {
288                 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
289             }
290         }
291
292         Icmpv6Match icmpv6Match = match.getIcmpv6Match();
293         if (icmpv6Match != null) {
294             if (icmpv6Match.getIcmpv6Type() != null) {
295                 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
296             }
297
298             if (icmpv6Match.getIcmpv6Code() != null) {
299                 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
300             }
301         }
302
303         Layer3Match layer3Match = match.getLayer3Match();
304         if (layer3Match != null) {
305             if (layer3Match instanceof Ipv4Match) {
306                 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
307                 if (ipv4Match.getIpv4Source() != null) {
308                     matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
309                 }
310                 if (ipv4Match.getIpv4Destination() != null) {
311                     matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
312                 }
313             } else if (layer3Match instanceof ArpMatch) {
314                 ArpMatch arpMatch = (ArpMatch) layer3Match;
315                 if (arpMatch.getArpOp() != null) {
316                     matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
317                 }
318
319                 if (arpMatch.getArpSourceTransportAddress() != null) {
320                     matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
321                 }
322
323                 if (arpMatch.getArpTargetTransportAddress() != null) {
324                     matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
325                 }
326
327                 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
328                 if (arpSourceHardwareAddress != null) {
329                     matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
330                             arpSourceHardwareAddress.getMask()));
331                 }
332
333                 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
334                 if (arpTargetHardwareAddress != null) {
335                     matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
336                             arpTargetHardwareAddress.getMask()));
337                 }
338             }
339
340             else if (layer3Match instanceof Ipv6Match) {
341                 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
342                 if (ipv6Match.getIpv6Source() != null) {
343                     matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
344                 }
345
346                 if (ipv6Match.getIpv6Destination() != null) {
347                     matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
348                 }
349
350                 if (ipv6Match.getIpv6Label() != null) {
351                     matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
352                 }
353
354                 if (ipv6Match.getIpv6NdTarget() != null) {
355                     matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
356                 }
357
358                 if (ipv6Match.getIpv6NdSll() != null) {
359                     matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
360                 }
361
362                 if (ipv6Match.getIpv6NdTll() != null) {
363                     matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
364                 }
365
366                 if (ipv6Match.getIpv6ExtHeader() != null) {
367                     matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
368                 }
369             }
370         }
371
372         ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
373         if (protocolMatchFields != null) {
374             if (protocolMatchFields.getMplsLabel() != null) {
375                 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
376             }
377
378             if (protocolMatchFields.getMplsBos() != null) {
379                 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
380             }
381
382             if (protocolMatchFields.getMplsTc() != null) {
383                 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
384             }
385
386             if (protocolMatchFields.getPbb() != null) {
387                 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
388             }
389         }
390
391         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
392                 .getTunnel();
393         if (tunnel != null) {
394             matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
395         }
396
397         
398         return matchEntriesList;
399     }
400     
401     /**
402      * Method convert Openflow 1.0 specific flow match to MD-SAL format 
403      * flow match
404      * @param match
405      * @return
406      * @author avishnoi@in.ibm.com
407      */
408     public static Match fromOFMatchV10ToSALMatch(MatchV10 swMatch,BigInteger datapathid){
409         MatchBuilder matchBuilder = new MatchBuilder();
410         EthernetMatchBuilder ethMatchBuilder =  new EthernetMatchBuilder();
411         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
412         Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
413         IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
414         if(!swMatch.getWildcards().isINPORT().booleanValue()&& swMatch.getInPort() != null){
415             matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,(long)swMatch.getInPort()));
416         }
417         
418         if(!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc()!= null){
419             EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
420             ethSrcBuilder.setAddress(swMatch.getDlSrc());
421             ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
422             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
423         }
424         if(!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst()!= null){
425             EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
426             ethDstBuilder.setAddress(swMatch.getDlDst());
427             ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
428             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
429         }
430         if(!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType()!= null){
431             EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
432             ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)swMatch.getDlType()));
433             ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
434             matchBuilder.setEthernetMatch(ethMatchBuilder.build());
435         }
436         if(!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan()!=null){
437             VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
438             vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(swMatch.getDlVlan()));
439             vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
440             matchBuilder.setVlanMatch(vlanMatchBuilder.build());
441         }
442         if(!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp()!= null){
443             vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(swMatch.getDlVlanPcp()));
444             matchBuilder.setVlanMatch(vlanMatchBuilder.build());
445         }
446         if(!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwSrc() !=null){
447             String ipv4PrefixStr = swMatch.getNwSrc().getValue();
448             if(swMatch.getNwSrcMask()!= null){
449                 ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwSrcMask();
450             }
451             if(!ipv4PrefixStr.equals(noIp)){
452                 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
453                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
454             }
455         }
456         if(!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwDst() !=null){
457             String ipv4PrefixStr = swMatch.getNwDst().getValue();
458             if(swMatch.getNwDstMask()!= null){
459                 ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwDstMask();
460             }
461             if(!ipv4PrefixStr.equals(noIp)){
462                 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
463                 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
464             }
465         }
466         if(!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto()!= null ){
467             ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
468             matchBuilder.setIpMatch(ipMatchBuilder.build());
469         }
470         if(!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP){
471             TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
472             if(!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc()!= null)
473                 tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
474             if(!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst()!= null)
475                 tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
476             
477             if(!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue())
478                 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
479         }
480         if(!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP){
481             UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
482             if(!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc()!= null)
483                 udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
484             if(!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst()!= null)
485                 udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
486             
487             if(!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue())
488                 matchBuilder.setLayer4Match(udpMatchBuilder.build());
489         }
490         if(!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos()!=null){
491             //DSCP default value is 0 from the library but controller side it is null.
492             // look if there better solution 
493             if(0 != swMatch.getNwTos()) 
494             {
495                ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
496             }
497             matchBuilder.setIpMatch(ipMatchBuilder.build());
498         }
499         
500         return matchBuilder.build();
501     }
502
503     /**
504      * Method converts Openflow 1.3+ specific flow match to MD-SAL format
505      * flow match
506      * @param match
507      * @return
508      * @author avishnoi@in.ibm.com
509      */
510     public static Match fromOFMatchToSALMatch(
511             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match swMatch,BigInteger datapathid) {
512         
513         MatchBuilder matchBuilder = new MatchBuilder();
514         EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
515         VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
516         IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
517         TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
518         UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
519         SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
520         Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
521         Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
522         Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
523         ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
524         Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
525         ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
526
527         List<MatchEntries> swMatchList = swMatch.getMatchEntries();
528         
529         for(MatchEntries ofMatch : swMatchList){
530             
531             if(ofMatch.getOxmMatchField().equals(InPort.class)){
532                 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
533                 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNumber.getPortNumber().getValue()));
534             }else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)){
535                 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
536                 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,portNumber.getPortNumber().getValue()));
537             }else if(ofMatch.getOxmMatchField().equals(Metadata.class)){
538                 MetadataBuilder metadataBuilder = new MetadataBuilder();
539                 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
540                 if(metadataMatchEntry != null){
541                     metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
542                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
543                     if(maskMatchEntry != null){
544                         metadataBuilder.setMetadataMask(maskMatchEntry.getMask());
545                     }
546                     matchBuilder.setMetadata(metadataBuilder.build());
547                 }
548             }else if(ofMatch.getOxmMatchField().equals(EthSrc.class)){
549                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
550                 if(macAddressMatchEntry != null){
551                     EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
552                     ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
553                     ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
554                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
555                 }
556             }else if(ofMatch.getOxmMatchField().equals(EthDst.class)){
557                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
558                 if(macAddressMatchEntry != null){
559                     EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
560                     ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
561                     ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
562                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
563                 }
564             }else if(ofMatch.getOxmMatchField().equals(EthType.class)){
565                 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
566                 if(ethTypeMatchEntry != null){
567                     EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
568                     ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)ethTypeMatchEntry.getEthType().getValue()));
569                     ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
570                     matchBuilder.setEthernetMatch(ethMatchBuilder.build());
571                 }
572             }else if(ofMatch.getOxmMatchField().equals(VlanVid.class)){
573                 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
574                 if(vlanVidMatchEntry != null){
575                     VlanIdBuilder vlanBuilder = new VlanIdBuilder();
576                     vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatchEntry.getVlanVid()));                   
577                     vlanMatchBuilder.setVlanId(vlanBuilder.build());
578                     matchBuilder.setVlanMatch(vlanMatchBuilder.build());
579                 }
580             }else if(ofMatch.getOxmMatchField().equals(VlanPcp.class)){
581                 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
582                 if(vlanPcpMatchEntry != null){
583                     vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(vlanPcpMatchEntry.getVlanPcp()));
584                     matchBuilder.setVlanMatch(vlanMatchBuilder.build());
585                 }
586             }else if(ofMatch.getOxmMatchField().equals(IpDscp.class)){
587                 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
588                 if(dscpMatchEntry != null){
589                     ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
590                     matchBuilder.setIpMatch(ipMatchBuilder.build());
591                 }
592             }else if(ofMatch.getOxmMatchField().equals(IpEcn.class)){
593                 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
594                 if(ecnMatchEntry != null){
595                     ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
596                     matchBuilder.setIpMatch(ipMatchBuilder.build());
597                 }
598             }else if(ofMatch.getOxmMatchField().equals(IpProto.class)){
599                 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch.getAugmentation(ProtocolNumberMatchEntry.class);
600                 if(protocolNumberMatchEntry != null){
601                     ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
602                     matchBuilder.setIpMatch(ipMatchBuilder.build());
603                 }
604             }else if(ofMatch.getOxmMatchField().equals(TcpSrc.class)){
605                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
606                 if(portMatchEntry != null){
607                     tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
608                     matchBuilder.setLayer4Match(tcpMatchBuilder.build());
609                 }
610             }else if(ofMatch.getOxmMatchField().equals(TcpDst.class)){
611                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
612                 if(portMatchEntry != null){
613                     tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
614                     matchBuilder.setLayer4Match(tcpMatchBuilder.build());
615                 }
616             }else if(ofMatch.getOxmMatchField().equals(UdpSrc.class)){
617                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
618                 if(portMatchEntry != null){
619                     udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
620                     matchBuilder.setLayer4Match(udpMatchBuilder.build());
621                 }
622             }else if(ofMatch.getOxmMatchField().equals(UdpDst.class)){
623                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
624                 if(portMatchEntry != null){
625                     udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
626                     matchBuilder.setLayer4Match(udpMatchBuilder.build());
627                 }
628             }else if(ofMatch.getOxmMatchField().equals(SctpSrc.class)){
629                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
630                 if(portMatchEntry != null){
631                     sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
632                     matchBuilder.setLayer4Match(sctpMatchBuilder.build());
633                 }
634             }else if(ofMatch.getOxmMatchField().equals(SctpDst.class)){
635                 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
636                 if(portMatchEntry != null){
637                     sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
638                     matchBuilder.setLayer4Match(sctpMatchBuilder.build());
639                 }
640             }else if(ofMatch.getOxmMatchField().equals(Icmpv4Type.class)){
641                 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
642                 if(icmpv4TypeMatchEntry != null){
643                     icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
644                     matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
645                 }
646             }else if(ofMatch.getOxmMatchField().equals(Icmpv4Code.class)){
647                 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
648                 if(icmpv4CodeMatchEntry != null){
649                     icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
650                     matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
651                 }
652             }else if(ofMatch.getOxmMatchField().equals(Icmpv6Type.class)){
653                 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
654                 if(icmpv6TypeMatchEntry != null){
655                     icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
656                     matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
657                 }
658             }else if(ofMatch.getOxmMatchField().equals(Icmpv6Code.class)){
659                 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
660                 if(icmpv6CodeMatchEntry != null){
661                     icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
662                     matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
663                 }
664             }else if(ofMatch.getOxmMatchField().equals(Ipv4Src.class) ||
665                     ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
666                 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
667                 if(ipv4AddressMatchEntry != null){
668                     String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
669                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
670                     if(maskMatchEntry != null){
671                         ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
672                     }
673                     if(ofMatch.getOxmMatchField().equals(Ipv4Src.class)){
674                         ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
675                     }
676                     if(ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
677                         ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
678                     }
679                     matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
680                 }
681             }else if(ofMatch.getOxmMatchField().equals(ArpOp.class)){
682                 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
683                 if(opCodeMatchEntry != null){
684                     arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
685                     matchBuilder.setLayer3Match(arpMatchBuilder.build());
686                 }
687             }else if(ofMatch.getOxmMatchField().equals(ArpSpa.class) ||
688                     ofMatch.getOxmMatchField().equals(ArpTpa.class)){
689                 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
690                 if(ipv4AddressMatchEntry != null){
691                     String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
692                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
693                     if(maskMatchEntry != null){
694                         ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
695                     }
696                     if(ofMatch.getOxmMatchField().equals(ArpSpa.class)){
697                         arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
698                     }
699                     if(ofMatch.getOxmMatchField().equals(ArpTpa.class)){
700                         arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
701                     }
702                     matchBuilder.setLayer3Match(arpMatchBuilder.build());
703                 }
704             }else if(ofMatch.getOxmMatchField().equals(ArpSha.class) ||
705                     ofMatch.getOxmMatchField().equals(ArpTha.class)){
706                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
707                 if(macAddressMatchEntry !=null){
708                     if(ofMatch.getOxmMatchField().equals(ArpSha.class)){
709                         ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
710                         arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
711                         MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
712                         if(maskMatchEntry != null){
713                             arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
714                         }
715                         arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
716                         matchBuilder.setLayer3Match(arpMatchBuilder.build());
717                     }
718                     if(ofMatch.getOxmMatchField().equals(ArpTha.class)){
719                         ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
720                         arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
721                         MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
722                         if(maskMatchEntry != null){
723                             arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
724                         }
725                         arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
726                         matchBuilder.setLayer3Match(arpMatchBuilder.build());
727                     }
728                 }
729             }else if(ofMatch.getOxmMatchField().equals(Ipv6Src.class) ||
730                     ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
731                 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
732                 if(ipv6AddressMatchEntry != null){
733                     String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
734                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
735                     if(maskMatchEntry != null){
736                         ipv6PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
737                     }
738                     if(ofMatch.getOxmMatchField().equals(Ipv6Src.class)){
739                         ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
740                     }
741                     if(ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
742                         ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
743                     }
744                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
745                 }
746             }else if(ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)){
747                 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
748                 if(ipv6FlabelMatchEntry != null){
749                     Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
750                     ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
751                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
752                     if(maskMatchEntry != null){
753                         ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
754                     }
755                     ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
756                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
757                 }
758             }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)){
759                 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
760                 if(ipv6AddressMatchEntry != null){
761                     ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
762                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
763                 }
764             }else if(ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)){
765                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
766                 if(macAddressMatchEntry != null){
767                     ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
768                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
769                 }
770             }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)){
771                 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
772                 if(macAddressMatchEntry != null){
773                     ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
774                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
775                 }
776             }else if(ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)){
777                 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
778                 if(pseudoFieldMatchEntry != null){
779                     Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
780                         
781                     Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
782                     Integer bitmap = 0;
783                     bitmap |= pField.isNonext()?(1 << 0): ~(1 << 0);
784                     bitmap |= pField.isEsp()?(1 << 1): ~(1 << 1);
785                     bitmap |= pField.isAuth()?(1 << 2): ~(1 << 2);
786                     bitmap |= pField.isDest()?(1 << 3): ~(1 << 3);
787                     bitmap |= pField.isFrag()?(1 << 4): ~(1 << 4);
788                     bitmap |= pField.isRouter()?(1 << 5): ~(1 << 5);
789                     bitmap |= pField.isHop()?(1 << 6): ~(1 << 6);
790                     bitmap |= pField.isUnrep()?(1 << 7): ~(1 << 7);
791                     bitmap |= pField.isUnseq()?(1 << 8): ~(1 << 8);
792
793                     ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
794                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
795                     if(maskMatchEntry != null){
796                         ipv6ExtHeaderBuilder.setIpv6ExthdrMask(maskMatchEntry.getMask());
797                     }
798                     ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
799                     matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
800                 }
801             }else if(ofMatch.getOxmMatchField().equals(MplsLabel.class)){
802                 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
803                 if(mplsLabelMatchEntry != null){
804                     protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
805                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
806                 }
807             }else if(ofMatch.getOxmMatchField().equals(MplsBos.class)){
808                 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
809                 if(bosMatchEntry != null){
810                     protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
811                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
812                 }
813             }else if(ofMatch.getOxmMatchField().equals(MplsTc.class)){
814                 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
815                 if(tcMatchEntry != null){
816                     protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
817                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
818                 }
819             }else if(ofMatch.getOxmMatchField().equals(PbbIsid.class)){
820                 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
821                 if(isidMatchEntry != null){
822                     PbbBuilder pbbBuilder = new PbbBuilder();
823                     pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
824                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
825                     if(maskMatchEntry != null){
826                         pbbBuilder.setPbbMask(maskMatchEntry.getMask());
827                     }
828                     protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
829                     matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
830                 }
831             }else if(ofMatch.getOxmMatchField().equals(TunnelId.class)){
832                 TunnelBuilder tunnelBuilder = new TunnelBuilder();
833                 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
834                 if(metadataMatchEntry != null){
835                     tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
836                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
837                     if(maskMatchEntry != null){
838                         tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
839                     }
840                     matchBuilder.setTunnel(tunnelBuilder.build());
841                 }
842             }
843         }
844         return matchBuilder.build();
845     }
846
847     
848     private static MatchEntries toOfMplsPbb(Pbb pbb) {
849         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
850         boolean hasmask = false;
851         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
852         matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
853         IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
854         isidBuilder.setIsid(pbb.getPbbIsid());
855         matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
856         if (pbb.getPbbMask() != null) {
857             hasmask = true;
858             addMaskAugmentation(matchEntriesBuilder, pbb.getPbbMask());
859         }
860         matchEntriesBuilder.setHasMask(hasmask);
861         return matchEntriesBuilder.build();
862     }
863
864     private static MatchEntries toOfMplsTc(Short mplsTc) {
865         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
866         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
867         matchEntriesBuilder.setHasMask(false);
868         matchEntriesBuilder.setOxmMatchField(MplsTc.class);
869         TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
870         tcBuilder.setTc(mplsTc);
871         matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
872         return matchEntriesBuilder.build();
873     }
874
875     private static MatchEntries toOfMplsBos(Short mplsBos) {
876         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
877         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
878         matchEntriesBuilder.setHasMask(false);
879         matchEntriesBuilder.setOxmMatchField(MplsBos.class);
880         BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
881         if (mplsBos != 0) {
882             bosBuilder.setBos(true);
883         } else {
884             bosBuilder.setBos(false);
885         }
886         matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
887         return matchEntriesBuilder.build();
888     }
889
890     private static MatchEntries toOfMplsLabel(Long mplsLabel) {
891         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
892         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
893         matchEntriesBuilder.setHasMask(false);
894         matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
895         MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
896         mplsLabelBuilder.setMplsLabel(mplsLabel);
897         matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
898         return matchEntriesBuilder.build();
899     }
900
901     private static MatchEntries toOfIpv6ExtHeader(Ipv6ExtHeader ipv6ExtHeader) {
902         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
903         boolean hasmask = false;
904         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
905         matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
906         PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
907         Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
908         final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
909         final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
910         final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
911         final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
912         final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
913         final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
914         final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
915         final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
916         final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
917         pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
918         matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
919         if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
920             hasmask = true;
921             addMaskAugmentation(matchEntriesBuilder, ipv6ExtHeader.getIpv6ExthdrMask());
922         }
923         matchEntriesBuilder.setHasMask(hasmask);
924         return matchEntriesBuilder.build();
925     }
926
927     private static MatchEntries toOfIpv6FlowLabel(Ipv6Label ipv6Label) {
928         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
929         boolean hasmask = false;
930         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
931         matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
932         Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
933         ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
934         matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
935         if (ipv6Label.getFlabelMask() != null) {
936             hasmask = true;
937             addMaskAugmentation(matchEntriesBuilder, ipv6Label.getFlabelMask());
938         }
939         matchEntriesBuilder.setHasMask(hasmask);
940         return matchEntriesBuilder.build();
941     }
942
943     private static MatchEntries toOfPort(Class<? extends MatchField> field, Long portNumber) {
944         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
945         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
946         matchEntriesBuilder.setHasMask(false);
947         matchEntriesBuilder.setOxmMatchField(field);
948         PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
949         port.setPortNumber(new PortNumber(portNumber));
950         matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
951         return matchEntriesBuilder.build();
952     }
953
954     private static MatchEntries toOfMetadata(Class<? extends MatchField> field, BigInteger metadata, byte[] metadataMask) {
955         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
956         boolean hasmask = false;
957         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
958         matchEntriesBuilder.setOxmMatchField(field);
959         addMetadataAugmentation(matchEntriesBuilder, metadata);
960         if (metadataMask != null) {
961             hasmask = true;
962             addMaskAugmentation(matchEntriesBuilder, metadataMask);
963         }
964         matchEntriesBuilder.setHasMask(hasmask);
965         return matchEntriesBuilder.build();
966     }
967
968     private static MatchEntries toOfMacAddress(Class<? extends MatchField> field,
969             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
970             byte[] mask) {
971         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
972         boolean hasmask = false;
973         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
974         matchEntriesBuilder.setOxmMatchField(field);
975         addMacAddressAugmentation(matchEntriesBuilder, macAddress);
976         if (mask != null) {
977             hasmask = true;
978             addMaskAugmentation(matchEntriesBuilder, mask);
979         }
980         matchEntriesBuilder.setHasMask(hasmask);
981         return matchEntriesBuilder.build();
982     }
983
984     private static MatchEntries toOfEthernetType(EthernetType ethernetType) {
985         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
986         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
987         matchEntriesBuilder.setHasMask(false);
988         matchEntriesBuilder.setOxmMatchField(EthType.class);
989         EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
990         ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
991         matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
992         return matchEntriesBuilder.build();
993     }
994
995     private static MatchEntries toOfLayer3Port(Class<? extends MatchField> field,
996             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
997         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
998         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
999         matchEntriesBuilder.setHasMask(false);
1000         matchEntriesBuilder.setOxmMatchField(field);
1001         PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
1002         portBuilder.setPort(portNumber);
1003         matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
1004         return matchEntriesBuilder.build();
1005     }
1006
1007     private static MatchEntries toOfIcmpv4Type(Short icmpv4Type) {
1008         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1009         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1010         matchEntriesBuilder.setHasMask(false);
1011         matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1012         Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1013         icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1014         matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1015         return matchEntriesBuilder.build();
1016     }
1017
1018     private static MatchEntries toOfIcmpv4Code(Short icmpv4Code) {
1019         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1020         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1021         matchEntriesBuilder.setHasMask(false);
1022         matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1023         Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1024         icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1025         matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1026         return matchEntriesBuilder.build();
1027     }
1028
1029     private static MatchEntries toOfIcmpv6Type(Short icmpv6Type) {
1030         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1031         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1032         matchEntriesBuilder.setHasMask(false);
1033         matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1034         Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1035         icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1036         matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1037         return matchEntriesBuilder.build();
1038     }
1039
1040     private static MatchEntries toOfIcmpv6Code(Short icmpv6Code) {
1041         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1042         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1043         matchEntriesBuilder.setHasMask(false);
1044         matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1045         Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1046         icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1047         matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1048         return matchEntriesBuilder.build();
1049     }
1050
1051     private static MatchEntries toOfIpv4Prefix(Class<? extends MatchField> field, Ipv4Prefix ipv4Prefix) {
1052         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1053         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1054         matchEntriesBuilder.setOxmMatchField(field);
1055         boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1056         matchEntriesBuilder.setHasMask(hasMask);
1057         return matchEntriesBuilder.build();
1058     }
1059
1060     private static MatchEntries toOfIpv6Prefix(Class<? extends MatchField> field, Ipv6Prefix ipv6Prefix) {
1061         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1062         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1063         matchEntriesBuilder.setOxmMatchField(field);
1064         boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1065         matchEntriesBuilder.setHasMask(hasmask);
1066         return matchEntriesBuilder.build();
1067     }
1068
1069     private static MatchEntries toOfIpDscp(Dscp ipDscp) {
1070         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1071         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1072         matchEntriesBuilder.setHasMask(false);
1073         matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1074         DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1075         dscpBuilder.setDscp(ipDscp);
1076         matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1077         return matchEntriesBuilder.build();
1078     }
1079
1080     private static MatchEntries toOfVlanPcp(
1081             org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1082         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1083         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1084         matchEntriesBuilder.setHasMask(false);
1085         matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1086         VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1087         vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1088         matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1089         return matchEntriesBuilder.build();
1090     }
1091
1092     private static MatchEntries toOfVlanVid(VlanId vlanId) {
1093         // TODO: verify
1094         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1095         boolean hasmask = false;
1096         boolean setCfiBit = false;
1097         Integer vidEntryValue = 0;
1098         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1099         matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1100         VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1101         if (vlanId.isVlanIdPresent() == Boolean.TRUE) {
1102             setCfiBit = true;
1103             if (vlanId.getVlanId() != null) {
1104                 vidEntryValue = vlanId.getVlanId().getValue();
1105             }
1106             hasmask = (vidEntryValue == 0);
1107         }
1108         vlanVidBuilder.setCfiBit(setCfiBit);
1109         vlanVidBuilder.setVlanVid(vidEntryValue);
1110         matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1111         if (hasmask) {
1112             addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1113         }
1114         matchEntriesBuilder.setHasMask(hasmask);
1115         return matchEntriesBuilder.build();
1116     }
1117
1118     private static MatchEntries toOfIpProto(Short ipProtocol) {
1119         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1120         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1121         matchEntriesBuilder.setHasMask(false);
1122         matchEntriesBuilder.setOxmMatchField(IpProto.class);
1123         ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1124         protoNumberBuilder.setProtocolNumber(ipProtocol);
1125         matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1126         return matchEntriesBuilder.build();
1127     }
1128
1129     private static MatchEntries toOfIpEcn(Short ipEcn) {
1130         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1131         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1132         matchEntriesBuilder.setHasMask(false);
1133         matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1134         EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1135         ecnBuilder.setEcn(ipEcn);
1136         matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1137         return matchEntriesBuilder.build();
1138     }
1139
1140     private static MatchEntries toOfArpOpCode(Integer arpOp) {
1141         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1142         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1143         matchEntriesBuilder.setHasMask(false);
1144         matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1145         OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1146         opcodeBuilder.setOpCode(arpOp);
1147         matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1148         return matchEntriesBuilder.build();
1149     }
1150
1151     private static MatchEntries toOfIpv6Address(Ipv6Address address) {
1152         MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1153         matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1154         matchEntriesBuilder.setHasMask(false);
1155         matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1156         Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1157         ipv6AddressBuilder.setIpv6Address(address);
1158         matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1159         return matchEntriesBuilder.build();
1160     }
1161
1162     private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
1163         MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1164         maskBuilder.setMask(mask);
1165         builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1166     }
1167
1168     private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
1169         boolean hasMask = false;
1170         String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
1171         Integer prefix = null;
1172         if (addressParts.length == 2) {
1173             prefix = Integer.parseInt(addressParts[1]);
1174         }
1175
1176         Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
1177         Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1178         ipv6AddressBuilder.setIpv6Address(ipv6Address);
1179         builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1180         if (prefix != null) {
1181             hasMask = true;
1182             addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1183         }
1184         return hasMask;
1185     }
1186
1187     private static byte[] convertIpv6PrefixToByteArray(int prefix) {
1188         // TODO: Temporary fix. Has performance impacts.
1189         byte[] mask = new byte[16];
1190         int oneCount = prefix;
1191         for (int count = 0; count < 16; count++) {
1192             int byteBits = 0;
1193             if (oneCount >= 8) {
1194                 byteBits = 8;
1195                 oneCount = oneCount - 8;
1196             } else {
1197                 byteBits = oneCount;
1198                 oneCount = 0;
1199             }
1200
1201             mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1202         }
1203         return mask;
1204     }
1205
1206     private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
1207         MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1208         metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerTo64Bit(metadata));
1209         builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1210     }
1211
1212     /**
1213      * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1214      *         false otherwise
1215      */
1216     private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
1217         boolean hasMask = false;
1218         String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
1219         Integer prefix = null;
1220         if (addressParts.length < 2) {
1221             prefix = 0;
1222         } else {
1223             prefix = Integer.parseInt(addressParts[1]);
1224         }
1225
1226         Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
1227         Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1228         ipv4AddressBuilder.setIpv4Address(ipv4Address);
1229         builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1230         if (prefix != 0) {
1231             int mask = 0xffffffff << (32 - prefix);
1232             byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1233                     (byte) mask };
1234             addMaskAugmentation(builder, maskBytes);
1235             hasMask = true;
1236         }
1237         return hasMask;
1238     }
1239
1240     private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
1241         MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1242         macAddress.setMacAddress(address);
1243         builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1244     }
1245
1246     /**
1247      * Method converts OF SetField Match to SAL SetFiled matches
1248      * TODO: enable or delete
1249      * @param action
1250      * @return
1251      */
1252     public static SetField ofToSALSetField(
1253             org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
1254         logger.info("OF SetField match to SAL SetField match converstion begins");
1255         SetFieldBuilder setField = new SetFieldBuilder();
1256         /*
1257          * OxmFieldsAction oxmFields =
1258          * action.getAugmentation(OxmFieldsAction.class);
1259          *
1260          * List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
1261          * org.opendaylight
1262          * .yang.gen.v1.urn.opendaylight.action.types.rev131112.action
1263          * .action.set.field.MatchBuilder match =new
1264          * org.opendaylight.yang.gen.v1
1265          * .urn.opendaylight.action.types.rev131112.action
1266          * .action.set.field.MatchBuilder();
1267          *
1268          * EthernetMatchBuilder ethernetMatchBuilder = null; VlanMatchBuilder
1269          * vlanMatchBuilder = null; IpMatchBuilder ipMatchBuilder = null;
1270          * TcpMatchBuilder tcpMatchBuilder = null; UdpMatchBuilder
1271          * udpMatchBuilder = null; SctpMatchBuilder sctpMatchBuilder = null;
1272          * Icmpv4MatchBuilder icmpv4MatchBuilder = null; Icmpv6MatchBuilder
1273          * icmpv6MatchBuilder = null; Ipv4MatchBuilder ipv4MatchBuilder = null;
1274          * ArpMatchBuilder arpMatchBuilder = null; Ipv6MatchBuilder
1275          * ipv6MatchBuilder = null; ProtocolMatchFieldsBuilder
1276          * protocolMatchFieldsBuilder = null;
1277          *
1278          * for(MatchEntries matchEntry : matchEntries){ if(matchEntry instanceof
1279          * InPort){ PortNumberMatchEntry inPort =
1280          * matchEntry.getAugmentation(PortNumberMatchEntry.class);
1281          * match.setInPort(inPort.getPortNumber().getValue()); }else if
1282          * (matchEntry instanceof InPhyPort){ PortNumberMatchEntry phyPort =
1283          * matchEntry.getAugmentation(PortNumberMatchEntry.class);
1284          * match.setInPhyPort(phyPort.getPortNumber().getValue()); }else if
1285          * (matchEntry instanceof Metadata){ MetadataMatchEntry metadataMatch =
1286          * matchEntry.getAugmentation(MetadataMatchEntry.class); MetadataBuilder
1287          * metadataBuilder = new MetadataBuilder();
1288          * metadataBuilder.setMetadata(new
1289          * BigInteger(metadataMatch.getMetadata())); MaskMatchEntry maskMatch =
1290          * matchEntry.getAugmentation(MaskMatchEntry.class); if (maskMatch !=
1291          * null){ metadataBuilder.setMetadataMask(maskMatch.getMask()); }
1292          * match.setMetadata(metadataBuilder.build()); }else if (matchEntry
1293          * instanceof EthDst){
1294          *
1295          * if(ethernetMatchBuilder == null) ethernetMatchBuilder = new
1296          * EthernetMatchBuilder();
1297          *
1298          * MacAddressMatchEntry macAddressMatch =
1299          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1300          * MaskMatchEntry maskMatch =
1301          * matchEntry.getAugmentation(MaskMatchEntry.class);
1302          * EthernetDestinationBuilder ethernetDestination = new
1303          * EthernetDestinationBuilder();
1304          * ethernetDestination.setAddress(macAddressMatch.getMacAddress());
1305          * if(maskMatch != null){
1306          * ethernetDestination.setMask(maskMatch.getMask()); }
1307          * ethernetMatchBuilder
1308          * .setEthernetDestination(ethernetDestination.build()); }else if
1309          * (matchEntry instanceof EthSrc){ if(ethernetMatchBuilder == null)
1310          * ethernetMatchBuilder = new EthernetMatchBuilder();
1311          *
1312          * MacAddressMatchEntry macAddressMatch =
1313          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1314          * MaskMatchEntry maskMatch =
1315          * matchEntry.getAugmentation(MaskMatchEntry.class);
1316          * EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
1317          * ethernetSource.setAddress(macAddressMatch.getMacAddress());
1318          * if(maskMatch != null){ ethernetSource.setMask(maskMatch.getMask()); }
1319          * ethernetMatchBuilder.setEthernetSource(ethernetSource.build()); }else
1320          * if (matchEntry instanceof EthType){ if(ethernetMatchBuilder == null)
1321          * ethernetMatchBuilder = new EthernetMatchBuilder();
1322          *
1323          * EthTypeMatchEntry etherTypeMatch =
1324          * matchEntry.getAugmentation(EthTypeMatchEntry.class);
1325          * EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
1326          * org.opendaylight
1327          * .yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType etherType
1328          * = new
1329          * org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827
1330          * .EtherType((long)etherTypeMatch.getEthType().getValue());
1331          * ethernetType.setType(etherType);
1332          * ethernetMatchBuilder.setEthernetType(ethernetType.build()); }else if
1333          * (matchEntry instanceof VlanVid){ if(vlanMatchBuilder == null)
1334          * vlanMatchBuilder = new VlanMatchBuilder();
1335          *
1336          * VlanVidMatchEntry vlanVidMatch =
1337          * matchEntry.getAugmentation(VlanVidMatchEntry.class); MaskMatchEntry
1338          * maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
1339          *
1340          * VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
1341          * vlanIdBuilder.setVlanId( new
1342          * org.opendaylight.yang.gen.v1.urn.opendaylight
1343          * .l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid())); if(maskMatch
1344          * != null){ vlanIdBuilder.setMask(maskMatch.getMask()); }
1345          * vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
1346          *
1347          * }else if (matchEntry instanceof VlanPcp){ if(vlanMatchBuilder ==
1348          * null) vlanMatchBuilder = new VlanMatchBuilder();
1349          *
1350          * VlanPcpMatchEntry vlanPcpMatch =
1351          * matchEntry.getAugmentation(VlanPcpMatchEntry.class);
1352          * vlanMatchBuilder.setVlanPcp( new
1353          * org.opendaylight.yang.gen.v1.urn.opendaylight
1354          * .l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp())); }else if
1355          * (matchEntry instanceof IpDscp){ if(ipMatchBuilder == null)
1356          * ipMatchBuilder = new IpMatchBuilder();
1357          *
1358          * DscpMatchEntry dscpMatchEntry =
1359          * matchEntry.getAugmentation(DscpMatchEntry.class);
1360          * ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
1361          *
1362          * }else if (matchEntry instanceof IpEcn){ if(ipMatchBuilder == null)
1363          * ipMatchBuilder = new IpMatchBuilder();
1364          *
1365          * EcnMatchEntry ecnMatchEntry =
1366          * matchEntry.getAugmentation(EcnMatchEntry.class);
1367          * ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
1368          *
1369          * }else if (matchEntry instanceof IpProto){ if(ipMatchBuilder == null)
1370          * ipMatchBuilder = new IpMatchBuilder();
1371          *
1372          * ProtocolNumberMatchEntry protocolNumberMatch =
1373          * matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
1374          * ipMatchBuilder
1375          * .setIpProtocol(protocolNumberMatch.getProtocolNumber()); }else if
1376          * (matchEntry instanceof TcpSrc){ if(tcpMatchBuilder == null)
1377          * tcpMatchBuilder = new TcpMatchBuilder();
1378          *
1379          * PortMatchEntry portMatchEntry =
1380          * matchEntry.getAugmentation(PortMatchEntry.class);
1381          * tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
1382          *
1383          * }else if (matchEntry instanceof TcpDst){ if(tcpMatchBuilder == null)
1384          * tcpMatchBuilder = new TcpMatchBuilder();
1385          *
1386          * PortMatchEntry portMatchEntry =
1387          * matchEntry.getAugmentation(PortMatchEntry.class);
1388          * tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
1389          *
1390          * }else if (matchEntry instanceof UdpSrc){ if(udpMatchBuilder == null)
1391          * udpMatchBuilder = new UdpMatchBuilder();
1392          *
1393          * PortMatchEntry portMatchEntry =
1394          * matchEntry.getAugmentation(PortMatchEntry.class);
1395          * udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
1396          *
1397          *
1398          * }else if (matchEntry instanceof UdpDst){ if(udpMatchBuilder == null)
1399          * udpMatchBuilder = new UdpMatchBuilder();
1400          *
1401          * PortMatchEntry portMatchEntry =
1402          * matchEntry.getAugmentation(PortMatchEntry.class);
1403          * udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
1404          * }else if (matchEntry instanceof SctpSrc){ if(sctpMatchBuilder ==
1405          * null) sctpMatchBuilder = new SctpMatchBuilder();
1406          *
1407          * PortMatchEntry portMatchEntry =
1408          * matchEntry.getAugmentation(PortMatchEntry.class);
1409          * sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
1410          *
1411          * }else if (matchEntry instanceof SctpDst){ if(sctpMatchBuilder ==
1412          * null) sctpMatchBuilder = new SctpMatchBuilder();
1413          *
1414          * PortMatchEntry portMatchEntry =
1415          * matchEntry.getAugmentation(PortMatchEntry.class);
1416          * sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
1417          * }else if (matchEntry instanceof Icmpv4Type){ if(icmpv4MatchBuilder ==
1418          * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1419          *
1420          * Icmpv4TypeMatchEntry icmpv4TypeMatchEntry =
1421          * matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
1422          * icmpv4MatchBuilder
1423          * .setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
1424          *
1425          * }else if (matchEntry instanceof Icmpv4Code){ if(icmpv4MatchBuilder ==
1426          * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1427          *
1428          * Icmpv4CodeMatchEntry icmpv4CodeMatchEntry =
1429          * matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
1430          * icmpv4MatchBuilder
1431          * .setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
1432          *
1433          * }else if (matchEntry instanceof Icmpv6Type){ if(icmpv6MatchBuilder ==
1434          * null) icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1435          *
1436          * Icmpv6TypeMatchEntry icmpv6TypeMatchEntry =
1437          * matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
1438          * icmpv6MatchBuilder
1439          * .setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type()); }else if
1440          * (matchEntry instanceof Icmpv6Code){ if(icmpv6MatchBuilder == null)
1441          * icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1442          *
1443          * Icmpv6CodeMatchEntry icmpv6CodeMatchEntry =
1444          * matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
1445          * icmpv6MatchBuilder
1446          * .setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code()); }else if
1447          * (matchEntry instanceof Ipv4Src){ if(ipv4MatchBuilder == null)
1448          * ipv4MatchBuilder = new Ipv4MatchBuilder();
1449          *
1450          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1451          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1452          * MaskMatchEntry maskMatchEntry =
1453          * matchEntry.getAugmentation(MaskMatchEntry.class);
1454          * ipv4MatchBuilder.setIpv4Source( new
1455          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1456          * String(maskMatchEntry.getMask())));
1457          *
1458          * }else if (matchEntry instanceof Ipv4Dst){ if(ipv4MatchBuilder ==
1459          * null) ipv4MatchBuilder = new Ipv4MatchBuilder();
1460          *
1461          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1462          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1463          * MaskMatchEntry maskMatchEntry =
1464          * matchEntry.getAugmentation(MaskMatchEntry.class);
1465          * ipv4MatchBuilder.setIpv4Destination( new
1466          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1467          * String(maskMatchEntry.getMask()))); }else if (matchEntry instanceof
1468          * ArpOp){ if(arpMatchBuilder == null) arpMatchBuilder = new
1469          * ArpMatchBuilder();
1470          *
1471          * OpCodeMatchEntry opCodeMatchEntry =
1472          * matchEntry.getAugmentation(OpCodeMatchEntry.class);
1473          * arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
1474          *
1475          * }else if (matchEntry instanceof ArpSpa){ if(arpMatchBuilder == null)
1476          * arpMatchBuilder = new ArpMatchBuilder();
1477          *
1478          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1479          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1480          * MaskMatchEntry maskMatchEntry =
1481          * matchEntry.getAugmentation(MaskMatchEntry.class);
1482          * arpMatchBuilder.setArpSourceTransportAddress( new
1483          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1484          * String(maskMatchEntry.getMask())));
1485          *
1486          * }else if (matchEntry instanceof ArpTpa){ if(arpMatchBuilder == null)
1487          * arpMatchBuilder = new ArpMatchBuilder();
1488          *
1489          * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1490          * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1491          * MaskMatchEntry maskMatchEntry =
1492          * matchEntry.getAugmentation(MaskMatchEntry.class);
1493          * arpMatchBuilder.setArpTargetTransportAddress( new
1494          * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1495          * String(maskMatchEntry.getMask())));
1496          *
1497          * }else if (matchEntry instanceof ArpSha){ if(arpMatchBuilder == null)
1498          * arpMatchBuilder = new ArpMatchBuilder();
1499          *
1500          * MacAddressMatchEntry macAddressMatchEntry =
1501          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1502          * MaskMatchEntry maskMatchEntry =
1503          * matchEntry.getAugmentation(MaskMatchEntry.class);
1504          * ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new
1505          * ArpSourceHardwareAddressBuilder();
1506          * arpSourceHardwareAddressBuilder.setAddress
1507          * (macAddressMatchEntry.getMacAddress());
1508          * arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1509          * arpMatchBuilder
1510          * .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
1511          * .build());
1512          *
1513          * }else if (matchEntry instanceof ArpTha){ if(arpMatchBuilder == null)
1514          * arpMatchBuilder = new ArpMatchBuilder();
1515          *
1516          * MacAddressMatchEntry macAddressMatchEntry =
1517          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1518          * MaskMatchEntry maskMatchEntry =
1519          * matchEntry.getAugmentation(MaskMatchEntry.class);
1520          * ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new
1521          * ArpTargetHardwareAddressBuilder();
1522          * arpTargetHardwareAddressBuilder.setAddress
1523          * (macAddressMatchEntry.getMacAddress());
1524          * arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1525          * arpMatchBuilder
1526          * .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
1527          * .build()); }else if (matchEntry instanceof Ipv6Src){
1528          * if(ipv6MatchBuilder == null) ipv6MatchBuilder = new
1529          * Ipv6MatchBuilder();
1530          *
1531          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1532          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1533          * MaskMatchEntry maskMatchEntry =
1534          * matchEntry.getAugmentation(MaskMatchEntry.class);
1535          * ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix
1536          * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1537          * String(maskMatchEntry.getMask())));
1538          *
1539          * }else if (matchEntry instanceof Ipv6Dst){ if(ipv6MatchBuilder ==
1540          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1541          *
1542          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1543          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1544          * MaskMatchEntry maskMatchEntry =
1545          * matchEntry.getAugmentation(MaskMatchEntry.class);
1546          * ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix
1547          * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1548          * String(maskMatchEntry.getMask())));
1549          *
1550          * }else if (matchEntry instanceof Ipv6Flabel){ if(ipv6MatchBuilder ==
1551          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1552          *
1553          * Ipv6FlabelMatchEntry ipv6FlabelMatchEntry =
1554          * matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
1555          * MaskMatchEntry maskMatchEntry =
1556          * matchEntry.getAugmentation(MaskMatchEntry.class); Ipv6LabelBuilder
1557          * ipv6LabelBuilder = new Ipv6LabelBuilder();
1558          * ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
1559          * ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
1560          * ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1561          *
1562          * }else if (matchEntry instanceof Ipv6NdTarget){ if(ipv6MatchBuilder ==
1563          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1564          * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1565          * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1566          * ipv6MatchBuilder
1567          * .setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
1568          *
1569          * }else if (matchEntry instanceof Ipv6NdSll){ if(ipv6MatchBuilder ==
1570          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1571          *
1572          * MacAddressMatchEntry macAddressMatchEntry =
1573          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1574          * ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
1575          * }else if (matchEntry instanceof Ipv6NdTll){ if(ipv6MatchBuilder ==
1576          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1577          *
1578          * MacAddressMatchEntry macAddressMatchEntry =
1579          * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1580          * ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
1581          *
1582          * }else if (matchEntry instanceof Ipv6Exthdr){ if(ipv6MatchBuilder ==
1583          * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1584          *
1585          * PseudoFieldMatchEntry pseudoFieldMatchEntry =
1586          * matchEntry.getAugmentation(PseudoFieldMatchEntry.class); PseudoField
1587          * pseudoField = pseudoFieldMatchEntry.getPseudoField(); int
1588          * pseudoFieldInt = 0; pseudoFieldInt |= pseudoField.isNonext()?(1 <<
1589          * 0):~(1 << 0); pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 <<
1590          * 1); pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
1591          * pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
1592          * pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
1593          * pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
1594          * pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
1595          * pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
1596          * pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
1597          *
1598          * ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt); }else if (matchEntry
1599          * instanceof MplsLabel){ if(protocolMatchFieldsBuilder == null)
1600          * protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1601          *
1602          * MplsLabelMatchEntry MplsLabelMatchEntry =
1603          * matchEntry.getAugmentation(MplsLabelMatchEntry.class);
1604          * protocolMatchFieldsBuilder
1605          * .setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
1606          *
1607          * }else if (matchEntry instanceof MplsBos){
1608          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1609          * new ProtocolMatchFieldsBuilder();
1610          *
1611          * BosMatchEntry bosMatchEntry =
1612          * matchEntry.getAugmentation(BosMatchEntry.class);
1613          * protocolMatchFieldsBuilder
1614          * .setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
1615          *
1616          * }else if (matchEntry instanceof MplsTc) {
1617          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1618          * new ProtocolMatchFieldsBuilder();
1619          *
1620          * TcMatchEntry tcMatchEntry =
1621          * matchEntry.getAugmentation(TcMatchEntry.class);
1622          * protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
1623          *
1624          * }else if (matchEntry instanceof PbbIsid){
1625          * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1626          * new ProtocolMatchFieldsBuilder();
1627          *
1628          * IsidMatchEntry isidMatchEntry =
1629          * matchEntry.getAugmentation(IsidMatchEntry.class); PbbBuilder
1630          * pbbBuilder = new PbbBuilder();
1631          * pbbBuilder.setPbbIsid(isidMatchEntry.getIsid()); MaskMatchEntry
1632          * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1633          * if(maskMatchEntry != null)
1634          * pbbBuilder.setPbbMask(maskMatchEntry.getMask());
1635          *
1636          * protocolMatchFieldsBuilder.setPbb(pbbBuilder.build()); }else if
1637          * (matchEntry instanceof TunnelId){ MetadataMatchEntry
1638          * metadataMatchEntry =
1639          * matchEntry.getAugmentation(MetadataMatchEntry.class); MaskMatchEntry
1640          * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1641          * TunnelBuilder tunnelBuilder = new TunnelBuilder();
1642          * tunnelBuilder.setTunnelId(new
1643          * BigInteger(metadataMatchEntry.getMetadata()));
1644          * tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
1645          * match.setTunnel(tunnelBuilder.build()); } } if(ethernetMatchBuilder
1646          * != null){ match.setEthernetMatch(ethernetMatchBuilder.build()); } if
1647          * (vlanMatchBuilder != null){
1648          * match.setVlanMatch(vlanMatchBuilder.build()); } if(ipMatchBuilder !=
1649          * null){ match.setIpMatch(ipMatchBuilder.build()); } if(tcpMatchBuilder
1650          * != null){ match.setLayer4Match(tcpMatchBuilder.build()); }
1651          * if(udpMatchBuilder != null){
1652          * match.setLayer4Match(udpMatchBuilder.build()); } if(sctpMatchBuilder
1653          * != null){ match.setLayer4Match(sctpMatchBuilder.build()); }
1654          * if(icmpv4MatchBuilder != null){
1655          * match.setIcmpv4Match(icmpv4MatchBuilder.build()); }
1656          * if(icmpv6MatchBuilder != null){
1657          * match.setIcmpv6Match(icmpv6MatchBuilder.build()); }
1658          * if(ipv4MatchBuilder != null){
1659          * match.setLayer3Match(ipv4MatchBuilder.build()); } if(arpMatchBuilder
1660          * != null){ match.setLayer3Match(arpMatchBuilder.build()); }
1661          * if(ipv6MatchBuilder != null){
1662          * match.setLayer3Match(ipv6MatchBuilder.build()); }
1663          * if(protocolMatchFieldsBuilder != null){
1664          * match.setProtocolMatchFields(protocolMatchFieldsBuilder.build()); }
1665          * setField.setMatch(match.build());
1666          */return setField.build();
1667     }
1668 }