2 * Copyright (c) 2013 Ericsson. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
11 import java.math.BigInteger;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
17 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
171 import org.slf4j.Logger;
172 import org.slf4j.LoggerFactory;
175 * Utility class for converting a MD-SAL Flow into the OF flow mod
177 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
178 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
179 static final String PREFIX_SEPARATOR = "/";
180 private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
181 private static final short PROTO_TCP = 6;
182 private static final short PROTO_UDP = 17;
185 public List<MatchEntries> convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match,BigInteger datapathid) {
186 List<MatchEntries> matchEntriesList = new ArrayList<>();
188 if (match.getInPort() != null) {
189 matchEntriesList.add(toOfPort(InPort.class, InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPort())));
192 if (match.getInPhyPort() != null) {
193 matchEntriesList.add(toOfPort(InPhyPort.class, InventoryDataServiceUtil.portNumberfromNodeConnectorId(match.getInPhyPort())));
196 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
198 if (metadata != null) {
199 matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
202 EthernetMatch ethernetMatch = match.getEthernetMatch();
203 if (ethernetMatch != null) {
204 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
205 if (ethernetDestination != null) {
206 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
207 ethernetDestination.getMask()));
210 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
211 if (ethernetSource != null) {
213 .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
216 if (ethernetMatch.getEthernetType() != null) {
217 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
221 VlanMatch vlanMatch = match.getVlanMatch();
222 if (vlanMatch != null) {
223 if (vlanMatch.getVlanId() != null) {
224 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
227 if (vlanMatch.getVlanPcp() != null) {
228 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
232 IpMatch ipMatch = match.getIpMatch();
233 if (ipMatch != null) {
234 if (ipMatch.getIpDscp() != null) {
235 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
238 if (ipMatch.getIpEcn() != null) {
239 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
242 if (ipMatch.getIpProtocol() != null) {
243 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
248 Layer4Match layer4Match = match.getLayer4Match();
249 if (layer4Match != null) {
250 if (layer4Match instanceof TcpMatch) {
251 TcpMatch tcpMatch = (TcpMatch) layer4Match;
252 if (tcpMatch.getTcpSourcePort() != null) {
253 matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
256 if (tcpMatch.getTcpDestinationPort() != null) {
257 matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
259 } else if (layer4Match instanceof UdpMatch) {
260 UdpMatch udpMatch = (UdpMatch) layer4Match;
261 if (udpMatch.getUdpSourcePort() != null) {
262 matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
265 if (udpMatch.getUdpDestinationPort() != null) {
266 matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
268 } else if (layer4Match instanceof SctpMatch) {
269 SctpMatch sctpMatch = (SctpMatch) layer4Match;
270 if (sctpMatch.getSctpSourcePort() != null) {
271 matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
274 if (sctpMatch.getSctpDestinationPort() != null) {
275 matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
280 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
281 if (icmpv4Match != null) {
282 if (icmpv4Match.getIcmpv4Type() != null) {
283 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
286 if (icmpv4Match.getIcmpv4Code() != null) {
287 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
291 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
292 if (icmpv6Match != null) {
293 if (icmpv6Match.getIcmpv6Type() != null) {
294 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
297 if (icmpv6Match.getIcmpv6Code() != null) {
298 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
302 Layer3Match layer3Match = match.getLayer3Match();
303 if (layer3Match != null) {
304 if (layer3Match instanceof Ipv4Match) {
305 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
306 if (ipv4Match.getIpv4Source() != null) {
307 matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
309 if (ipv4Match.getIpv4Destination() != null) {
310 matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
312 } else if (layer3Match instanceof ArpMatch) {
313 ArpMatch arpMatch = (ArpMatch) layer3Match;
314 if (arpMatch.getArpOp() != null) {
315 matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
318 if (arpMatch.getArpSourceTransportAddress() != null) {
319 matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
322 if (arpMatch.getArpTargetTransportAddress() != null) {
323 matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
326 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
327 if (arpSourceHardwareAddress != null) {
328 matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
329 arpSourceHardwareAddress.getMask()));
332 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
333 if (arpTargetHardwareAddress != null) {
334 matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
335 arpTargetHardwareAddress.getMask()));
339 else if (layer3Match instanceof Ipv6Match) {
340 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
341 if (ipv6Match.getIpv6Source() != null) {
342 matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
345 if (ipv6Match.getIpv6Destination() != null) {
346 matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
349 if (ipv6Match.getIpv6Label() != null) {
350 matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
353 if (ipv6Match.getIpv6NdTarget() != null) {
354 matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
357 if (ipv6Match.getIpv6NdSll() != null) {
358 matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
361 if (ipv6Match.getIpv6NdTll() != null) {
362 matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
365 if (ipv6Match.getIpv6ExtHeader() != null) {
366 matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
371 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
372 if (protocolMatchFields != null) {
373 if (protocolMatchFields.getMplsLabel() != null) {
374 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
377 if (protocolMatchFields.getMplsBos() != null) {
378 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
381 if (protocolMatchFields.getMplsTc() != null) {
382 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
385 if (protocolMatchFields.getPbb() != null) {
386 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
390 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
392 if (tunnel != null) {
393 matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
397 return matchEntriesList;
401 * Method convert Openflow 1.0 specific flow match to MD-SAL format
405 * @author avishnoi@in.ibm.com
407 public static Match fromOFMatchV10ToSALMatch(MatchV10 swMatch,BigInteger datapathid){
408 MatchBuilder matchBuilder = new MatchBuilder();
409 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
410 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
411 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
412 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
414 if(swMatch.getInPort() != null){
415 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,(long)swMatch.getInPort()));
418 if(swMatch.getDlSrc()!= null){
419 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
420 ethSrcBuilder.setAddress(swMatch.getDlSrc());
421 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
422 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
424 if(swMatch.getDlDst()!= null){
425 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
426 ethDstBuilder.setAddress(swMatch.getDlDst());
427 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
428 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
430 if(swMatch.getDlType()!= null){
431 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
432 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)swMatch.getDlType()));
433 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
434 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
436 if(swMatch.getDlVlan()!=null){
437 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
438 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(swMatch.getDlVlan()));
439 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
440 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
442 if(swMatch.getDlVlanPcp()!= null){
443 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(swMatch.getDlVlanPcp()));
444 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
446 if(swMatch.getNwSrc() !=null){
447 String ipv4PrefixStr = swMatch.getNwSrc().getValue();
448 if(swMatch.getNwSrcMask()!= null){
449 ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwSrcMask();
451 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
452 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
454 if(swMatch.getNwDst() !=null){
455 String ipv4PrefixStr = swMatch.getNwDst().getValue();
456 if(swMatch.getNwDstMask()!= null){
457 ipv4PrefixStr +=PREFIX_SEPARATOR+swMatch.getNwDstMask();
459 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
460 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
462 if(swMatch.getNwProto()!= null ){
463 ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
464 matchBuilder.setIpMatch(ipMatchBuilder.build());
466 if(swMatch.getNwProto() == PROTO_TCP){
467 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
468 if(swMatch.getTpSrc()!= null)
469 tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
470 if(swMatch.getTpDst()!= null)
471 tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
472 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
474 if(swMatch.getNwProto() == PROTO_UDP){
475 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
476 if(swMatch.getTpSrc()!= null)
477 udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpSrc()));
478 if(swMatch.getTpDst()!= null)
479 udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(swMatch.getTpDst()));
480 matchBuilder.setLayer4Match(udpMatchBuilder.build());
482 if(swMatch.getNwTos()!=null){
483 //DSCP default value is 0 from the library but controller side it is null.
484 // look if there better solution
485 if(0 != swMatch.getNwTos())
487 ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
489 matchBuilder.setIpMatch(ipMatchBuilder.build());
492 return matchBuilder.build();
496 * Method converts Openflow 1.3+ specific flow match to MD-SAL format
500 * @author avishnoi@in.ibm.com
502 public static Match fromOFMatchToSALMatch(
503 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match swMatch,BigInteger datapathid) {
505 MatchBuilder matchBuilder = new MatchBuilder();
506 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
507 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
508 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
509 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
510 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
511 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
512 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
513 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
514 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
515 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
516 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
517 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
519 List<MatchEntries> swMatchList = swMatch.getMatchEntries();
521 for(MatchEntries ofMatch : swMatchList){
523 if(ofMatch.getOxmMatchField().equals(InPort.class)){
524 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
525 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNumber.getPortNumber().getValue()));
526 }else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)){
527 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
528 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,portNumber.getPortNumber().getValue()));
529 }else if(ofMatch.getOxmMatchField().equals(Metadata.class)){
530 MetadataBuilder metadataBuilder = new MetadataBuilder();
531 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
532 if(metadataMatchEntry != null){
533 metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
534 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
535 if(maskMatchEntry != null){
536 metadataBuilder.setMetadataMask(maskMatchEntry.getMask());
538 matchBuilder.setMetadata(metadataBuilder.build());
540 }else if(ofMatch.getOxmMatchField().equals(EthSrc.class)){
541 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
542 if(macAddressMatchEntry != null){
543 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
544 ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
545 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
546 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
548 }else if(ofMatch.getOxmMatchField().equals(EthDst.class)){
549 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
550 if(macAddressMatchEntry != null){
551 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
552 ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
553 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
554 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
556 }else if(ofMatch.getOxmMatchField().equals(EthType.class)){
557 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
558 if(ethTypeMatchEntry != null){
559 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
560 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)ethTypeMatchEntry.getEthType().getValue()));
561 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
562 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
564 }else if(ofMatch.getOxmMatchField().equals(VlanVid.class)){
565 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
566 if(vlanVidMatchEntry != null){
567 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
568 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatchEntry.getVlanVid()));
569 vlanMatchBuilder.setVlanId(vlanBuilder.build());
570 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
572 }else if(ofMatch.getOxmMatchField().equals(VlanPcp.class)){
573 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
574 if(vlanPcpMatchEntry != null){
575 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(vlanPcpMatchEntry.getVlanPcp()));
576 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
578 }else if(ofMatch.getOxmMatchField().equals(IpDscp.class)){
579 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
580 if(dscpMatchEntry != null){
581 ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
582 matchBuilder.setIpMatch(ipMatchBuilder.build());
584 }else if(ofMatch.getOxmMatchField().equals(IpEcn.class)){
585 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
586 if(ecnMatchEntry != null){
587 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
588 matchBuilder.setIpMatch(ipMatchBuilder.build());
590 }else if(ofMatch.getOxmMatchField().equals(IpProto.class)){
591 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch.getAugmentation(ProtocolNumberMatchEntry.class);
592 if(protocolNumberMatchEntry != null){
593 ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
594 matchBuilder.setIpMatch(ipMatchBuilder.build());
596 }else if(ofMatch.getOxmMatchField().equals(TcpSrc.class)){
597 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
598 if(portMatchEntry != null){
599 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
600 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
602 }else if(ofMatch.getOxmMatchField().equals(TcpDst.class)){
603 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
604 if(portMatchEntry != null){
605 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
606 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
608 }else if(ofMatch.getOxmMatchField().equals(UdpSrc.class)){
609 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
610 if(portMatchEntry != null){
611 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
612 matchBuilder.setLayer4Match(udpMatchBuilder.build());
614 }else if(ofMatch.getOxmMatchField().equals(UdpDst.class)){
615 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
616 if(portMatchEntry != null){
617 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
618 matchBuilder.setLayer4Match(udpMatchBuilder.build());
620 }else if(ofMatch.getOxmMatchField().equals(SctpSrc.class)){
621 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
622 if(portMatchEntry != null){
623 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
624 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
626 }else if(ofMatch.getOxmMatchField().equals(SctpDst.class)){
627 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
628 if(portMatchEntry != null){
629 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
630 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
632 }else if(ofMatch.getOxmMatchField().equals(Icmpv4Type.class)){
633 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
634 if(icmpv4TypeMatchEntry != null){
635 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
636 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
638 }else if(ofMatch.getOxmMatchField().equals(Icmpv4Code.class)){
639 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
640 if(icmpv4CodeMatchEntry != null){
641 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
642 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
644 }else if(ofMatch.getOxmMatchField().equals(Icmpv6Type.class)){
645 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
646 if(icmpv6TypeMatchEntry != null){
647 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
648 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
650 }else if(ofMatch.getOxmMatchField().equals(Icmpv6Code.class)){
651 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
652 if(icmpv6CodeMatchEntry != null){
653 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
654 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
656 }else if(ofMatch.getOxmMatchField().equals(Ipv4Src.class) ||
657 ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
658 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
659 if(ipv4AddressMatchEntry != null){
660 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
661 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
662 if(maskMatchEntry != null){
663 ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
665 if(ofMatch.getOxmMatchField().equals(Ipv4Src.class)){
666 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
668 if(ofMatch.getOxmMatchField().equals(Ipv4Dst.class)){
669 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
671 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
673 }else if(ofMatch.getOxmMatchField().equals(ArpOp.class)){
674 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
675 if(opCodeMatchEntry != null){
676 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
677 matchBuilder.setLayer3Match(arpMatchBuilder.build());
679 }else if(ofMatch.getOxmMatchField().equals(ArpSpa.class) ||
680 ofMatch.getOxmMatchField().equals(ArpTpa.class)){
681 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
682 if(ipv4AddressMatchEntry != null){
683 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
684 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
685 if(maskMatchEntry != null){
686 ipv4PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
688 if(ofMatch.getOxmMatchField().equals(ArpSpa.class)){
689 arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
691 if(ofMatch.getOxmMatchField().equals(ArpTpa.class)){
692 arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
694 matchBuilder.setLayer3Match(arpMatchBuilder.build());
696 }else if(ofMatch.getOxmMatchField().equals(ArpSha.class) ||
697 ofMatch.getOxmMatchField().equals(ArpTha.class)){
698 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
699 if(macAddressMatchEntry !=null){
700 if(ofMatch.getOxmMatchField().equals(ArpSha.class)){
701 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
702 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
703 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
704 if(maskMatchEntry != null){
705 arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
707 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
708 matchBuilder.setLayer3Match(arpMatchBuilder.build());
710 if(ofMatch.getOxmMatchField().equals(ArpTha.class)){
711 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
712 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
713 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
714 if(maskMatchEntry != null){
715 arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
717 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
718 matchBuilder.setLayer3Match(arpMatchBuilder.build());
721 }else if(ofMatch.getOxmMatchField().equals(Ipv6Src.class) ||
722 ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
723 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
724 if(ipv6AddressMatchEntry != null){
725 String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
726 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
727 if(maskMatchEntry != null){
728 ipv6PrefixStr +=PREFIX_SEPARATOR+ ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
730 if(ofMatch.getOxmMatchField().equals(Ipv6Src.class)){
731 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
733 if(ofMatch.getOxmMatchField().equals(Ipv6Dst.class)){
734 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
736 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
738 }else if(ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)){
739 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
740 if(ipv6FlabelMatchEntry != null){
741 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
742 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
743 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
744 if(maskMatchEntry != null){
745 ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
747 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
748 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
750 }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)){
751 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
752 if(ipv6AddressMatchEntry != null){
753 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
754 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
756 }else if(ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)){
757 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
758 if(macAddressMatchEntry != null){
759 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
760 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
762 }else if(ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)){
763 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
764 if(macAddressMatchEntry != null){
765 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
766 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
768 }else if(ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)){
769 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
770 if(pseudoFieldMatchEntry != null){
771 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
773 Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
775 bitmap |= pField.isNonext()?(1 << 0): ~(1 << 0);
776 bitmap |= pField.isEsp()?(1 << 1): ~(1 << 1);
777 bitmap |= pField.isAuth()?(1 << 2): ~(1 << 2);
778 bitmap |= pField.isDest()?(1 << 3): ~(1 << 3);
779 bitmap |= pField.isFrag()?(1 << 4): ~(1 << 4);
780 bitmap |= pField.isRouter()?(1 << 5): ~(1 << 5);
781 bitmap |= pField.isHop()?(1 << 6): ~(1 << 6);
782 bitmap |= pField.isUnrep()?(1 << 7): ~(1 << 7);
783 bitmap |= pField.isUnseq()?(1 << 8): ~(1 << 8);
785 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
786 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
787 if(maskMatchEntry != null){
788 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(maskMatchEntry.getMask());
790 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
791 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
793 }else if(ofMatch.getOxmMatchField().equals(MplsLabel.class)){
794 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
795 if(mplsLabelMatchEntry != null){
796 protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
797 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
799 }else if(ofMatch.getOxmMatchField().equals(MplsBos.class)){
800 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
801 if(bosMatchEntry != null){
802 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
803 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
805 }else if(ofMatch.getOxmMatchField().equals(MplsTc.class)){
806 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
807 if(tcMatchEntry != null){
808 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
809 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
811 }else if(ofMatch.getOxmMatchField().equals(PbbIsid.class)){
812 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
813 if(isidMatchEntry != null){
814 PbbBuilder pbbBuilder = new PbbBuilder();
815 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
816 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
817 if(maskMatchEntry != null){
818 pbbBuilder.setPbbMask(maskMatchEntry.getMask());
820 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
821 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
823 }else if(ofMatch.getOxmMatchField().equals(TunnelId.class)){
824 TunnelBuilder tunnelBuilder = new TunnelBuilder();
825 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
826 if(metadataMatchEntry != null){
827 tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
828 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
829 if(maskMatchEntry != null){
830 tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
832 matchBuilder.setTunnel(tunnelBuilder.build());
836 return matchBuilder.build();
840 private static MatchEntries toOfMplsPbb(Pbb pbb) {
841 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
842 boolean hasmask = false;
843 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
844 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
845 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
846 isidBuilder.setIsid(pbb.getPbbIsid());
847 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
848 if (pbb.getPbbMask() != null) {
850 addMaskAugmentation(matchEntriesBuilder, pbb.getPbbMask());
852 matchEntriesBuilder.setHasMask(hasmask);
853 return matchEntriesBuilder.build();
856 private static MatchEntries toOfMplsTc(Short mplsTc) {
857 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
858 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
859 matchEntriesBuilder.setHasMask(false);
860 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
861 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
862 tcBuilder.setTc(mplsTc);
863 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
864 return matchEntriesBuilder.build();
867 private static MatchEntries toOfMplsBos(Short mplsBos) {
868 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
869 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
870 matchEntriesBuilder.setHasMask(false);
871 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
872 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
874 bosBuilder.setBos(true);
876 bosBuilder.setBos(false);
878 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
879 return matchEntriesBuilder.build();
882 private static MatchEntries toOfMplsLabel(Long mplsLabel) {
883 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
884 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
885 matchEntriesBuilder.setHasMask(false);
886 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
887 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
888 mplsLabelBuilder.setMplsLabel(mplsLabel);
889 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
890 return matchEntriesBuilder.build();
893 private static MatchEntries toOfIpv6ExtHeader(Ipv6ExtHeader ipv6ExtHeader) {
894 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
895 boolean hasmask = false;
896 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
897 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
898 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
899 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
900 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
901 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
902 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
903 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
904 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
905 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
906 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
907 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
908 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
909 pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
910 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
911 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
913 addMaskAugmentation(matchEntriesBuilder, ipv6ExtHeader.getIpv6ExthdrMask());
915 matchEntriesBuilder.setHasMask(hasmask);
916 return matchEntriesBuilder.build();
919 private static MatchEntries toOfIpv6FlowLabel(Ipv6Label ipv6Label) {
920 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
921 boolean hasmask = false;
922 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
923 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
924 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
925 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
926 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
927 if (ipv6Label.getFlabelMask() != null) {
929 addMaskAugmentation(matchEntriesBuilder, ipv6Label.getFlabelMask());
931 matchEntriesBuilder.setHasMask(hasmask);
932 return matchEntriesBuilder.build();
935 private static MatchEntries toOfPort(Class<? extends MatchField> field, Long portNumber) {
936 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
937 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
938 matchEntriesBuilder.setHasMask(false);
939 matchEntriesBuilder.setOxmMatchField(field);
940 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
941 port.setPortNumber(new PortNumber(portNumber));
942 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
943 return matchEntriesBuilder.build();
946 private static MatchEntries toOfMetadata(Class<? extends MatchField> field, BigInteger metadata, byte[] metadataMask) {
947 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
948 boolean hasmask = false;
949 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
950 matchEntriesBuilder.setOxmMatchField(field);
951 addMetadataAugmentation(matchEntriesBuilder, metadata);
952 if (metadataMask != null) {
954 addMaskAugmentation(matchEntriesBuilder, metadataMask);
956 matchEntriesBuilder.setHasMask(hasmask);
957 return matchEntriesBuilder.build();
960 private static MatchEntries toOfMacAddress(Class<? extends MatchField> field,
961 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
963 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
964 boolean hasmask = false;
965 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
966 matchEntriesBuilder.setOxmMatchField(field);
967 addMacAddressAugmentation(matchEntriesBuilder, macAddress);
970 addMaskAugmentation(matchEntriesBuilder, mask);
972 matchEntriesBuilder.setHasMask(hasmask);
973 return matchEntriesBuilder.build();
976 private static MatchEntries toOfEthernetType(EthernetType ethernetType) {
977 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
978 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
979 matchEntriesBuilder.setHasMask(false);
980 matchEntriesBuilder.setOxmMatchField(EthType.class);
981 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
982 ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
983 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
984 return matchEntriesBuilder.build();
987 private static MatchEntries toOfLayer3Port(Class<? extends MatchField> field,
988 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
989 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
990 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
991 matchEntriesBuilder.setHasMask(false);
992 matchEntriesBuilder.setOxmMatchField(field);
993 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
994 portBuilder.setPort(portNumber);
995 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
996 return matchEntriesBuilder.build();
999 private static MatchEntries toOfIcmpv4Type(Short icmpv4Type) {
1000 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1001 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1002 matchEntriesBuilder.setHasMask(false);
1003 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1004 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1005 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1006 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1007 return matchEntriesBuilder.build();
1010 private static MatchEntries toOfIcmpv4Code(Short icmpv4Code) {
1011 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1012 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1013 matchEntriesBuilder.setHasMask(false);
1014 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1015 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1016 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1017 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1018 return matchEntriesBuilder.build();
1021 private static MatchEntries toOfIcmpv6Type(Short icmpv6Type) {
1022 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1023 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1024 matchEntriesBuilder.setHasMask(false);
1025 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1026 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1027 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1028 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1029 return matchEntriesBuilder.build();
1032 private static MatchEntries toOfIcmpv6Code(Short icmpv6Code) {
1033 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1034 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1035 matchEntriesBuilder.setHasMask(false);
1036 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1037 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1038 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1039 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1040 return matchEntriesBuilder.build();
1043 private static MatchEntries toOfIpv4Prefix(Class<? extends MatchField> field, Ipv4Prefix ipv4Prefix) {
1044 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1045 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1046 matchEntriesBuilder.setOxmMatchField(field);
1047 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1048 matchEntriesBuilder.setHasMask(hasMask);
1049 return matchEntriesBuilder.build();
1052 private static MatchEntries toOfIpv6Prefix(Class<? extends MatchField> field, Ipv6Prefix ipv6Prefix) {
1053 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1054 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1055 matchEntriesBuilder.setOxmMatchField(field);
1056 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1057 matchEntriesBuilder.setHasMask(hasmask);
1058 return matchEntriesBuilder.build();
1061 private static MatchEntries toOfIpDscp(Dscp ipDscp) {
1062 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1063 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1064 matchEntriesBuilder.setHasMask(false);
1065 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1066 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1067 dscpBuilder.setDscp(ipDscp);
1068 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1069 return matchEntriesBuilder.build();
1072 private static MatchEntries toOfVlanPcp(
1073 org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1074 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1075 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1076 matchEntriesBuilder.setHasMask(false);
1077 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1078 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1079 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1080 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1081 return matchEntriesBuilder.build();
1084 private static MatchEntries toOfVlanVid(VlanId vlanId) {
1086 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1087 boolean hasmask = false;
1088 boolean setCfiBit = false;
1089 Integer vidEntryValue = 0;
1090 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1091 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1092 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1093 if (vlanId.isVlanIdPresent() == Boolean.TRUE) {
1095 if (vlanId.getVlanId() != null) {
1096 vidEntryValue = vlanId.getVlanId().getValue();
1098 hasmask = (vidEntryValue == 0);
1100 vlanVidBuilder.setCfiBit(setCfiBit);
1101 vlanVidBuilder.setVlanVid(vidEntryValue);
1102 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1104 addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1106 matchEntriesBuilder.setHasMask(hasmask);
1107 return matchEntriesBuilder.build();
1110 private static MatchEntries toOfIpProto(Short ipProtocol) {
1111 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1112 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1113 matchEntriesBuilder.setHasMask(false);
1114 matchEntriesBuilder.setOxmMatchField(IpProto.class);
1115 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1116 protoNumberBuilder.setProtocolNumber(ipProtocol);
1117 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1118 return matchEntriesBuilder.build();
1121 private static MatchEntries toOfIpEcn(Short ipEcn) {
1122 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1123 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1124 matchEntriesBuilder.setHasMask(false);
1125 matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1126 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1127 ecnBuilder.setEcn(ipEcn);
1128 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1129 return matchEntriesBuilder.build();
1132 private static MatchEntries toOfArpOpCode(Integer arpOp) {
1133 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1134 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1135 matchEntriesBuilder.setHasMask(false);
1136 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1137 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1138 opcodeBuilder.setOpCode(arpOp);
1139 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1140 return matchEntriesBuilder.build();
1143 private static MatchEntries toOfIpv6Address(Ipv6Address address) {
1144 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1145 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1146 matchEntriesBuilder.setHasMask(false);
1147 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1148 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1149 ipv6AddressBuilder.setIpv6Address(address);
1150 matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1151 return matchEntriesBuilder.build();
1154 private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
1155 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1156 maskBuilder.setMask(mask);
1157 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1160 private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
1161 boolean hasMask = false;
1162 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
1163 Integer prefix = null;
1164 if (addressParts.length == 2) {
1165 prefix = Integer.parseInt(addressParts[1]);
1168 Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
1169 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1170 ipv6AddressBuilder.setIpv6Address(ipv6Address);
1171 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1172 if (prefix != null) {
1174 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1179 private static byte[] convertIpv6PrefixToByteArray(int prefix) {
1180 // TODO: Temporary fix. Has performance impacts.
1181 byte[] mask = new byte[16];
1182 int oneCount = prefix;
1183 for (int count = 0; count < 16; count++) {
1185 if (oneCount >= 8) {
1187 oneCount = oneCount - 8;
1189 byteBits = oneCount;
1193 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1198 private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
1199 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1200 metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerTo64Bit(metadata));
1201 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1205 * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1208 private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
1209 boolean hasMask = false;
1210 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
1211 Integer prefix = null;
1212 if (addressParts.length < 2) {
1215 prefix = Integer.parseInt(addressParts[1]);
1218 Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
1219 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1220 ipv4AddressBuilder.setIpv4Address(ipv4Address);
1221 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1223 int mask = 0xffffffff << (32 - prefix);
1224 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1226 addMaskAugmentation(builder, maskBytes);
1232 private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
1233 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1234 macAddress.setMacAddress(address);
1235 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1239 * Method converts OF SetField Match to SAL SetFiled matches
1240 * TODO: enable or delete
1244 public static SetField ofToSALSetField(
1245 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
1246 logger.info("OF SetField match to SAL SetField match converstion begins");
1247 SetFieldBuilder setField = new SetFieldBuilder();
1249 * OxmFieldsAction oxmFields =
1250 * action.getAugmentation(OxmFieldsAction.class);
1252 * List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
1254 * .yang.gen.v1.urn.opendaylight.action.types.rev131112.action
1255 * .action.set.field.MatchBuilder match =new
1256 * org.opendaylight.yang.gen.v1
1257 * .urn.opendaylight.action.types.rev131112.action
1258 * .action.set.field.MatchBuilder();
1260 * EthernetMatchBuilder ethernetMatchBuilder = null; VlanMatchBuilder
1261 * vlanMatchBuilder = null; IpMatchBuilder ipMatchBuilder = null;
1262 * TcpMatchBuilder tcpMatchBuilder = null; UdpMatchBuilder
1263 * udpMatchBuilder = null; SctpMatchBuilder sctpMatchBuilder = null;
1264 * Icmpv4MatchBuilder icmpv4MatchBuilder = null; Icmpv6MatchBuilder
1265 * icmpv6MatchBuilder = null; Ipv4MatchBuilder ipv4MatchBuilder = null;
1266 * ArpMatchBuilder arpMatchBuilder = null; Ipv6MatchBuilder
1267 * ipv6MatchBuilder = null; ProtocolMatchFieldsBuilder
1268 * protocolMatchFieldsBuilder = null;
1270 * for(MatchEntries matchEntry : matchEntries){ if(matchEntry instanceof
1271 * InPort){ PortNumberMatchEntry inPort =
1272 * matchEntry.getAugmentation(PortNumberMatchEntry.class);
1273 * match.setInPort(inPort.getPortNumber().getValue()); }else if
1274 * (matchEntry instanceof InPhyPort){ PortNumberMatchEntry phyPort =
1275 * matchEntry.getAugmentation(PortNumberMatchEntry.class);
1276 * match.setInPhyPort(phyPort.getPortNumber().getValue()); }else if
1277 * (matchEntry instanceof Metadata){ MetadataMatchEntry metadataMatch =
1278 * matchEntry.getAugmentation(MetadataMatchEntry.class); MetadataBuilder
1279 * metadataBuilder = new MetadataBuilder();
1280 * metadataBuilder.setMetadata(new
1281 * BigInteger(metadataMatch.getMetadata())); MaskMatchEntry maskMatch =
1282 * matchEntry.getAugmentation(MaskMatchEntry.class); if (maskMatch !=
1283 * null){ metadataBuilder.setMetadataMask(maskMatch.getMask()); }
1284 * match.setMetadata(metadataBuilder.build()); }else if (matchEntry
1285 * instanceof EthDst){
1287 * if(ethernetMatchBuilder == null) ethernetMatchBuilder = new
1288 * EthernetMatchBuilder();
1290 * MacAddressMatchEntry macAddressMatch =
1291 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1292 * MaskMatchEntry maskMatch =
1293 * matchEntry.getAugmentation(MaskMatchEntry.class);
1294 * EthernetDestinationBuilder ethernetDestination = new
1295 * EthernetDestinationBuilder();
1296 * ethernetDestination.setAddress(macAddressMatch.getMacAddress());
1297 * if(maskMatch != null){
1298 * ethernetDestination.setMask(maskMatch.getMask()); }
1299 * ethernetMatchBuilder
1300 * .setEthernetDestination(ethernetDestination.build()); }else if
1301 * (matchEntry instanceof EthSrc){ if(ethernetMatchBuilder == null)
1302 * ethernetMatchBuilder = new EthernetMatchBuilder();
1304 * MacAddressMatchEntry macAddressMatch =
1305 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1306 * MaskMatchEntry maskMatch =
1307 * matchEntry.getAugmentation(MaskMatchEntry.class);
1308 * EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
1309 * ethernetSource.setAddress(macAddressMatch.getMacAddress());
1310 * if(maskMatch != null){ ethernetSource.setMask(maskMatch.getMask()); }
1311 * ethernetMatchBuilder.setEthernetSource(ethernetSource.build()); }else
1312 * if (matchEntry instanceof EthType){ if(ethernetMatchBuilder == null)
1313 * ethernetMatchBuilder = new EthernetMatchBuilder();
1315 * EthTypeMatchEntry etherTypeMatch =
1316 * matchEntry.getAugmentation(EthTypeMatchEntry.class);
1317 * EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
1319 * .yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType etherType
1321 * org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827
1322 * .EtherType((long)etherTypeMatch.getEthType().getValue());
1323 * ethernetType.setType(etherType);
1324 * ethernetMatchBuilder.setEthernetType(ethernetType.build()); }else if
1325 * (matchEntry instanceof VlanVid){ if(vlanMatchBuilder == null)
1326 * vlanMatchBuilder = new VlanMatchBuilder();
1328 * VlanVidMatchEntry vlanVidMatch =
1329 * matchEntry.getAugmentation(VlanVidMatchEntry.class); MaskMatchEntry
1330 * maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
1332 * VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
1333 * vlanIdBuilder.setVlanId( new
1334 * org.opendaylight.yang.gen.v1.urn.opendaylight
1335 * .l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid())); if(maskMatch
1336 * != null){ vlanIdBuilder.setMask(maskMatch.getMask()); }
1337 * vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
1339 * }else if (matchEntry instanceof VlanPcp){ if(vlanMatchBuilder ==
1340 * null) vlanMatchBuilder = new VlanMatchBuilder();
1342 * VlanPcpMatchEntry vlanPcpMatch =
1343 * matchEntry.getAugmentation(VlanPcpMatchEntry.class);
1344 * vlanMatchBuilder.setVlanPcp( new
1345 * org.opendaylight.yang.gen.v1.urn.opendaylight
1346 * .l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp())); }else if
1347 * (matchEntry instanceof IpDscp){ if(ipMatchBuilder == null)
1348 * ipMatchBuilder = new IpMatchBuilder();
1350 * DscpMatchEntry dscpMatchEntry =
1351 * matchEntry.getAugmentation(DscpMatchEntry.class);
1352 * ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
1354 * }else if (matchEntry instanceof IpEcn){ if(ipMatchBuilder == null)
1355 * ipMatchBuilder = new IpMatchBuilder();
1357 * EcnMatchEntry ecnMatchEntry =
1358 * matchEntry.getAugmentation(EcnMatchEntry.class);
1359 * ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
1361 * }else if (matchEntry instanceof IpProto){ if(ipMatchBuilder == null)
1362 * ipMatchBuilder = new IpMatchBuilder();
1364 * ProtocolNumberMatchEntry protocolNumberMatch =
1365 * matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
1367 * .setIpProtocol(protocolNumberMatch.getProtocolNumber()); }else if
1368 * (matchEntry instanceof TcpSrc){ if(tcpMatchBuilder == null)
1369 * tcpMatchBuilder = new TcpMatchBuilder();
1371 * PortMatchEntry portMatchEntry =
1372 * matchEntry.getAugmentation(PortMatchEntry.class);
1373 * tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
1375 * }else if (matchEntry instanceof TcpDst){ if(tcpMatchBuilder == null)
1376 * tcpMatchBuilder = new TcpMatchBuilder();
1378 * PortMatchEntry portMatchEntry =
1379 * matchEntry.getAugmentation(PortMatchEntry.class);
1380 * tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
1382 * }else if (matchEntry instanceof UdpSrc){ if(udpMatchBuilder == null)
1383 * udpMatchBuilder = new UdpMatchBuilder();
1385 * PortMatchEntry portMatchEntry =
1386 * matchEntry.getAugmentation(PortMatchEntry.class);
1387 * udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
1390 * }else if (matchEntry instanceof UdpDst){ if(udpMatchBuilder == null)
1391 * udpMatchBuilder = new UdpMatchBuilder();
1393 * PortMatchEntry portMatchEntry =
1394 * matchEntry.getAugmentation(PortMatchEntry.class);
1395 * udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
1396 * }else if (matchEntry instanceof SctpSrc){ if(sctpMatchBuilder ==
1397 * null) sctpMatchBuilder = new SctpMatchBuilder();
1399 * PortMatchEntry portMatchEntry =
1400 * matchEntry.getAugmentation(PortMatchEntry.class);
1401 * sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
1403 * }else if (matchEntry instanceof SctpDst){ if(sctpMatchBuilder ==
1404 * null) sctpMatchBuilder = new SctpMatchBuilder();
1406 * PortMatchEntry portMatchEntry =
1407 * matchEntry.getAugmentation(PortMatchEntry.class);
1408 * sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
1409 * }else if (matchEntry instanceof Icmpv4Type){ if(icmpv4MatchBuilder ==
1410 * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1412 * Icmpv4TypeMatchEntry icmpv4TypeMatchEntry =
1413 * matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
1414 * icmpv4MatchBuilder
1415 * .setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
1417 * }else if (matchEntry instanceof Icmpv4Code){ if(icmpv4MatchBuilder ==
1418 * null) icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1420 * Icmpv4CodeMatchEntry icmpv4CodeMatchEntry =
1421 * matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
1422 * icmpv4MatchBuilder
1423 * .setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
1425 * }else if (matchEntry instanceof Icmpv6Type){ if(icmpv6MatchBuilder ==
1426 * null) icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1428 * Icmpv6TypeMatchEntry icmpv6TypeMatchEntry =
1429 * matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
1430 * icmpv6MatchBuilder
1431 * .setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type()); }else if
1432 * (matchEntry instanceof Icmpv6Code){ if(icmpv6MatchBuilder == null)
1433 * icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1435 * Icmpv6CodeMatchEntry icmpv6CodeMatchEntry =
1436 * matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
1437 * icmpv6MatchBuilder
1438 * .setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code()); }else if
1439 * (matchEntry instanceof Ipv4Src){ if(ipv4MatchBuilder == null)
1440 * ipv4MatchBuilder = new Ipv4MatchBuilder();
1442 * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1443 * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1444 * MaskMatchEntry maskMatchEntry =
1445 * matchEntry.getAugmentation(MaskMatchEntry.class);
1446 * ipv4MatchBuilder.setIpv4Source( new
1447 * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1448 * String(maskMatchEntry.getMask())));
1450 * }else if (matchEntry instanceof Ipv4Dst){ if(ipv4MatchBuilder ==
1451 * null) ipv4MatchBuilder = new Ipv4MatchBuilder();
1453 * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1454 * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1455 * MaskMatchEntry maskMatchEntry =
1456 * matchEntry.getAugmentation(MaskMatchEntry.class);
1457 * ipv4MatchBuilder.setIpv4Destination( new
1458 * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1459 * String(maskMatchEntry.getMask()))); }else if (matchEntry instanceof
1460 * ArpOp){ if(arpMatchBuilder == null) arpMatchBuilder = new
1461 * ArpMatchBuilder();
1463 * OpCodeMatchEntry opCodeMatchEntry =
1464 * matchEntry.getAugmentation(OpCodeMatchEntry.class);
1465 * arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
1467 * }else if (matchEntry instanceof ArpSpa){ if(arpMatchBuilder == null)
1468 * arpMatchBuilder = new ArpMatchBuilder();
1470 * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1471 * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1472 * MaskMatchEntry maskMatchEntry =
1473 * matchEntry.getAugmentation(MaskMatchEntry.class);
1474 * arpMatchBuilder.setArpSourceTransportAddress( new
1475 * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1476 * String(maskMatchEntry.getMask())));
1478 * }else if (matchEntry instanceof ArpTpa){ if(arpMatchBuilder == null)
1479 * arpMatchBuilder = new ArpMatchBuilder();
1481 * Ipv4AddressMatchEntry ipv4AddressMatchEntry =
1482 * matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1483 * MaskMatchEntry maskMatchEntry =
1484 * matchEntry.getAugmentation(MaskMatchEntry.class);
1485 * arpMatchBuilder.setArpTargetTransportAddress( new
1486 * Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue() +"/"+new
1487 * String(maskMatchEntry.getMask())));
1489 * }else if (matchEntry instanceof ArpSha){ if(arpMatchBuilder == null)
1490 * arpMatchBuilder = new ArpMatchBuilder();
1492 * MacAddressMatchEntry macAddressMatchEntry =
1493 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1494 * MaskMatchEntry maskMatchEntry =
1495 * matchEntry.getAugmentation(MaskMatchEntry.class);
1496 * ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new
1497 * ArpSourceHardwareAddressBuilder();
1498 * arpSourceHardwareAddressBuilder.setAddress
1499 * (macAddressMatchEntry.getMacAddress());
1500 * arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1502 * .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
1505 * }else if (matchEntry instanceof ArpTha){ if(arpMatchBuilder == null)
1506 * arpMatchBuilder = new ArpMatchBuilder();
1508 * MacAddressMatchEntry macAddressMatchEntry =
1509 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1510 * MaskMatchEntry maskMatchEntry =
1511 * matchEntry.getAugmentation(MaskMatchEntry.class);
1512 * ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new
1513 * ArpTargetHardwareAddressBuilder();
1514 * arpTargetHardwareAddressBuilder.setAddress
1515 * (macAddressMatchEntry.getMacAddress());
1516 * arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1518 * .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
1519 * .build()); }else if (matchEntry instanceof Ipv6Src){
1520 * if(ipv6MatchBuilder == null) ipv6MatchBuilder = new
1521 * Ipv6MatchBuilder();
1523 * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1524 * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1525 * MaskMatchEntry maskMatchEntry =
1526 * matchEntry.getAugmentation(MaskMatchEntry.class);
1527 * ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix
1528 * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1529 * String(maskMatchEntry.getMask())));
1531 * }else if (matchEntry instanceof Ipv6Dst){ if(ipv6MatchBuilder ==
1532 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1534 * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1535 * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1536 * MaskMatchEntry maskMatchEntry =
1537 * matchEntry.getAugmentation(MaskMatchEntry.class);
1538 * ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix
1539 * (ipv6AddressMatchEntry.getIpv6Address().getValue()+ "/"+new
1540 * String(maskMatchEntry.getMask())));
1542 * }else if (matchEntry instanceof Ipv6Flabel){ if(ipv6MatchBuilder ==
1543 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1545 * Ipv6FlabelMatchEntry ipv6FlabelMatchEntry =
1546 * matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
1547 * MaskMatchEntry maskMatchEntry =
1548 * matchEntry.getAugmentation(MaskMatchEntry.class); Ipv6LabelBuilder
1549 * ipv6LabelBuilder = new Ipv6LabelBuilder();
1550 * ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
1551 * ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
1552 * ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1554 * }else if (matchEntry instanceof Ipv6NdTarget){ if(ipv6MatchBuilder ==
1555 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1556 * Ipv6AddressMatchEntry ipv6AddressMatchEntry =
1557 * matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1559 * .setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
1561 * }else if (matchEntry instanceof Ipv6NdSll){ if(ipv6MatchBuilder ==
1562 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1564 * MacAddressMatchEntry macAddressMatchEntry =
1565 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1566 * ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
1567 * }else if (matchEntry instanceof Ipv6NdTll){ if(ipv6MatchBuilder ==
1568 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1570 * MacAddressMatchEntry macAddressMatchEntry =
1571 * matchEntry.getAugmentation(MacAddressMatchEntry.class);
1572 * ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
1574 * }else if (matchEntry instanceof Ipv6Exthdr){ if(ipv6MatchBuilder ==
1575 * null) ipv6MatchBuilder = new Ipv6MatchBuilder();
1577 * PseudoFieldMatchEntry pseudoFieldMatchEntry =
1578 * matchEntry.getAugmentation(PseudoFieldMatchEntry.class); PseudoField
1579 * pseudoField = pseudoFieldMatchEntry.getPseudoField(); int
1580 * pseudoFieldInt = 0; pseudoFieldInt |= pseudoField.isNonext()?(1 <<
1581 * 0):~(1 << 0); pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 <<
1582 * 1); pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
1583 * pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
1584 * pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
1585 * pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
1586 * pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
1587 * pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
1588 * pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
1590 * ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt); }else if (matchEntry
1591 * instanceof MplsLabel){ if(protocolMatchFieldsBuilder == null)
1592 * protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1594 * MplsLabelMatchEntry MplsLabelMatchEntry =
1595 * matchEntry.getAugmentation(MplsLabelMatchEntry.class);
1596 * protocolMatchFieldsBuilder
1597 * .setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
1599 * }else if (matchEntry instanceof MplsBos){
1600 * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1601 * new ProtocolMatchFieldsBuilder();
1603 * BosMatchEntry bosMatchEntry =
1604 * matchEntry.getAugmentation(BosMatchEntry.class);
1605 * protocolMatchFieldsBuilder
1606 * .setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
1608 * }else if (matchEntry instanceof MplsTc) {
1609 * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1610 * new ProtocolMatchFieldsBuilder();
1612 * TcMatchEntry tcMatchEntry =
1613 * matchEntry.getAugmentation(TcMatchEntry.class);
1614 * protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
1616 * }else if (matchEntry instanceof PbbIsid){
1617 * if(protocolMatchFieldsBuilder == null) protocolMatchFieldsBuilder =
1618 * new ProtocolMatchFieldsBuilder();
1620 * IsidMatchEntry isidMatchEntry =
1621 * matchEntry.getAugmentation(IsidMatchEntry.class); PbbBuilder
1622 * pbbBuilder = new PbbBuilder();
1623 * pbbBuilder.setPbbIsid(isidMatchEntry.getIsid()); MaskMatchEntry
1624 * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1625 * if(maskMatchEntry != null)
1626 * pbbBuilder.setPbbMask(maskMatchEntry.getMask());
1628 * protocolMatchFieldsBuilder.setPbb(pbbBuilder.build()); }else if
1629 * (matchEntry instanceof TunnelId){ MetadataMatchEntry
1630 * metadataMatchEntry =
1631 * matchEntry.getAugmentation(MetadataMatchEntry.class); MaskMatchEntry
1632 * maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1633 * TunnelBuilder tunnelBuilder = new TunnelBuilder();
1634 * tunnelBuilder.setTunnelId(new
1635 * BigInteger(metadataMatchEntry.getMetadata()));
1636 * tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
1637 * match.setTunnel(tunnelBuilder.build()); } } if(ethernetMatchBuilder
1638 * != null){ match.setEthernetMatch(ethernetMatchBuilder.build()); } if
1639 * (vlanMatchBuilder != null){
1640 * match.setVlanMatch(vlanMatchBuilder.build()); } if(ipMatchBuilder !=
1641 * null){ match.setIpMatch(ipMatchBuilder.build()); } if(tcpMatchBuilder
1642 * != null){ match.setLayer4Match(tcpMatchBuilder.build()); }
1643 * if(udpMatchBuilder != null){
1644 * match.setLayer4Match(udpMatchBuilder.build()); } if(sctpMatchBuilder
1645 * != null){ match.setLayer4Match(sctpMatchBuilder.build()); }
1646 * if(icmpv4MatchBuilder != null){
1647 * match.setIcmpv4Match(icmpv4MatchBuilder.build()); }
1648 * if(icmpv6MatchBuilder != null){
1649 * match.setIcmpv6Match(icmpv6MatchBuilder.build()); }
1650 * if(ipv4MatchBuilder != null){
1651 * match.setLayer3Match(ipv4MatchBuilder.build()); } if(arpMatchBuilder
1652 * != null){ match.setLayer3Match(arpMatchBuilder.build()); }
1653 * if(ipv6MatchBuilder != null){
1654 * match.setLayer3Match(ipv6MatchBuilder.build()); }
1655 * if(protocolMatchFieldsBuilder != null){
1656 * match.setProtocolMatchFields(protocolMatchFieldsBuilder.build()); }
1657 * setField.setMatch(match.build());
1658 */return setField.build();