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