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.OxmFieldsAction;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntryBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
182 import org.slf4j.Logger;
183 import org.slf4j.LoggerFactory;
185 import com.google.common.base.Splitter;
188 * Utility class for converting a MD-SAL Flow into the OF flow mod
190 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
191 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
192 static final String PREFIX_SEPARATOR = "/";
193 static final Splitter PREFIX_SPLITTER = Splitter.on('/');
194 private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
195 private static final short PROTO_TCP = 6;
196 private static final short PROTO_UDP = 17;
197 private static final String noIp = "0.0.0.0/0";
200 public List<MatchEntries> convert(
201 final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
202 List<MatchEntries> matchEntriesList = new ArrayList<>();
204 if (match.getInPort() != null) {
205 matchEntriesList.add(toOfPort(InPort.class,
206 InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPort())));
209 if (match.getInPhyPort() != null) {
210 matchEntriesList.add(toOfPort(InPhyPort.class,
211 InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPhyPort())));
214 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
216 if (metadata != null) {
217 matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
220 EthernetMatch ethernetMatch = match.getEthernetMatch();
221 if (ethernetMatch != null) {
222 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
223 if (ethernetDestination != null) {
224 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
225 ethernetDestination.getMask()));
228 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
229 if (ethernetSource != null) {
231 .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
234 if (ethernetMatch.getEthernetType() != null) {
235 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
239 VlanMatch vlanMatch = match.getVlanMatch();
240 if (vlanMatch != null) {
241 if (vlanMatch.getVlanId() != null) {
242 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
245 if (vlanMatch.getVlanPcp() != null) {
246 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
250 IpMatch ipMatch = match.getIpMatch();
251 if (ipMatch != null) {
252 if (ipMatch.getIpDscp() != null) {
253 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
256 if (ipMatch.getIpEcn() != null) {
257 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
260 if (ipMatch.getIpProtocol() != null) {
261 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
266 Layer4Match layer4Match = match.getLayer4Match();
267 if (layer4Match != null) {
268 if (layer4Match instanceof TcpMatch) {
269 TcpMatch tcpMatch = (TcpMatch) layer4Match;
270 if (tcpMatch.getTcpSourcePort() != null) {
271 matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
274 if (tcpMatch.getTcpDestinationPort() != null) {
275 matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
277 } else if (layer4Match instanceof UdpMatch) {
278 UdpMatch udpMatch = (UdpMatch) layer4Match;
279 if (udpMatch.getUdpSourcePort() != null) {
280 matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
283 if (udpMatch.getUdpDestinationPort() != null) {
284 matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
286 } else if (layer4Match instanceof SctpMatch) {
287 SctpMatch sctpMatch = (SctpMatch) layer4Match;
288 if (sctpMatch.getSctpSourcePort() != null) {
289 matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
292 if (sctpMatch.getSctpDestinationPort() != null) {
293 matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
298 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
299 if (icmpv4Match != null) {
300 if (icmpv4Match.getIcmpv4Type() != null) {
301 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
304 if (icmpv4Match.getIcmpv4Code() != null) {
305 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
309 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
310 if (icmpv6Match != null) {
311 if (icmpv6Match.getIcmpv6Type() != null) {
312 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
315 if (icmpv6Match.getIcmpv6Code() != null) {
316 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
320 Layer3Match layer3Match = match.getLayer3Match();
321 if (layer3Match != null) {
322 if (layer3Match instanceof Ipv4Match) {
323 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
324 if (ipv4Match.getIpv4Source() != null) {
325 matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
327 if (ipv4Match.getIpv4Destination() != null) {
328 matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
330 } else if (layer3Match instanceof ArpMatch) {
331 ArpMatch arpMatch = (ArpMatch) layer3Match;
332 if (arpMatch.getArpOp() != null) {
333 matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
336 if (arpMatch.getArpSourceTransportAddress() != null) {
337 matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
340 if (arpMatch.getArpTargetTransportAddress() != null) {
341 matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
344 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
345 if (arpSourceHardwareAddress != null) {
346 matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
347 arpSourceHardwareAddress.getMask()));
350 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
351 if (arpTargetHardwareAddress != null) {
352 matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
353 arpTargetHardwareAddress.getMask()));
357 else if (layer3Match instanceof Ipv6Match) {
358 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
359 if (ipv6Match.getIpv6Source() != null) {
360 matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
363 if (ipv6Match.getIpv6Destination() != null) {
364 matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
367 if (ipv6Match.getIpv6Label() != null) {
368 matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
371 if (ipv6Match.getIpv6NdTarget() != null) {
372 matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
375 if (ipv6Match.getIpv6NdSll() != null) {
376 matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
379 if (ipv6Match.getIpv6NdTll() != null) {
380 matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
383 if (ipv6Match.getIpv6ExtHeader() != null) {
384 matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
389 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
390 if (protocolMatchFields != null) {
391 if (protocolMatchFields.getMplsLabel() != null) {
392 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
395 if (protocolMatchFields.getMplsBos() != null) {
396 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
399 if (protocolMatchFields.getMplsTc() != null) {
400 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
403 if (protocolMatchFields.getPbb() != null) {
404 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
408 //FIXME: move to extensible support
409 TcpFlagMatch tcpFlagMatch = match.getTcpFlagMatch();
410 if (tcpFlagMatch != null) {
411 if (tcpFlagMatch.getTcpFlag() != null) {
412 matchEntriesList.add(toOfTcpFlag(tcpFlagMatch.getTcpFlag()));
416 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
418 if (tunnel != null) {
419 matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
422 return matchEntriesList;
426 * Method convert Openflow 1.0 specific flow match to MD-SAL format flow
431 * @author avishnoi@in.ibm.com
433 public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid) {
434 MatchBuilder matchBuilder = new MatchBuilder();
435 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
436 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
437 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
438 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
439 if (!swMatch.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
440 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
441 (long) swMatch.getInPort()));
444 if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
445 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
446 ethSrcBuilder.setAddress(swMatch.getDlSrc());
447 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
448 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
450 if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
451 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
452 ethDstBuilder.setAddress(swMatch.getDlDst());
453 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
454 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
456 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
457 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
458 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
459 (long) swMatch.getDlType()));
460 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
461 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
463 if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
464 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
465 int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
466 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
467 vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false: true);
468 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
469 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
471 if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp() != null) {
472 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
473 swMatch.getDlVlanPcp()));
474 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
476 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
477 String ipv4PrefixStr = swMatch.getNwSrc().getValue();
478 if (swMatch.getNwSrcMask() != null) {
479 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
481 if (!ipv4PrefixStr.equals(noIp)) {
482 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
483 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
486 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
487 String ipv4PrefixStr = swMatch.getNwDst().getValue();
488 if (swMatch.getNwDstMask() != null) {
489 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
491 if (!ipv4PrefixStr.equals(noIp)) {
492 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
493 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
496 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
497 ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
498 matchBuilder.setIpMatch(ipMatchBuilder.build());
500 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
501 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
502 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
504 .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
505 swMatch.getTpSrc()));
507 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
509 .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
510 swMatch.getTpDst()));
513 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
514 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
517 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
518 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
519 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
521 .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
522 swMatch.getTpSrc()));
524 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
526 .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
527 swMatch.getTpDst()));
530 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
531 matchBuilder.setLayer4Match(udpMatchBuilder.build());
534 if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
535 // DSCP default value is 0 from the library but controller side it
537 // look if there better solution
538 if (0 != swMatch.getNwTos()) {
539 ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
541 matchBuilder.setIpMatch(ipMatchBuilder.build());
544 return matchBuilder.build();
548 * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
553 * @author avishnoi@in.ibm.com
555 public static Match fromOFMatchToSALMatch(
556 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch,
557 final BigInteger datapathid) {
559 return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid);
563 private static Match OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid){
565 MatchBuilder matchBuilder = new MatchBuilder();
566 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
567 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
568 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
569 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
570 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
571 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
572 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
573 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
574 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
575 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
576 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
577 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
578 TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
580 for (MatchEntries ofMatch : swMatchList) {
582 if (ofMatch.getOxmMatchField().equals(InPort.class)) {
583 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
584 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
585 portNumber.getPortNumber().getValue()));
586 } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
587 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
588 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
589 portNumber.getPortNumber().getValue()));
590 } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
591 MetadataBuilder metadataBuilder = new MetadataBuilder();
592 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
593 if (metadataMatchEntry != null) {
594 metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
595 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
596 if (maskMatchEntry != null) {
597 metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
600 matchBuilder.setMetadata(metadataBuilder.build());
602 } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
603 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
604 if (macAddressMatchEntry != null) {
605 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
606 ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
607 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
608 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
610 } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
611 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
612 if (macAddressMatchEntry != null) {
613 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
614 ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
615 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
616 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
618 } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
619 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
620 if (ethTypeMatchEntry != null) {
621 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
623 .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
624 (long) ethTypeMatchEntry.getEthType().getValue()));
625 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
626 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
628 } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
629 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
630 if (vlanVidMatchEntry != null) {
631 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
632 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
633 vlanVidMatchEntry.getVlanVid()));
634 vlanMatchBuilder.setVlanId(vlanBuilder.build());
635 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
637 } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
638 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
639 if (vlanPcpMatchEntry != null) {
641 .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
642 vlanPcpMatchEntry.getVlanPcp()));
643 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
645 } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
646 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
647 if (dscpMatchEntry != null) {
648 ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
649 matchBuilder.setIpMatch(ipMatchBuilder.build());
651 } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
652 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
653 if (ecnMatchEntry != null) {
654 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
655 matchBuilder.setIpMatch(ipMatchBuilder.build());
657 } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
658 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch
659 .getAugmentation(ProtocolNumberMatchEntry.class);
660 if (protocolNumberMatchEntry != null) {
661 ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
662 matchBuilder.setIpMatch(ipMatchBuilder.build());
664 } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
665 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
666 if (portMatchEntry != null) {
667 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
668 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
670 } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
671 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
672 if (portMatchEntry != null) {
673 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
674 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
676 } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
677 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
678 if (portMatchEntry != null) {
679 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
680 matchBuilder.setLayer4Match(udpMatchBuilder.build());
682 } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
683 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
684 if (portMatchEntry != null) {
685 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
686 matchBuilder.setLayer4Match(udpMatchBuilder.build());
688 } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
689 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
690 if (portMatchEntry != null) {
691 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
692 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
694 } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
695 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
696 if (portMatchEntry != null) {
697 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
698 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
700 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
701 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
702 if (icmpv4TypeMatchEntry != null) {
703 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
704 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
706 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
707 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
708 if (icmpv4CodeMatchEntry != null) {
709 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
710 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
712 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
713 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
714 if (icmpv6TypeMatchEntry != null) {
715 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
716 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
718 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
719 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
720 if (icmpv6CodeMatchEntry != null) {
721 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
722 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
724 } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)
725 || ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
726 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
727 if (ipv4AddressMatchEntry != null) {
728 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
729 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
730 if (maskMatchEntry != null) {
731 int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
733 while(receivedMask != 0xffffffff){
734 receivedMask = receivedMask >> 1;
737 ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount);
739 //Openflow Spec : 1.3.2
740 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
741 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
742 // statistics response.
744 ipv4PrefixStr+=PREFIX_SEPARATOR + "32";
746 if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
747 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
749 if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
750 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
752 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
754 } else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
755 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
756 if (opCodeMatchEntry != null) {
757 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
758 matchBuilder.setLayer3Match(arpMatchBuilder.build());
760 } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)
761 || ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
762 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
763 if (ipv4AddressMatchEntry != null) {
764 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
765 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
766 if (maskMatchEntry != null) {
767 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
769 if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
770 arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
772 if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
773 arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
775 matchBuilder.setLayer3Match(arpMatchBuilder.build());
777 } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)
778 || ofMatch.getOxmMatchField().equals(ArpTha.class)) {
779 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
780 if (macAddressMatchEntry != null) {
781 if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
782 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
783 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
784 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
785 if (maskMatchEntry != null) {
786 arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
787 .macAddressToString(maskMatchEntry.getMask())));
789 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
790 matchBuilder.setLayer3Match(arpMatchBuilder.build());
792 if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
793 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
794 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
795 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
796 if (maskMatchEntry != null) {
797 arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
798 .macAddressToString(maskMatchEntry.getMask())));
800 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
801 matchBuilder.setLayer3Match(arpMatchBuilder.build());
804 } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)
805 || ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
806 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
807 if (ipv6AddressMatchEntry != null) {
808 String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
809 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
810 if(maskMatchEntry != null){
811 ipv6PrefixStr += PREFIX_SEPARATOR
812 + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
815 if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
816 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
818 if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
819 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
821 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
823 } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
824 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
825 if (ipv6FlabelMatchEntry != null) {
826 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
827 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
828 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
829 if (maskMatchEntry != null) {
830 ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(new Long(ByteUtil
831 .bytesToUnsignedInt(maskMatchEntry.getMask()))));
833 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
834 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
836 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
837 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
838 if (ipv6AddressMatchEntry != null) {
839 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
840 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
842 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
843 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
844 if (macAddressMatchEntry != null) {
845 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
846 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
848 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
849 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
850 if (macAddressMatchEntry != null) {
851 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
852 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
854 } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
855 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
856 if (pseudoFieldMatchEntry != null) {
857 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
859 Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
860 Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
862 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
863 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
864 if (maskMatchEntry != null) {
865 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(maskMatchEntry.getMask()));
867 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
868 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
870 } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
871 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
872 if (mplsLabelMatchEntry != null) {
873 protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
874 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
876 } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
877 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
878 if (bosMatchEntry != null) {
879 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos() ? (short) 1 : (short) 0);
880 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
882 } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
883 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
884 if (tcMatchEntry != null) {
885 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
886 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
888 } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
889 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
890 if (isidMatchEntry != null) {
891 PbbBuilder pbbBuilder = new PbbBuilder();
892 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
893 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
894 if (maskMatchEntry != null) {
895 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedInt(maskMatchEntry.getMask()));
897 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
898 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
900 } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
901 TunnelBuilder tunnelBuilder = new TunnelBuilder();
902 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
903 if (metadataMatchEntry != null) {
904 tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
905 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
906 if (maskMatchEntry != null) {
907 tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
910 matchBuilder.setTunnel(tunnelBuilder.build());
912 } else if (ofMatch.getOxmMatchField().equals(TcpFlag.class)) {
913 //FIXME: move to extensible support
914 TcpFlagMatchEntry tcpFlagMatch = ofMatch.getAugmentation(TcpFlagMatchEntry.class);
915 if (tcpFlagMatch != null) {
916 tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
917 matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
921 return matchBuilder.build();
923 private static MatchEntries toOfMplsPbb(final Pbb pbb) {
924 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
925 boolean hasmask = false;
926 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
927 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
928 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
929 isidBuilder.setIsid(pbb.getPbbIsid());
930 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
931 if (pbb.getPbbMask() != null) {
933 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(pbb.getPbbMask()));
935 matchEntriesBuilder.setHasMask(hasmask);
936 return matchEntriesBuilder.build();
939 private static MatchEntries toOfMplsTc(final Short mplsTc) {
940 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
941 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
942 matchEntriesBuilder.setHasMask(false);
943 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
944 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
945 tcBuilder.setTc(mplsTc);
946 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
947 return matchEntriesBuilder.build();
950 private static MatchEntries toOfMplsBos(final Short mplsBos) {
951 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
952 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
953 matchEntriesBuilder.setHasMask(false);
954 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
955 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
957 bosBuilder.setBos(true);
959 bosBuilder.setBos(false);
961 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
962 return matchEntriesBuilder.build();
965 private static MatchEntries toOfMplsLabel(final Long mplsLabel) {
966 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
967 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
968 matchEntriesBuilder.setHasMask(false);
969 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
970 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
971 mplsLabelBuilder.setMplsLabel(mplsLabel);
972 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
973 return matchEntriesBuilder.build();
976 private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
977 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
978 boolean hasmask = false;
979 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
980 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
981 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
982 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
983 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
984 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
985 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
986 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
987 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
988 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
989 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
990 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
991 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
992 pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
993 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
994 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
996 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
998 matchEntriesBuilder.setHasMask(hasmask);
999 return matchEntriesBuilder.build();
1002 private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
1003 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1004 boolean hasmask = false;
1005 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1006 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
1007 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
1008 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
1009 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
1010 if (ipv6Label.getFlabelMask() != null) {
1012 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
1014 matchEntriesBuilder.setHasMask(hasmask);
1015 return matchEntriesBuilder.build();
1018 private static MatchEntries toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
1019 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1020 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1021 matchEntriesBuilder.setHasMask(false);
1022 matchEntriesBuilder.setOxmMatchField(field);
1023 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
1024 port.setPortNumber(new PortNumber(portNumber));
1025 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
1026 return matchEntriesBuilder.build();
1029 private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
1030 final BigInteger metadataMask) {
1031 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1032 boolean hasmask = false;
1033 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1034 matchEntriesBuilder.setOxmMatchField(field);
1035 addMetadataAugmentation(matchEntriesBuilder, metadata);
1036 if (metadataMask != null) {
1038 addMaskAugmentation(matchEntriesBuilder,
1039 ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
1041 matchEntriesBuilder.setHasMask(hasmask);
1042 return matchEntriesBuilder.build();
1045 public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
1046 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
1047 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
1048 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1049 boolean hasmask = false;
1050 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1051 matchEntriesBuilder.setOxmMatchField(field);
1052 addMacAddressAugmentation(matchEntriesBuilder, macAddress);
1055 addMaskAugmentation(matchEntriesBuilder, ByteBufUtils.macAddressToBytes(mask.getValue()));
1057 matchEntriesBuilder.setHasMask(hasmask);
1058 return matchEntriesBuilder.build();
1061 private static MatchEntries toOfEthernetType(final EthernetType ethernetType) {
1062 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1063 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1064 matchEntriesBuilder.setHasMask(false);
1065 matchEntriesBuilder.setOxmMatchField(EthType.class);
1066 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
1067 ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
1068 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
1069 return matchEntriesBuilder.build();
1072 private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
1073 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
1074 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1075 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1076 matchEntriesBuilder.setHasMask(false);
1077 matchEntriesBuilder.setOxmMatchField(field);
1078 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
1079 portBuilder.setPort(portNumber);
1080 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
1081 return matchEntriesBuilder.build();
1084 private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) {
1085 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1086 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1087 matchEntriesBuilder.setHasMask(false);
1088 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1089 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1090 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1091 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1092 return matchEntriesBuilder.build();
1095 private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) {
1096 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1097 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1098 matchEntriesBuilder.setHasMask(false);
1099 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1100 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1101 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1102 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1103 return matchEntriesBuilder.build();
1106 private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) {
1107 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1108 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1109 matchEntriesBuilder.setHasMask(false);
1110 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1111 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1112 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1113 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1114 return matchEntriesBuilder.build();
1117 private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) {
1118 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1119 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1120 matchEntriesBuilder.setHasMask(false);
1121 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1122 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1123 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1124 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1125 return matchEntriesBuilder.build();
1128 public static MatchEntries toOfIpv4Prefix(final Class<? extends MatchField> field, final Ipv4Prefix ipv4Prefix) {
1129 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1130 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1131 matchEntriesBuilder.setOxmMatchField(field);
1132 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1133 matchEntriesBuilder.setHasMask(hasMask);
1134 return matchEntriesBuilder.build();
1137 private static MatchEntries toOfIpv6Prefix(final Class<? extends MatchField> field, final Ipv6Prefix ipv6Prefix) {
1138 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1139 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1140 matchEntriesBuilder.setOxmMatchField(field);
1141 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1142 matchEntriesBuilder.setHasMask(hasmask);
1143 return matchEntriesBuilder.build();
1146 public static MatchEntries toOfIpDscp(final Dscp ipDscp) {
1147 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1148 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1149 matchEntriesBuilder.setHasMask(false);
1150 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1151 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1152 dscpBuilder.setDscp(ipDscp);
1153 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1154 return matchEntriesBuilder.build();
1157 public static MatchEntries toOfVlanPcp(
1158 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1159 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1160 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1161 matchEntriesBuilder.setHasMask(false);
1162 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1163 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1164 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1165 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1166 return matchEntriesBuilder.build();
1169 private static MatchEntries toOfVlanVid(final VlanId vlanId) {
1171 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1172 boolean hasmask = false;
1173 boolean setCfiBit = false;
1174 Integer vidEntryValue = 0;
1175 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1176 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1177 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1178 if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
1180 if (vlanId.getVlanId() != null) {
1181 vidEntryValue = vlanId.getVlanId().getValue();
1183 hasmask = (vidEntryValue == 0);
1185 vlanVidBuilder.setCfiBit(setCfiBit);
1186 vlanVidBuilder.setVlanVid(vidEntryValue);
1187 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1189 addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1191 matchEntriesBuilder.setHasMask(hasmask);
1192 return matchEntriesBuilder.build();
1195 private static MatchEntries toOfIpProto(final Short ipProtocol) {
1196 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1197 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1198 matchEntriesBuilder.setHasMask(false);
1199 matchEntriesBuilder.setOxmMatchField(IpProto.class);
1200 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1201 protoNumberBuilder.setProtocolNumber(ipProtocol);
1202 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1203 return matchEntriesBuilder.build();
1206 private static MatchEntries toOfIpEcn(final Short ipEcn) {
1207 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1208 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1209 matchEntriesBuilder.setHasMask(false);
1210 matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1211 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1212 ecnBuilder.setEcn(ipEcn);
1213 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1214 return matchEntriesBuilder.build();
1217 private static MatchEntries toOfArpOpCode(final Integer arpOp) {
1218 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1219 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1220 matchEntriesBuilder.setHasMask(false);
1221 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1222 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1223 opcodeBuilder.setOpCode(arpOp);
1224 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1225 return matchEntriesBuilder.build();
1228 private static MatchEntries toOfIpv6Address(final Ipv6Address address) {
1229 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1230 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1231 matchEntriesBuilder.setHasMask(false);
1232 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1233 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1234 ipv6AddressBuilder.setIpv6Address(address);
1235 matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1236 return matchEntriesBuilder.build();
1239 //FIXME: move to extensible support
1240 private static MatchEntries toOfTcpFlag(Integer tcpFlag) {
1241 MatchEntriesBuilder matchBuilder = new MatchEntriesBuilder();
1242 matchBuilder.setOxmClass(Nxm1Class.class);
1243 matchBuilder.setHasMask(false);
1244 matchBuilder.setOxmMatchField(TcpFlag.class);
1245 TcpFlagMatchEntryBuilder tcpFlagBuilder = new TcpFlagMatchEntryBuilder();
1246 tcpFlagBuilder.setTcpFlag(tcpFlag);
1247 matchBuilder.addAugmentation(TcpFlagMatchEntry.class, tcpFlagBuilder.build());
1248 return matchBuilder.build();
1251 private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) {
1252 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1253 maskBuilder.setMask(mask);
1254 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1257 private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) {
1258 boolean hasMask = false;
1259 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1260 Ipv6Address ipv6Address = new Ipv6Address(addressParts.next());
1262 Integer prefix = null;
1263 if (addressParts.hasNext()) {
1264 prefix = Integer.parseInt(addressParts.next());
1267 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1268 ipv6AddressBuilder.setIpv6Address(ipv6Address);
1269 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1270 if (prefix != null) {
1272 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1277 private static byte[] convertIpv6PrefixToByteArray(final int prefix) {
1278 // TODO: Temporary fix. Has performance impacts.
1279 byte[] mask = new byte[16];
1280 int oneCount = prefix;
1281 for (int count = 0; count < 16; count++) {
1283 if (oneCount >= 8) {
1285 oneCount = oneCount - 8;
1287 byteBits = oneCount;
1291 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1296 private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) {
1297 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1298 metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
1299 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1303 * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1306 private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
1307 boolean hasMask = false;
1308 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1309 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
1312 if (addressParts.hasNext()) {
1313 prefix = Integer.parseInt(addressParts.next());
1318 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1319 ipv4AddressBuilder.setIpv4Address(ipv4Address);
1320 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1322 int mask = 0xffffffff << (32 - prefix);
1323 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1325 addMaskAugmentation(builder, maskBytes);
1331 private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) {
1332 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1333 macAddress.setMacAddress(address);
1334 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1338 * Method converts OF SetField action to SAL SetFiled action.
1343 public static SetField fromOFSetFieldToSALSetFieldAction(
1344 final Action action) {
1345 logger.debug("Converting OF SetField action to SAL SetField action");
1346 SetFieldBuilder setField = new SetFieldBuilder();
1347 OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
1348 Match match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntries(), null);
1349 setField.fieldsFrom(match);
1350 return setField.build();