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