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