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