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