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.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.openflowplugin.openflow.md.util.OpenflowVersion;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatch;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
185 import org.slf4j.Logger;
186 import org.slf4j.LoggerFactory;
188 import com.google.common.base.Splitter;
191 * Utility class for converting a MD-SAL Flow into the OF flow mod
193 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
194 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
195 static final String PREFIX_SEPARATOR = "/";
196 static final Splitter PREFIX_SPLITTER = Splitter.on('/');
197 private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
198 private static final short PROTO_TCP = 6;
199 private static final short PROTO_UDP = 17;
200 private static final String noIp = "0.0.0.0/0";
203 public List<MatchEntries> convert(
204 final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
205 List<MatchEntries> matchEntriesList = new ArrayList<>();
206 if (match == null) return matchEntriesList;
207 if (match.getInPort() != null) {
208 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
209 matchEntriesList.add(toOfPort(InPort.class,
210 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPort())));
213 if (match.getInPhyPort() != null) {
214 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
215 matchEntriesList.add(toOfPort(InPhyPort.class,
216 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPhyPort())));
219 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
221 if (metadata != null) {
222 matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
225 EthernetMatch ethernetMatch = match.getEthernetMatch();
226 if (ethernetMatch != null) {
227 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
228 if (ethernetDestination != null) {
229 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
230 ethernetDestination.getMask()));
233 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
234 if (ethernetSource != null) {
236 .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
239 if (ethernetMatch.getEthernetType() != null) {
240 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
244 VlanMatch vlanMatch = match.getVlanMatch();
245 if (vlanMatch != null) {
246 if (vlanMatch.getVlanId() != null) {
247 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
250 if (vlanMatch.getVlanPcp() != null) {
251 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
255 IpMatch ipMatch = match.getIpMatch();
256 if (ipMatch != null) {
257 if (ipMatch.getIpDscp() != null) {
258 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
261 if (ipMatch.getIpEcn() != null) {
262 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
265 if (ipMatch.getIpProtocol() != null) {
266 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
271 Layer4Match layer4Match = match.getLayer4Match();
272 if (layer4Match != null) {
273 if (layer4Match instanceof TcpMatch) {
274 TcpMatch tcpMatch = (TcpMatch) layer4Match;
275 if (tcpMatch.getTcpSourcePort() != null) {
276 matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
279 if (tcpMatch.getTcpDestinationPort() != null) {
280 matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
282 } else if (layer4Match instanceof UdpMatch) {
283 UdpMatch udpMatch = (UdpMatch) layer4Match;
284 if (udpMatch.getUdpSourcePort() != null) {
285 matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
288 if (udpMatch.getUdpDestinationPort() != null) {
289 matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
291 } else if (layer4Match instanceof SctpMatch) {
292 SctpMatch sctpMatch = (SctpMatch) layer4Match;
293 if (sctpMatch.getSctpSourcePort() != null) {
294 matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
297 if (sctpMatch.getSctpDestinationPort() != null) {
298 matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
303 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
304 if (icmpv4Match != null) {
305 if (icmpv4Match.getIcmpv4Type() != null) {
306 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
309 if (icmpv4Match.getIcmpv4Code() != null) {
310 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
314 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
315 if (icmpv6Match != null) {
316 if (icmpv6Match.getIcmpv6Type() != null) {
317 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
320 if (icmpv6Match.getIcmpv6Code() != null) {
321 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
325 Layer3Match layer3Match = match.getLayer3Match();
326 if (layer3Match != null) {
327 if (layer3Match instanceof Ipv4Match) {
328 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
329 if (ipv4Match.getIpv4Source() != null) {
330 matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
332 if (ipv4Match.getIpv4Destination() != null) {
333 matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
336 if (layer3Match instanceof TunnelIpv4Match) {
337 TunnelIpv4Match tunnelIpv4Src = (TunnelIpv4Match) layer3Match;
338 if (tunnelIpv4Src.getTunnelIpv4Source() != null) {
339 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Src.class, tunnelIpv4Src.getTunnelIpv4Source()));
341 if (tunnelIpv4Src.getTunnelIpv4Destination() != null) {
342 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Dst.class, tunnelIpv4Src.getTunnelIpv4Destination()));
344 } else if (layer3Match instanceof ArpMatch) {
345 ArpMatch arpMatch = (ArpMatch) layer3Match;
346 if (arpMatch.getArpOp() != null) {
347 matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
350 if (arpMatch.getArpSourceTransportAddress() != null) {
351 matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
354 if (arpMatch.getArpTargetTransportAddress() != null) {
355 matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
358 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
359 if (arpSourceHardwareAddress != null) {
360 matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
361 arpSourceHardwareAddress.getMask()));
364 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
365 if (arpTargetHardwareAddress != null) {
366 matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
367 arpTargetHardwareAddress.getMask()));
371 else if (layer3Match instanceof Ipv6Match) {
372 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
373 if (ipv6Match.getIpv6Source() != null) {
374 matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
377 if (ipv6Match.getIpv6Destination() != null) {
378 matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
381 if (ipv6Match.getIpv6Label() != null) {
382 matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
385 if (ipv6Match.getIpv6NdTarget() != null) {
386 matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
389 if (ipv6Match.getIpv6NdSll() != null) {
390 matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
393 if (ipv6Match.getIpv6NdTll() != null) {
394 matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
397 if (ipv6Match.getIpv6ExtHeader() != null) {
398 matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
403 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
404 if (protocolMatchFields != null) {
405 if (protocolMatchFields.getMplsLabel() != null) {
406 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
409 if (protocolMatchFields.getMplsBos() != null) {
410 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
413 if (protocolMatchFields.getMplsTc() != null) {
414 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
417 if (protocolMatchFields.getPbb() != null) {
418 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
422 //FIXME: move to extensible support
423 // TODO: Move to seperate bundle as soon as OF extensibility is supported by ofplugin/java
424 TcpFlagMatch tcpFlagMatch = match.getTcpFlagMatch();
425 if (tcpFlagMatch != null) {
426 if (tcpFlagMatch.getTcpFlag() != null) {
427 matchEntriesList.add(NxmExtensionsConvertor.toNxmTcpFlag(tcpFlagMatch.getTcpFlag()));
431 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
433 if (tunnel != null) {
434 matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
437 return matchEntriesList;
441 * Method convert Openflow 1.0 specific flow match to MD-SAL format flow
446 * @author avishnoi@in.ibm.com
448 public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
449 MatchBuilder matchBuilder = new MatchBuilder();
450 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
451 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
452 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
453 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
454 if (!swMatch.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
455 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
456 (long) swMatch.getInPort(), ofVersion));
459 if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
460 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
461 ethSrcBuilder.setAddress(swMatch.getDlSrc());
462 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
463 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
465 if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
466 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
467 ethDstBuilder.setAddress(swMatch.getDlDst());
468 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
469 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
471 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
472 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
473 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
474 (long) swMatch.getDlType()));
475 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
476 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
478 if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
479 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
480 int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
481 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
482 vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false: true);
483 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
484 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
486 if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp() != null) {
487 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
488 swMatch.getDlVlanPcp()));
489 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
491 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
492 String ipv4PrefixStr = swMatch.getNwSrc().getValue();
493 if (swMatch.getNwSrcMask() != null) {
494 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
496 if (!ipv4PrefixStr.equals(noIp)) {
497 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
498 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
501 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
502 String ipv4PrefixStr = swMatch.getNwDst().getValue();
503 if (swMatch.getNwDstMask() != null) {
504 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
506 if (!ipv4PrefixStr.equals(noIp)) {
507 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
508 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
511 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
512 ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
513 matchBuilder.setIpMatch(ipMatchBuilder.build());
515 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
516 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
517 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
519 .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
520 swMatch.getTpSrc()));
522 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
524 .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
525 swMatch.getTpDst()));
528 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
529 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
532 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
533 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
534 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
536 .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
537 swMatch.getTpSrc()));
539 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
541 .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
542 swMatch.getTpDst()));
545 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
546 matchBuilder.setLayer4Match(udpMatchBuilder.build());
549 if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
550 // DSCP default value is 0 from the library but controller side it
552 // look if there better solution
553 if (0 != swMatch.getNwTos()) {
554 ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
556 matchBuilder.setIpMatch(ipMatchBuilder.build());
559 return matchBuilder.build();
563 * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
568 * @author avishnoi@in.ibm.com
570 public static Match fromOFMatchToSALMatch(
571 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch,
572 final BigInteger datapathid, final OpenflowVersion ofVersion) {
573 return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid, ofVersion);
576 private static Match OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
577 OpenflowVersion ofVersion){
579 MatchBuilder matchBuilder = new MatchBuilder();
580 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
581 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
582 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
583 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
584 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
585 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
586 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
587 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
588 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
589 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
590 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
591 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
592 TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
593 TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
595 for (MatchEntries ofMatch : swMatchList) {
597 if (ofMatch.getOxmMatchField().equals(InPort.class)) {
598 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
599 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
600 portNumber.getPortNumber().getValue(), ofVersion));
601 } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
602 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
603 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
604 portNumber.getPortNumber().getValue(), ofVersion));
605 } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
606 MetadataBuilder metadataBuilder = new MetadataBuilder();
607 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
608 if (metadataMatchEntry != null) {
609 metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
610 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
611 if (maskMatchEntry != null) {
612 metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
615 matchBuilder.setMetadata(metadataBuilder.build());
617 } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
618 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
619 if (macAddressMatchEntry != null) {
620 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
621 ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
622 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
623 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
625 } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
626 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
627 if (macAddressMatchEntry != null) {
628 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
629 ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
630 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
631 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
633 } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
634 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
635 if (ethTypeMatchEntry != null) {
636 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
638 .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
639 (long) ethTypeMatchEntry.getEthType().getValue()));
640 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
641 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
643 } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
644 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
645 if (vlanVidMatchEntry != null) {
646 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
647 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
648 vlanVidMatchEntry.getVlanVid()));
649 vlanMatchBuilder.setVlanId(vlanBuilder.build());
650 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
652 } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
653 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
654 if (vlanPcpMatchEntry != null) {
656 .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
657 vlanPcpMatchEntry.getVlanPcp()));
658 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
660 } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
661 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
662 if (dscpMatchEntry != null) {
663 ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
664 matchBuilder.setIpMatch(ipMatchBuilder.build());
666 } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
667 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
668 if (ecnMatchEntry != null) {
669 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
670 matchBuilder.setIpMatch(ipMatchBuilder.build());
672 } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
673 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch
674 .getAugmentation(ProtocolNumberMatchEntry.class);
675 if (protocolNumberMatchEntry != null) {
676 ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
677 matchBuilder.setIpMatch(ipMatchBuilder.build());
679 } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
680 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
681 if (portMatchEntry != null) {
682 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
683 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
685 } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
686 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
687 if (portMatchEntry != null) {
688 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
689 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
691 } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
692 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
693 if (portMatchEntry != null) {
694 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
695 matchBuilder.setLayer4Match(udpMatchBuilder.build());
697 } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
698 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
699 if (portMatchEntry != null) {
700 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
701 matchBuilder.setLayer4Match(udpMatchBuilder.build());
703 } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
704 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
705 if (portMatchEntry != null) {
706 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
707 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
709 } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
710 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
711 if (portMatchEntry != null) {
712 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
713 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
715 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
716 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
717 if (icmpv4TypeMatchEntry != null) {
718 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
719 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
721 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
722 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
723 if (icmpv4CodeMatchEntry != null) {
724 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
725 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
727 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
728 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
729 if (icmpv6TypeMatchEntry != null) {
730 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
731 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
733 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
734 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
735 if (icmpv6CodeMatchEntry != null) {
736 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
737 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
739 } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)
740 || ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
741 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
742 if (ipv4AddressMatchEntry != null) {
743 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
744 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
745 if (maskMatchEntry != null) {
746 int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
748 while(receivedMask != 0xffffffff){
749 receivedMask = receivedMask >> 1;
752 ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount);
754 //Openflow Spec : 1.3.2
755 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
756 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
757 // statistics response.
759 ipv4PrefixStr+=PREFIX_SEPARATOR + "32";
761 if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
762 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
764 if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
765 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
767 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
771 else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
772 || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
773 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
774 if (ipv4AddressMatchEntry != null) {
775 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
776 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
777 if (maskMatchEntry != null) {
778 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
780 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)) {
781 tunnelIpv4MatchBuilder.setTunnelIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
783 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
784 tunnelIpv4MatchBuilder.setTunnelIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
786 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
789 else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
790 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
791 if (opCodeMatchEntry != null) {
792 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
793 matchBuilder.setLayer3Match(arpMatchBuilder.build());
795 } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)
796 || ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
797 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
798 if (ipv4AddressMatchEntry != null) {
799 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
800 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
801 if (maskMatchEntry != null) {
802 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
804 if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
805 arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
807 if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
808 arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
810 matchBuilder.setLayer3Match(arpMatchBuilder.build());
812 } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)
813 || ofMatch.getOxmMatchField().equals(ArpTha.class)) {
814 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
815 if (macAddressMatchEntry != null) {
816 if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
817 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
818 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
819 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
820 if (maskMatchEntry != null) {
821 arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
822 .macAddressToString(maskMatchEntry.getMask())));
824 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
825 matchBuilder.setLayer3Match(arpMatchBuilder.build());
827 if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
828 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
829 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
830 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
831 if (maskMatchEntry != null) {
832 arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
833 .macAddressToString(maskMatchEntry.getMask())));
835 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
836 matchBuilder.setLayer3Match(arpMatchBuilder.build());
839 } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)
840 || ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
841 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
842 if (ipv6AddressMatchEntry != null) {
843 String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
844 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
845 if(maskMatchEntry != null){
846 ipv6PrefixStr += PREFIX_SEPARATOR
847 + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
850 if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
851 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
853 if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
854 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
856 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
858 } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
859 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
860 if (ipv6FlabelMatchEntry != null) {
861 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
862 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
863 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
864 if (maskMatchEntry != null) {
865 ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(new Long(ByteUtil
866 .bytesToUnsignedInt(maskMatchEntry.getMask()))));
868 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
869 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
871 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
872 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
873 if (ipv6AddressMatchEntry != null) {
874 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
875 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
877 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
878 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
879 if (macAddressMatchEntry != null) {
880 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
881 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
883 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
884 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
885 if (macAddressMatchEntry != null) {
886 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
887 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
889 } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
890 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
891 if (pseudoFieldMatchEntry != null) {
892 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
894 Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
895 Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
897 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
898 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
899 if (maskMatchEntry != null) {
900 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(maskMatchEntry.getMask()));
902 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
903 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
905 } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
906 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
907 if (mplsLabelMatchEntry != null) {
908 protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
909 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
911 } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
912 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
913 if (bosMatchEntry != null) {
914 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos() ? (short) 1 : (short) 0);
915 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
917 } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
918 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
919 if (tcMatchEntry != null) {
920 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
921 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
923 } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
924 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
925 if (isidMatchEntry != null) {
926 PbbBuilder pbbBuilder = new PbbBuilder();
927 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
928 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
929 if (maskMatchEntry != null) {
930 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedInt(maskMatchEntry.getMask()));
932 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
933 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
935 } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
936 TunnelBuilder tunnelBuilder = new TunnelBuilder();
937 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
938 if (metadataMatchEntry != null) {
939 tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
940 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
941 if (maskMatchEntry != null) {
942 tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
945 matchBuilder.setTunnel(tunnelBuilder.build());
947 } else if (ofMatch.getOxmMatchField().equals(TcpFlag.class)) {
948 //FIXME: move to extensible support
949 TcpFlagMatchEntry tcpFlagMatch = ofMatch.getAugmentation(TcpFlagMatchEntry.class);
950 if (tcpFlagMatch != null) {
951 tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
952 matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
956 return matchBuilder.build();
958 private static MatchEntries toOfMplsPbb(final Pbb pbb) {
959 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
960 boolean hasmask = false;
961 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
962 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
963 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
964 isidBuilder.setIsid(pbb.getPbbIsid());
965 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
966 if (pbb.getPbbMask() != null) {
968 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(pbb.getPbbMask()));
970 matchEntriesBuilder.setHasMask(hasmask);
971 return matchEntriesBuilder.build();
974 private static MatchEntries toOfMplsTc(final Short mplsTc) {
975 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
976 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
977 matchEntriesBuilder.setHasMask(false);
978 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
979 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
980 tcBuilder.setTc(mplsTc);
981 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
982 return matchEntriesBuilder.build();
985 private static MatchEntries toOfMplsBos(final Short mplsBos) {
986 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
987 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
988 matchEntriesBuilder.setHasMask(false);
989 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
990 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
992 bosBuilder.setBos(true);
994 bosBuilder.setBos(false);
996 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
997 return matchEntriesBuilder.build();
1000 private static MatchEntries toOfMplsLabel(final Long mplsLabel) {
1001 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1002 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1003 matchEntriesBuilder.setHasMask(false);
1004 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
1005 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
1006 mplsLabelBuilder.setMplsLabel(mplsLabel);
1007 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
1008 return matchEntriesBuilder.build();
1011 private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
1012 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1013 boolean hasmask = false;
1014 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1015 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
1016 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
1017 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
1018 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
1019 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
1020 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
1021 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
1022 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
1023 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
1024 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
1025 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
1026 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
1027 pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
1028 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
1029 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
1031 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
1033 matchEntriesBuilder.setHasMask(hasmask);
1034 return matchEntriesBuilder.build();
1037 private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
1038 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1039 boolean hasmask = false;
1040 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1041 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
1042 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
1043 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
1044 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
1045 if (ipv6Label.getFlabelMask() != null) {
1047 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
1049 matchEntriesBuilder.setHasMask(hasmask);
1050 return matchEntriesBuilder.build();
1053 private static MatchEntries toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
1054 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1055 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1056 matchEntriesBuilder.setHasMask(false);
1057 matchEntriesBuilder.setOxmMatchField(field);
1058 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
1059 port.setPortNumber(new PortNumber(portNumber));
1060 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
1061 return matchEntriesBuilder.build();
1064 private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
1065 final BigInteger metadataMask) {
1066 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1067 boolean hasmask = false;
1068 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1069 matchEntriesBuilder.setOxmMatchField(field);
1070 addMetadataAugmentation(matchEntriesBuilder, metadata);
1071 if (metadataMask != null) {
1073 addMaskAugmentation(matchEntriesBuilder,
1074 ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
1076 matchEntriesBuilder.setHasMask(hasmask);
1077 return matchEntriesBuilder.build();
1080 public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
1081 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
1082 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
1083 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1084 boolean hasmask = false;
1085 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1086 matchEntriesBuilder.setOxmMatchField(field);
1087 addMacAddressAugmentation(matchEntriesBuilder, macAddress);
1090 addMaskAugmentation(matchEntriesBuilder, ByteBufUtils.macAddressToBytes(mask.getValue()));
1092 matchEntriesBuilder.setHasMask(hasmask);
1093 return matchEntriesBuilder.build();
1096 private static MatchEntries toOfEthernetType(final EthernetType ethernetType) {
1097 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1098 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1099 matchEntriesBuilder.setHasMask(false);
1100 matchEntriesBuilder.setOxmMatchField(EthType.class);
1101 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
1102 ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
1103 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
1104 return matchEntriesBuilder.build();
1107 private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
1108 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
1109 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1110 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1111 matchEntriesBuilder.setHasMask(false);
1112 matchEntriesBuilder.setOxmMatchField(field);
1113 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
1114 portBuilder.setPort(portNumber);
1115 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
1116 return matchEntriesBuilder.build();
1119 private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) {
1120 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1121 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1122 matchEntriesBuilder.setHasMask(false);
1123 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1124 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1125 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1126 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1127 return matchEntriesBuilder.build();
1130 private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) {
1131 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1132 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1133 matchEntriesBuilder.setHasMask(false);
1134 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1135 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1136 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1137 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1138 return matchEntriesBuilder.build();
1141 private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) {
1142 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1143 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1144 matchEntriesBuilder.setHasMask(false);
1145 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1146 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1147 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1148 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1149 return matchEntriesBuilder.build();
1152 private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) {
1153 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1154 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1155 matchEntriesBuilder.setHasMask(false);
1156 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1157 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1158 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1159 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1160 return matchEntriesBuilder.build();
1163 public static MatchEntries toOfIpv4Prefix(final Class<? extends MatchField> field, final Ipv4Prefix ipv4Prefix) {
1164 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1165 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1166 matchEntriesBuilder.setOxmMatchField(field);
1167 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1168 matchEntriesBuilder.setHasMask(hasMask);
1169 return matchEntriesBuilder.build();
1172 private static MatchEntries toOfIpv6Prefix(final Class<? extends MatchField> field, final Ipv6Prefix ipv6Prefix) {
1173 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1174 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1175 matchEntriesBuilder.setOxmMatchField(field);
1176 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1177 matchEntriesBuilder.setHasMask(hasmask);
1178 return matchEntriesBuilder.build();
1181 public static MatchEntries toOfIpDscp(final Dscp ipDscp) {
1182 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1183 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1184 matchEntriesBuilder.setHasMask(false);
1185 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1186 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1187 dscpBuilder.setDscp(ipDscp);
1188 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1189 return matchEntriesBuilder.build();
1192 public static MatchEntries toOfVlanPcp(
1193 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1194 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1195 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1196 matchEntriesBuilder.setHasMask(false);
1197 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1198 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1199 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1200 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1201 return matchEntriesBuilder.build();
1204 private static MatchEntries toOfVlanVid(final VlanId vlanId) {
1206 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1207 boolean hasmask = false;
1208 boolean setCfiBit = false;
1209 Integer vidEntryValue = 0;
1210 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1211 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1212 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1213 if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
1215 if (vlanId.getVlanId() != null) {
1216 vidEntryValue = vlanId.getVlanId().getValue();
1218 hasmask = (vidEntryValue == 0);
1220 vlanVidBuilder.setCfiBit(setCfiBit);
1221 vlanVidBuilder.setVlanVid(vidEntryValue);
1222 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1224 addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1226 matchEntriesBuilder.setHasMask(hasmask);
1227 return matchEntriesBuilder.build();
1230 private static MatchEntries toOfIpProto(final Short ipProtocol) {
1231 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1232 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1233 matchEntriesBuilder.setHasMask(false);
1234 matchEntriesBuilder.setOxmMatchField(IpProto.class);
1235 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1236 protoNumberBuilder.setProtocolNumber(ipProtocol);
1237 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1238 return matchEntriesBuilder.build();
1241 private static MatchEntries toOfIpEcn(final Short ipEcn) {
1242 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1243 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1244 matchEntriesBuilder.setHasMask(false);
1245 matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1246 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1247 ecnBuilder.setEcn(ipEcn);
1248 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1249 return matchEntriesBuilder.build();
1252 private static MatchEntries toOfArpOpCode(final Integer arpOp) {
1253 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1254 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1255 matchEntriesBuilder.setHasMask(false);
1256 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1257 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1258 opcodeBuilder.setOpCode(arpOp);
1259 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1260 return matchEntriesBuilder.build();
1263 private static MatchEntries toOfIpv6Address(final Ipv6Address address) {
1264 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1265 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1266 matchEntriesBuilder.setHasMask(false);
1267 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1268 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1269 ipv6AddressBuilder.setIpv6Address(address);
1270 matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1271 return matchEntriesBuilder.build();
1274 private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) {
1275 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1276 maskBuilder.setMask(mask);
1277 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1280 private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) {
1281 boolean hasMask = false;
1282 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1283 Ipv6Address ipv6Address = new Ipv6Address(addressParts.next());
1285 Integer prefix = null;
1286 if (addressParts.hasNext()) {
1287 prefix = Integer.parseInt(addressParts.next());
1290 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1291 ipv6AddressBuilder.setIpv6Address(ipv6Address);
1292 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1293 if (prefix != null) {
1295 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1300 private static byte[] convertIpv6PrefixToByteArray(final int prefix) {
1301 // TODO: Temporary fix. Has performance impacts.
1302 byte[] mask = new byte[16];
1303 int oneCount = prefix;
1304 for (int count = 0; count < 16; count++) {
1306 if (oneCount >= 8) {
1308 oneCount = oneCount - 8;
1310 byteBits = oneCount;
1314 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1319 private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) {
1320 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1321 metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
1322 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1326 * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1329 private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
1330 boolean hasMask = false;
1331 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1332 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
1335 if (addressParts.hasNext()) {
1336 prefix = Integer.parseInt(addressParts.next());
1341 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1342 ipv4AddressBuilder.setIpv4Address(ipv4Address);
1343 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1345 int mask = 0xffffffff << (32 - prefix);
1346 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1348 addMaskAugmentation(builder, maskBytes);
1354 private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) {
1355 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1356 macAddress.setMacAddress(address);
1357 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1361 * Method converts OF SetField action to SAL SetFiled action.
1364 * @param ofVersion current ofp version
1367 public static SetField fromOFSetFieldToSALSetFieldAction(
1368 final Action action, OpenflowVersion ofVersion) {
1369 logger.debug("Converting OF SetField action to SAL SetField action");
1370 SetFieldBuilder setField = new SetFieldBuilder();
1371 OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
1372 Match match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntries(), null, ofVersion);
1373 setField.fieldsFrom(match);
1374 return setField.build();