2 * Copyright (c) 2013, 2015 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 static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
13 import com.google.common.base.Optional;
14 import java.math.BigInteger;
15 import java.nio.ByteBuffer;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.List;
19 import javax.annotation.Nonnull;
20 import org.opendaylight.openflowjava.util.ByteBufUtils;
21 import org.opendaylight.openflowplugin.api.OFConstants;
22 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
23 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
24 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
25 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.IpConversionUtil;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.OFApprovedExperimenterIds;
28 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
29 import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
30 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
31 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMask;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchArbitraryBitMaskBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMask;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchArbitraryBitMaskBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlags;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlagsContainer;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlagsContainerBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.oxm.container.match.entry.value.experimenter.id._case.TcpFlagsBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCaseBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.experimenter.id._case.ExperimenterBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldAction;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpOp;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpSha;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpSpa;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTha;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTpa;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthType;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Type;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Code;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Type;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpDscp;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpEcn;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.IpProto;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Exthdr;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Flabel;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdSll;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdTarget;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdTll;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Metadata;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsBos;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsLabel;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MplsTc;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.PbbIsid;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.SctpDst;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.SctpSrc;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TunnelId;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpDst;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpSrc;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanPcp;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.*;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.op._case.ArpOpBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.sha._case.ArpShaBuilder;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.spa._case.ArpSpaBuilder;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tha._case.ArpThaBuilder;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tpa._case.ArpTpaBuilder;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDstBuilder;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrcBuilder;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.type._case.EthTypeBuilder;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4CodeBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4TypeBuilder;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.code._case.Icmpv6CodeBuilder;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6TypeBuilder;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.phy.port._case.InPhyPortBuilder;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.in.port._case.InPortBuilder;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.dscp._case.IpDscpBuilder;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.ecn._case.IpEcnBuilder;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.proto._case.IpProtoBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4DstBuilder;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4SrcBuilder;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6DstBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.exthdr._case.Ipv6ExthdrBuilder;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.flabel._case.Ipv6FlabelBuilder;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.sll._case.Ipv6NdSllBuilder;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.target._case.Ipv6NdTargetBuilder;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.tll._case.Ipv6NdTllBuilder;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder;
185 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.bos._case.MplsBosBuilder;
186 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabelBuilder;
187 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.tc._case.MplsTcBuilder;
188 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.pbb.isid._case.PbbIsidBuilder;
189 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.dst._case.SctpDstBuilder;
190 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.src._case.SctpSrcBuilder;
191 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder;
192 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder;
193 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelIdBuilder;
194 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.dst._case.UdpDstBuilder;
195 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrcBuilder;
196 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.pcp._case.VlanPcpBuilder;
197 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder;
198 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
199 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
200 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
201 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
202 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst;
203 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src;
204 import org.slf4j.Logger;
205 import org.slf4j.LoggerFactory;
208 * Utility class for converting a MD-SAL Flow into the OF flow mod
210 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntry>> {
211 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
212 private static final byte[] VLAN_VID_MASK = new byte[]{16, 0};
213 private static final short PROTO_TCP = 6;
214 private static final short PROTO_UDP = 17;
215 private static final short PROTO_ICMPV4 = 1;
216 private static final String NO_IP = "0.0.0.0/0";
218 // Pre-calculated masks for the 33 possible values. Do not give them out, but clone() them as they may
219 // end up being leaked and vulnerable.
220 private static final byte[][] IPV4_MASKS;
222 final byte[][] tmp = new byte[33][];
223 for (int i = 0; i <= 32; ++i) {
224 final int mask = 0xffffffff << (32 - i);
225 tmp[i] = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8), (byte) mask};
232 public List<MatchEntry> convert(
233 final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
234 List<MatchEntry> matchEntryList = new ArrayList<>();
236 return matchEntryList;
238 if (match.getInPort() != null) {
239 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
240 matchEntryList.add(toOfPort(InPort.class,
241 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPort())));
244 if (match.getInPhyPort() != null) {
245 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
246 matchEntryList.add(toOfPhyPort(InPhyPort.class,
247 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPhyPort())));
250 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
252 if (metadata != null) {
253 matchEntryList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
256 ethernetMatch(matchEntryList, match.getEthernetMatch());
257 vlanMatch(matchEntryList, match.getVlanMatch());
258 ipMatch(matchEntryList, match.getIpMatch());
259 layer4Match(matchEntryList, match.getLayer4Match());
260 icmpv4Match(matchEntryList, match.getIcmpv4Match());
261 icmpv6Match(matchEntryList, match.getIcmpv6Match());
262 layer3Match(matchEntryList, match.getLayer3Match());
263 protocolMatchFields(matchEntryList, match.getProtocolMatchFields());
264 tcpFlagsMatch(matchEntryList, match.getTcpFlagsMatch());
266 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
268 if (tunnel != null) {
269 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
270 TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
271 TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
272 boolean hasMask = false;
273 if (null != tunnel.getTunnelMask()) {
275 tunnelIdBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelMask(), OFConstants.SIZE_OF_LONG_IN_BYTES));
277 tunnelIdBuilder.setTunnelId(ByteUtil.convertBigIntegerToNBytes(tunnel.getTunnelId(), OFConstants.SIZE_OF_LONG_IN_BYTES));
278 tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
279 matchEntryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
280 matchEntryBuilder.setHasMask(hasMask);
281 matchEntryBuilder.setOxmMatchField(TunnelId.class);
282 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
283 matchEntryList.add(matchEntryBuilder.build());
288 * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
289 * - we might need version for conversion and for key
292 Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
293 if (extensionListOpt.isPresent()) {
294 for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
295 // TODO: get real version
296 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
297 ConvertorToOFJava<MatchEntry> convertor =
298 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
299 MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
300 matchEntryList.add(ofMatch);
304 return matchEntryList;
307 private static void tcpFlagsMatch(List<MatchEntry> matchEntryList, TcpFlagsMatch tcpFlagsMatch) {
308 ExperimenterIdCaseBuilder expIdCaseBuilder = new ExperimenterIdCaseBuilder();
309 if (tcpFlagsMatch != null) {
310 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
311 matchEntryBuilder.setOxmClass(ExperimenterClass.class);
312 matchEntryBuilder.setHasMask(false);
313 matchEntryBuilder.setOxmMatchField(TcpFlags.class);
315 TcpFlagsContainerBuilder tcpFlagsContainerBuilder = new TcpFlagsContainerBuilder();
316 TcpFlagsBuilder tcpFlagsBuilder = new TcpFlagsBuilder();
317 tcpFlagsBuilder.setFlags(tcpFlagsMatch.getTcpFlags());
318 if(tcpFlagsMatch.getTcpFlagsMask() != null) {
319 matchEntryBuilder.setHasMask(true);
320 tcpFlagsBuilder.setMask(ByteUtil.unsignedShortToBytes(tcpFlagsMatch.getTcpFlagsMask()));
322 tcpFlagsContainerBuilder.setTcpFlags(tcpFlagsBuilder.build());
324 //Set experimenter ID.
325 ExperimenterBuilder experimenterBuilder = new ExperimenterBuilder();
326 experimenterBuilder.setExperimenter(new ExperimenterId(OFApprovedExperimenterIds.MATCH_TCP_FLAGS_EXP_ID));
327 expIdCaseBuilder.setExperimenter(experimenterBuilder.build());
329 expIdCaseBuilder.addAugmentation(TcpFlagsContainer.class, tcpFlagsContainerBuilder.build());
330 matchEntryBuilder.setMatchEntryValue(expIdCaseBuilder.build());
331 matchEntryList.add(matchEntryBuilder.build());
335 private static void protocolMatchFields(final List<MatchEntry> matchEntryList,
336 final ProtocolMatchFields protocolMatchFields) {
337 if (protocolMatchFields != null) {
338 if (protocolMatchFields.getMplsLabel() != null) {
339 matchEntryList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
342 if (protocolMatchFields.getMplsBos() != null) {
343 matchEntryList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
346 if (protocolMatchFields.getMplsTc() != null) {
347 matchEntryList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
350 if (protocolMatchFields.getPbb() != null) {
351 matchEntryList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
357 private static void layer3Match(final List<MatchEntry> matchEntryList, final Layer3Match layer3Match) {
358 if (layer3Match != null) {
359 if(layer3Match instanceof Ipv6MatchArbitraryBitMask){
360 Ipv6MatchArbitraryBitMask Ipv6ArbitraryMaskMatchFields = (Ipv6MatchArbitraryBitMask) layer3Match;
361 if (Ipv6ArbitraryMaskMatchFields.getIpv6SourceAddressNoMask() != null) {
362 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
363 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
364 matchEntryBuilder.setOxmMatchField(Ipv6Src.class);
366 Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
367 Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
368 ipv6SrcBuilder.setIpv6Address(Ipv6ArbitraryMaskMatchFields.getIpv6SourceAddressNoMask());
369 Ipv6ArbitraryMask sourceArbitrarySubNetMask = Ipv6ArbitraryMaskMatchFields.getIpv6SourceArbitraryBitmask();
370 boolean hasMask = false;
371 if (sourceArbitrarySubNetMask != null) {
372 byte[] maskByteArray = IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(sourceArbitrarySubNetMask);
373 if (maskByteArray != null) {
374 ipv6SrcBuilder.setMask(maskByteArray);
378 matchEntryBuilder.setHasMask(hasMask);
379 ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
380 matchEntryBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
381 matchEntryList.add(matchEntryBuilder.build());
383 if (Ipv6ArbitraryMaskMatchFields.getIpv6DestinationAddressNoMask() != null) {
384 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
385 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
386 matchEntryBuilder.setOxmMatchField(Ipv6Dst.class);
388 Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
389 Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
391 ipv6DstBuilder.setIpv6Address(Ipv6ArbitraryMaskMatchFields.getIpv6DestinationAddressNoMask());
392 Ipv6ArbitraryMask destinationArbitrarySubNetMask = Ipv6ArbitraryMaskMatchFields.getIpv6DestinationArbitraryBitmask();
394 boolean hasMask = false;
395 if (destinationArbitrarySubNetMask != null) {
396 byte[] maskByteArray = IpConversionUtil.convertIpv6ArbitraryMaskToByteArray(destinationArbitrarySubNetMask);
397 if (maskByteArray != null) {
398 ipv6DstBuilder.setMask(maskByteArray);
402 matchEntryBuilder.setHasMask(hasMask);
403 ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
404 matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
405 matchEntryList.add(matchEntryBuilder.build());
408 if(layer3Match instanceof Ipv4MatchArbitraryBitMask) {
409 Ipv4MatchArbitraryBitMask ipv4MatchArbitraryBitMaskFields = (Ipv4MatchArbitraryBitMask) layer3Match;
410 if (ipv4MatchArbitraryBitMaskFields.getIpv4SourceAddressNoMask() != null) {
411 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
412 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
413 matchEntryBuilder.setOxmMatchField(Ipv4Src.class);
415 Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
416 Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
418 ipv4SrcBuilder.setIpv4Address(ipv4MatchArbitraryBitMaskFields.getIpv4SourceAddressNoMask());
419 DottedQuad sourceArbitrarySubNetMask = ipv4MatchArbitraryBitMaskFields.getIpv4SourceArbitraryBitmask();
421 boolean hasMask = false;
422 if (sourceArbitrarySubNetMask != null) {
423 byte[] maskByteArray = IpConversionUtil.convertArbitraryMaskToByteArray(sourceArbitrarySubNetMask);
424 if (maskByteArray != null) {
425 ipv4SrcBuilder.setMask(maskByteArray);
429 matchEntryBuilder.setHasMask(hasMask);
430 ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
431 matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
432 matchEntryList.add(matchEntryBuilder.build());
434 if (ipv4MatchArbitraryBitMaskFields.getIpv4DestinationAddressNoMask() != null) {
435 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
436 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
437 matchEntryBuilder.setOxmMatchField(Ipv4Dst.class);
439 Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
440 Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
442 ipv4DstBuilder.setIpv4Address(ipv4MatchArbitraryBitMaskFields.getIpv4DestinationAddressNoMask());
443 DottedQuad destArbitrarySubNetMask = ipv4MatchArbitraryBitMaskFields.getIpv4DestinationArbitraryBitmask();
445 boolean hasMask = false;
446 if (destArbitrarySubNetMask != null) {
447 byte[] maskByteArray = IpConversionUtil.convertArbitraryMaskToByteArray(destArbitrarySubNetMask);
448 if (maskByteArray != null) {
449 ipv4DstBuilder.setMask(maskByteArray);
453 matchEntryBuilder.setHasMask(hasMask);
454 ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
455 matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
456 matchEntryList.add(matchEntryBuilder.build());
459 if(layer3Match instanceof Ipv4Match){
460 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
461 if (ipv4Match.getIpv4Source() != null) {
462 Ipv4Prefix ipv4Prefix = ipv4Match.getIpv4Source();
463 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
464 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
465 matchEntryBuilder.setOxmMatchField(Ipv4Src.class);
467 Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
468 Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
470 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
471 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
472 ipv4SrcBuilder.setIpv4Address(ipv4Address);
473 boolean hasMask = false;
474 byte[] mask = extractIpv4Mask(addressParts);
476 ipv4SrcBuilder.setMask(mask);
479 matchEntryBuilder.setHasMask(hasMask);
480 ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
481 matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
482 matchEntryList.add(matchEntryBuilder.build());
484 if (ipv4Match.getIpv4Destination() != null) {
485 Ipv4Prefix ipv4Prefix = ipv4Match.getIpv4Destination();
486 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
487 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
488 matchEntryBuilder.setOxmMatchField(Ipv4Dst.class);
490 Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
491 Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
493 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
494 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
495 ipv4DstBuilder.setIpv4Address(ipv4Address);
496 boolean hasMask = false;
497 byte[] mask = extractIpv4Mask(addressParts);
499 ipv4DstBuilder.setMask(mask);
502 matchEntryBuilder.setHasMask(hasMask);
503 ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
504 matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
505 matchEntryList.add(matchEntryBuilder.build());
508 if (layer3Match instanceof TunnelIpv4Match) {
509 TunnelIpv4Match tunnelIpv4Src = (TunnelIpv4Match) layer3Match;
510 if (tunnelIpv4Src.getTunnelIpv4Source() != null) {
511 Ipv4Prefix ipv4Prefix = tunnelIpv4Src.getTunnelIpv4Source();
512 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
513 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
514 matchEntryBuilder.setOxmMatchField(Ipv4Src.class);
516 Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder();
517 Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder();
519 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
520 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
521 ipv4SrcBuilder.setIpv4Address(ipv4Address);
522 boolean hasMask = false;
523 byte[] mask = extractIpv4Mask(addressParts);
525 ipv4SrcBuilder.setMask(mask);
528 matchEntryBuilder.setHasMask(hasMask);
529 ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build());
530 matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build());
531 matchEntryList.add(matchEntryBuilder.build());
533 if (tunnelIpv4Src.getTunnelIpv4Destination() != null) {
534 Ipv4Prefix ipv4Prefix = tunnelIpv4Src.getTunnelIpv4Destination();
535 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
536 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
537 matchEntryBuilder.setOxmMatchField(Ipv4Dst.class);
539 Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
540 Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
542 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
543 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
544 ipv4DstBuilder.setIpv4Address(ipv4Address);
545 boolean hasMask = false;
546 byte[] mask = extractIpv4Mask(addressParts);
548 ipv4DstBuilder.setMask(mask);
551 matchEntryBuilder.setHasMask(hasMask);
552 ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
553 matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
554 matchEntryList.add(matchEntryBuilder.build());
556 } else if (layer3Match instanceof ArpMatch) {
557 ArpMatch arpMatch = (ArpMatch) layer3Match;
558 if (arpMatch.getArpOp() != null) {
559 matchEntryList.add(toOfArpOpCode(arpMatch.getArpOp()));
562 if (arpMatch.getArpSourceTransportAddress() != null) {
563 Ipv4Prefix ipv4Prefix = arpMatch.getArpSourceTransportAddress();
564 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
565 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
566 matchEntryBuilder.setOxmMatchField(ArpSpa.class);
568 ArpSpaCaseBuilder arpSpaCaseBuilder = new ArpSpaCaseBuilder();
569 ArpSpaBuilder arpSpaBuilder = new ArpSpaBuilder();
571 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
572 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
573 arpSpaBuilder.setIpv4Address(ipv4Address);
574 boolean hasMask = false;
575 byte[] mask = extractIpv4Mask(addressParts);
577 arpSpaBuilder.setMask(mask);
580 matchEntryBuilder.setHasMask(hasMask);
581 arpSpaCaseBuilder.setArpSpa(arpSpaBuilder.build());
582 matchEntryBuilder.setMatchEntryValue(arpSpaCaseBuilder.build());
583 matchEntryList.add(matchEntryBuilder.build());
586 if (arpMatch.getArpTargetTransportAddress() != null) {
587 Ipv4Prefix ipv4Prefix = arpMatch.getArpTargetTransportAddress();
588 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
589 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
590 matchEntryBuilder.setOxmMatchField(ArpTpa.class);
592 ArpTpaCaseBuilder arpTpaCaseBuilder = new ArpTpaCaseBuilder();
593 ArpTpaBuilder arpTpaBuilder = new ArpTpaBuilder();
595 Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
596 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
597 arpTpaBuilder.setIpv4Address(ipv4Address);
598 boolean hasMask = false;
599 byte[] mask = extractIpv4Mask(addressParts);
601 arpTpaBuilder.setMask(mask);
604 matchEntryBuilder.setHasMask(hasMask);
605 arpTpaCaseBuilder.setArpTpa(arpTpaBuilder.build());
606 matchEntryBuilder.setMatchEntryValue(arpTpaCaseBuilder.build());
607 matchEntryList.add(matchEntryBuilder.build());
610 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
611 if (arpSourceHardwareAddress != null) {
612 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
613 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
614 matchEntryBuilder.setOxmMatchField(ArpSha.class);
616 ArpShaCaseBuilder arpShaCaseBuilder = new ArpShaCaseBuilder();
617 ArpShaBuilder arpShaBuilder = new ArpShaBuilder();
618 arpShaBuilder.setMacAddress(arpSourceHardwareAddress.getAddress());
619 boolean hasMask = false;
620 if (null != arpSourceHardwareAddress.getMask()) {
621 arpShaBuilder.setMask(ByteBufUtils.macAddressToBytes(arpSourceHardwareAddress.getMask().getValue()));
624 arpShaCaseBuilder.setArpSha(arpShaBuilder.build());
625 matchEntryBuilder.setMatchEntryValue(arpShaCaseBuilder.build());
626 matchEntryBuilder.setHasMask(hasMask);
627 matchEntryList.add(matchEntryBuilder.build());
630 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
631 if (arpTargetHardwareAddress != null) {
632 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
633 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
634 matchEntryBuilder.setOxmMatchField(ArpTha.class);
636 ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder();
637 ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
638 arpThaBuilder.setMacAddress(arpTargetHardwareAddress.getAddress());
639 boolean hasMask = false;
640 if (null != arpTargetHardwareAddress.getMask()) {
641 arpThaBuilder.setMask(ByteBufUtils.macAddressToBytes(arpTargetHardwareAddress.getMask().getValue()));
644 arpThaCaseBuilder.setArpTha(arpThaBuilder.build());
645 matchEntryBuilder.setMatchEntryValue(arpThaCaseBuilder.build());
646 matchEntryBuilder.setHasMask(hasMask);
647 matchEntryList.add(matchEntryBuilder.build());
649 } else if (layer3Match instanceof Ipv6Match) {
650 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
651 if (ipv6Match.getIpv6Source() != null) {
652 Ipv6Prefix ipv6Prefix = ipv6Match.getIpv6Source();
653 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
654 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
655 matchEntryBuilder.setOxmMatchField(Ipv6Src.class);
657 Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder();
658 Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder();
659 final Integer prefix = IpConversionUtil.extractIpv6Prefix(ipv6Prefix);
660 boolean hasMask = false;
661 if (null != prefix) {
662 ipv6SrcBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
665 ipv6SrcBuilder.setIpv6Address(IpConversionUtil.extractIpv6Address(ipv6Prefix));
666 ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build());
667 matchEntryBuilder.setHasMask(hasMask);
668 matchEntryBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build());
669 matchEntryList.add(matchEntryBuilder.build());
672 if (ipv6Match.getIpv6Destination() != null) {
673 Ipv6Prefix ipv6Prefix = ipv6Match.getIpv6Destination();
674 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
675 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
676 matchEntryBuilder.setOxmMatchField(Ipv6Dst.class);
678 Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
679 Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
680 final Integer prefix = IpConversionUtil.extractIpv6Prefix(ipv6Prefix);
681 boolean hasMask = false;
682 if (null != prefix) {
683 ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
686 ipv6DstBuilder.setIpv6Address(IpConversionUtil.extractIpv6Address(ipv6Prefix));
687 ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
688 matchEntryBuilder.setHasMask(hasMask);
689 matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
690 matchEntryList.add(matchEntryBuilder.build());
693 if (ipv6Match.getIpv6Label() != null) {
694 matchEntryList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
697 if (ipv6Match.getIpv6NdTarget() != null) {
698 matchEntryList.add(toOfIpv6NdTargetAddress(ipv6Match.getIpv6NdTarget()));
701 if (ipv6Match.getIpv6NdSll() != null) {
702 MacAddress ipv6NdSll = ipv6Match.getIpv6NdSll();
703 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
704 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
705 matchEntryBuilder.setOxmMatchField(Ipv6NdSll.class);
707 Ipv6NdSllCaseBuilder ipv6NdSllCaseBuilder = new Ipv6NdSllCaseBuilder();
708 Ipv6NdSllBuilder ipv6NdSllBuilder = new Ipv6NdSllBuilder();
709 ipv6NdSllBuilder.setMacAddress(ipv6NdSll);
710 ipv6NdSllCaseBuilder.setIpv6NdSll(ipv6NdSllBuilder.build());
711 matchEntryBuilder.setMatchEntryValue(ipv6NdSllCaseBuilder.build());
712 matchEntryBuilder.setHasMask(false);
713 matchEntryList.add(matchEntryBuilder.build());
716 if (ipv6Match.getIpv6NdTll() != null) {
717 MacAddress ipv6NdSll = ipv6Match.getIpv6NdTll();
718 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
719 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
720 matchEntryBuilder.setOxmMatchField(Ipv6NdTll.class);
722 Ipv6NdTllCaseBuilder ipv6NdTllCaseBuilder = new Ipv6NdTllCaseBuilder();
723 Ipv6NdTllBuilder ipv6NdTllBuilder = new Ipv6NdTllBuilder();
724 ipv6NdTllBuilder.setMacAddress(ipv6NdSll);
725 ipv6NdTllCaseBuilder.setIpv6NdTll(ipv6NdTllBuilder.build());
726 matchEntryBuilder.setMatchEntryValue(ipv6NdTllCaseBuilder.build());
727 matchEntryBuilder.setHasMask(false);
728 matchEntryList.add(matchEntryBuilder.build());
732 if (ipv6Match.getIpv6ExtHeader() != null) {
733 matchEntryList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
740 private static void icmpv6Match(final List<MatchEntry> matchEntryList, final Icmpv6Match icmpv6Match) {
741 if (icmpv6Match != null) {
742 if (icmpv6Match.getIcmpv6Type() != null) {
743 matchEntryList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
746 if (icmpv6Match.getIcmpv6Code() != null) {
747 matchEntryList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
753 private static void icmpv4Match(final List<MatchEntry> matchEntryList, final Icmpv4Match icmpv4Match) {
754 if (icmpv4Match != null) {
755 if (icmpv4Match.getIcmpv4Type() != null) {
756 matchEntryList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
759 if (icmpv4Match.getIcmpv4Code() != null) {
760 matchEntryList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
766 private static void layer4Match(final List<MatchEntry> matchEntryList, final Layer4Match layer4Match) {
767 if (layer4Match != null) {
768 if (layer4Match instanceof TcpMatch) {
769 TcpMatch tcpMatch = (TcpMatch) layer4Match;
771 if (tcpMatch.getTcpSourcePort() != null) {
772 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
773 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
774 matchEntryBuilder.setOxmMatchField(TcpSrc.class);
776 TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
777 TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
778 tcpSrcBuilder.setPort(tcpMatch.getTcpSourcePort());
779 tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
781 matchEntryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
782 matchEntryBuilder.setHasMask(false);
783 matchEntryList.add(matchEntryBuilder.build());
785 if (tcpMatch.getTcpDestinationPort() != null) {
786 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
787 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
788 matchEntryBuilder.setOxmMatchField(TcpDst.class);
790 TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder();
791 TcpDstBuilder tcpDstBuilder = new TcpDstBuilder();
792 tcpDstBuilder.setPort(tcpMatch.getTcpDestinationPort());
793 tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build());
794 matchEntryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build());
795 matchEntryBuilder.setHasMask(false);
796 matchEntryList.add(matchEntryBuilder.build());
798 } else if (layer4Match instanceof UdpMatch) {
799 UdpMatch udpMatch = (UdpMatch) layer4Match;
800 if (udpMatch.getUdpSourcePort() != null) {
801 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
802 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
803 matchEntryBuilder.setOxmMatchField(UdpSrc.class);
805 UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
806 UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
807 boolean hasMask = false;
808 udpSrcBuilder.setPort(udpMatch.getUdpSourcePort());
809 udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
810 matchEntryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
811 matchEntryBuilder.setHasMask(hasMask);
812 matchEntryList.add(matchEntryBuilder.build());
815 if (udpMatch.getUdpDestinationPort() != null) {
816 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
817 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
818 matchEntryBuilder.setOxmMatchField(UdpDst.class);
820 UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder();
821 UdpDstBuilder udpDstBuilder = new UdpDstBuilder();
822 udpDstBuilder.setPort(udpMatch.getUdpDestinationPort());
823 udpDstCaseBuilder.setUdpDst(udpDstBuilder.build());
824 matchEntryBuilder.setMatchEntryValue(udpDstCaseBuilder.build());
825 matchEntryBuilder.setHasMask(false);
826 matchEntryList.add(matchEntryBuilder.build());
828 } else if (layer4Match instanceof SctpMatch) {
829 SctpMatch sctpMatch = (SctpMatch) layer4Match;
830 if (sctpMatch.getSctpSourcePort() != null) {
831 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
832 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
833 matchEntryBuilder.setOxmMatchField(SctpSrc.class);
835 SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder();
836 SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder();
837 sctpSrcBuilder.setPort(sctpMatch.getSctpSourcePort());
838 sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build());
839 matchEntryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build());
840 matchEntryBuilder.setHasMask(false);
841 matchEntryList.add(matchEntryBuilder.build());
844 if (sctpMatch.getSctpDestinationPort() != null) {
845 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
846 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
847 matchEntryBuilder.setOxmMatchField(SctpDst.class);
849 SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder();
850 SctpDstBuilder sctpDstBuilder = new SctpDstBuilder();
851 sctpDstBuilder.setPort(sctpMatch.getSctpDestinationPort());
852 sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build());
853 matchEntryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build());
854 matchEntryBuilder.setHasMask(false);
855 matchEntryList.add(matchEntryBuilder.build());
862 private static void ipMatch(final List<MatchEntry> matchEntryList, final IpMatch ipMatch) {
863 if (ipMatch != null) {
864 if (ipMatch.getIpDscp() != null) {
865 matchEntryList.add(toOfIpDscp(ipMatch.getIpDscp()));
868 if (ipMatch.getIpEcn() != null) {
869 matchEntryList.add(toOfIpEcn(ipMatch.getIpEcn()));
872 if (ipMatch.getIpProtocol() != null) {
873 matchEntryList.add(toOfIpProto(ipMatch.getIpProtocol()));
879 private static void vlanMatch(final List<MatchEntry> matchEntryList, final VlanMatch vlanMatch) {
880 if (vlanMatch != null) {
881 if (vlanMatch.getVlanId() != null) {
882 VlanId vlanId = vlanMatch.getVlanId();
883 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
884 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
885 matchEntryBuilder.setOxmMatchField(VlanVid.class);
887 VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder();
888 VlanVidBuilder vlanVidBuilder = new VlanVidBuilder();
889 boolean setCfiBit = false;
890 Integer vidEntryValue = 0;
891 boolean hasmask = false;
892 if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
894 if (vlanId.getVlanId() != null) {
895 vidEntryValue = vlanId.getVlanId().getValue();
897 hasmask = (vidEntryValue == 0);
899 vlanVidBuilder.setMask(VLAN_VID_MASK);
903 vlanVidBuilder.setCfiBit(setCfiBit);
904 vlanVidBuilder.setVlanVid(vidEntryValue);
905 vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build());
906 matchEntryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build());
907 matchEntryBuilder.setHasMask(hasmask);
908 matchEntryList.add(matchEntryBuilder.build());
911 if (vlanMatch.getVlanPcp() != null) {
912 matchEntryList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
918 private static void ethernetMatch(final List<MatchEntry> matchEntryList, final EthernetMatch ethernetMatch) {
919 if (ethernetMatch != null) {
920 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
921 if (ethernetDestination != null) {
922 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
923 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
924 matchEntryBuilder.setOxmMatchField(EthDst.class);
925 EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder();
926 EthDstBuilder ethDstBuilder = new EthDstBuilder();
927 ethDstBuilder.setMacAddress(ethernetDestination.getAddress());
928 boolean hasMask = false;
929 if (null != ethernetDestination.getMask()) {
930 ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetDestination.getMask().getValue()));
933 ethDstCaseBuilder.setEthDst(ethDstBuilder.build());
934 matchEntryBuilder.setMatchEntryValue(ethDstCaseBuilder.build());
935 matchEntryBuilder.setHasMask(hasMask);
936 matchEntryList.add(matchEntryBuilder.build());
939 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
940 if (ethernetSource != null) {
941 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
942 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
943 matchEntryBuilder.setOxmMatchField(EthSrc.class);
945 EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder();
946 EthSrcBuilder ethDstBuilder = new EthSrcBuilder();
947 ethDstBuilder.setMacAddress(ethernetSource.getAddress());
948 boolean hasMask = false;
949 if (null != ethernetSource.getMask()) {
950 ethDstBuilder.setMask(ByteBufUtils.macAddressToBytes(ethernetSource.getMask().getValue()));
953 ethSrcCaseBuilder.setEthSrc(ethDstBuilder.build());
954 matchEntryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build());
955 matchEntryBuilder.setHasMask(hasMask);
956 matchEntryList.add(matchEntryBuilder.build());
959 if (ethernetMatch.getEthernetType() != null) {
960 matchEntryList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
966 private static byte[] extractIpv4Mask(final Iterator<String> addressParts) {
968 if (addressParts.hasNext()) {
969 int potentionalPrefix = Integer.parseInt(addressParts.next());
970 prefix = potentionalPrefix < 32 ? potentionalPrefix : 0;
976 // clone() is necessary to protect our constants
977 return IPV4_MASKS[prefix].clone();
983 * Method convert Openflow 1.0 specific flow match to MD-SAL format flow
985 * @param swMatch source match
986 * @param datapathid datapath id
987 * @param ofVersion openflow version
988 * @return match builder
990 public static MatchBuilder fromOFMatchV10ToSALMatch(@Nonnull final MatchV10 swMatch, @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
991 MatchBuilder matchBuilder = new MatchBuilder();
992 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
993 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
994 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
995 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
996 if (!swMatch.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
997 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
998 (long) swMatch.getInPort(), ofVersion));
1001 if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
1002 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
1003 ethSrcBuilder.setAddress(swMatch.getDlSrc());
1004 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
1005 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1007 if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
1008 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
1009 ethDstBuilder.setAddress(swMatch.getDlDst());
1010 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
1011 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1013 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
1014 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1015 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
1016 (long) swMatch.getDlType()));
1017 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
1018 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1020 if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
1021 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
1022 int vlanId = (swMatch.getDlVlan() == (0xffff)) ? 0 : swMatch.getDlVlan();
1023 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
1024 vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false : true);
1025 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
1026 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
1028 if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp() != null) {
1029 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
1030 swMatch.getDlVlanPcp()));
1031 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
1033 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
1034 final Ipv4Prefix prefix;
1035 if (swMatch.getNwSrcMask() != null) {
1036 prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(swMatch.getNwSrc(), swMatch.getNwSrcMask());
1038 //Openflow Spec : 1.3.2
1039 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
1040 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
1041 // statistics response.
1042 prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(swMatch.getNwSrc());
1044 if (!NO_IP.equals(prefix.getValue())) {
1045 ipv4MatchBuilder.setIpv4Source(prefix);
1046 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
1049 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
1050 final Ipv4Prefix prefix;
1051 if (swMatch.getNwDstMask() != null) {
1052 prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(swMatch.getNwDst(), swMatch.getNwDstMask());
1054 //Openflow Spec : 1.3.2
1055 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
1056 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
1057 // statistics response.
1058 prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(swMatch.getNwDst());
1060 if (!NO_IP.equals(prefix.getValue())) {
1061 ipv4MatchBuilder.setIpv4Destination(prefix);
1062 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
1065 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
1066 Short nwProto = swMatch.getNwProto();
1067 ipMatchBuilder.setIpProtocol(nwProto);
1068 matchBuilder.setIpMatch(ipMatchBuilder.build());
1070 int proto = nwProto.intValue();
1071 if (proto == PROTO_TCP) {
1072 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
1073 boolean hasTcp = false;
1074 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
1076 .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
1077 swMatch.getTpSrc()));
1080 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
1082 .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
1083 swMatch.getTpDst()));
1088 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
1090 } else if (proto == PROTO_UDP) {
1091 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
1092 boolean hasUdp = false;
1093 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
1095 .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
1096 swMatch.getTpSrc()));
1099 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
1101 .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(
1102 swMatch.getTpDst()));
1107 matchBuilder.setLayer4Match(udpMatchBuilder.build());
1109 } else if (proto == PROTO_ICMPV4) {
1110 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1111 boolean hasIcmpv4 = false;
1112 if (!swMatch.getWildcards().isTPSRC().booleanValue()) {
1113 Integer type = swMatch.getTpSrc();
1115 icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
1119 if (!swMatch.getWildcards().isTPDST().booleanValue()) {
1120 Integer code = swMatch.getTpDst();
1122 icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
1128 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
1132 if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
1133 Short dscp = ActionUtil.tosToDscp(swMatch.getNwTos().shortValue());
1134 ipMatchBuilder.setIpDscp(new Dscp(dscp));
1135 matchBuilder.setIpMatch(ipMatchBuilder.build());
1138 return matchBuilder;
1142 * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
1145 * @param swMatch source match
1146 * @param datapathid datapath id
1147 * @param ofVersion openflow version
1148 * @return md-sal match instance
1149 * @author avishnoi@in.ibm.com
1151 public static MatchBuilder fromOFMatchToSALMatch(
1152 @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
1153 @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
1154 return OfMatchToSALMatchConvertor(swMatch.getMatchEntry(), datapathid, ofVersion);
1157 private static MatchBuilder OfMatchToSALMatchConvertor(final List<MatchEntry> swMatchList, final BigInteger datapathid,
1158 final OpenflowVersion ofVersion) {
1160 MatchBuilder matchBuilder = new MatchBuilder();
1161 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
1162 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
1163 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
1164 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
1165 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
1166 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
1167 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1168 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1169 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
1170 Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder = new Ipv4MatchArbitraryBitMaskBuilder();
1171 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
1172 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
1173 Ipv6MatchArbitraryBitMaskBuilder ipv6MatchArbitraryBitMaskBuilder = new Ipv6MatchArbitraryBitMaskBuilder();
1174 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1175 TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
1176 TcpFlagsMatchBuilder tcpFlagsMatchBuilder = new TcpFlagsMatchBuilder();
1178 for (MatchEntry ofMatch : swMatchList) {
1180 if (ofMatch.getOxmMatchField().equals(InPort.class)) {
1181 PortNumber portNumber = ((InPortCase) ofMatch.getMatchEntryValue()).getInPort().getPortNumber();
1182 if (portNumber != null) {
1183 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNumber.getValue(), ofVersion));
1185 } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
1186 PortNumber portNumber = ((InPhyPortCase) ofMatch.getMatchEntryValue()).getInPhyPort().getPortNumber();
1187 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
1188 portNumber.getValue(), ofVersion));
1189 } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
1190 MetadataBuilder metadataBuilder = new MetadataBuilder();
1191 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.Metadata metadata = ((MetadataCase) ofMatch.getMatchEntryValue()).getMetadata();
1192 if (metadata != null) {
1193 metadataBuilder.setMetadata(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadata.getMetadata()));
1194 byte[] metadataMask = metadata.getMask();
1195 if (metadataMask != null) {
1196 metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, metadataMask));
1198 matchBuilder.setMetadata(metadataBuilder.build());
1200 } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
1201 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrc ethSrcCase = ((EthSrcCase) ofMatch.getMatchEntryValue()).getEthSrc();
1202 if (ethSrcCase != null) {
1203 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
1204 ethSourceBuilder.setAddress(ethSrcCase.getMacAddress());
1205 byte[] mask = ethSrcCase.getMask();
1207 ethSourceBuilder.setMask(new MacAddress(macAddressToString(mask)));
1209 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
1210 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1212 } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
1213 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDst ethDstCase = ((EthDstCase) ofMatch.getMatchEntryValue()).getEthDst();
1214 if (ethDstCase != null) {
1215 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
1216 ethDestinationBuilder.setAddress(ethDstCase.getMacAddress());
1217 byte[] destinationMask = ethDstCase.getMask();
1218 if (destinationMask != null) {
1219 ethDestinationBuilder.setMask(new MacAddress(macAddressToString(destinationMask)));
1221 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
1222 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1224 } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
1225 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.type._case.EthType ethTypeCase = ((EthTypeCase) ofMatch.getMatchEntryValue()).getEthType();
1226 if (ethTypeCase != null) {
1227 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
1229 .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
1230 (long) ethTypeCase.getEthType().getValue()));
1231 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
1232 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
1234 } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
1235 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVid vlanVid = ((VlanVidCase) ofMatch.getMatchEntryValue()).getVlanVid();
1236 if (vlanVid != null) {
1237 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
1238 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
1239 vlanVid.getVlanVid()))
1240 .setVlanIdPresent(vlanVid.isCfiBit());
1241 vlanBuilder.setVlanIdPresent(vlanVid.isCfiBit());
1242 vlanMatchBuilder.setVlanId(vlanBuilder.build());
1244 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
1246 } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
1247 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.pcp._case.VlanPcp vlanPcp = ((VlanPcpCase) ofMatch.getMatchEntryValue()).getVlanPcp();
1248 if (vlanPcp != null) {
1250 .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
1251 vlanPcp.getVlanPcp()));
1252 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
1254 } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
1255 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.dscp._case.IpDscp ipDscp = ((IpDscpCase) ofMatch.getMatchEntryValue()).getIpDscp();
1256 if (ipDscp != null) {
1257 ipMatchBuilder.setIpDscp(new Dscp(ipDscp.getDscp().getValue()));
1258 matchBuilder.setIpMatch(ipMatchBuilder.build());
1260 } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
1261 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.ecn._case.IpEcn ipEcn = ((IpEcnCase) ofMatch.getMatchEntryValue()).getIpEcn();
1262 if (ipEcn != null) {
1263 ipMatchBuilder.setIpEcn(ipEcn.getEcn());
1264 matchBuilder.setIpMatch(ipMatchBuilder.build());
1266 } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
1267 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ip.proto._case.IpProto ipProto = ((IpProtoCase) ofMatch.getMatchEntryValue()).getIpProto();
1268 Short protocolNumber = ipProto.getProtocolNumber();
1269 if (protocolNumber != null) {
1270 ipMatchBuilder.setIpProtocol(protocolNumber);
1271 matchBuilder.setIpMatch(ipMatchBuilder.build());
1273 } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
1274 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrc tcpSrc = ((TcpSrcCase) ofMatch.getMatchEntryValue()).getTcpSrc();
1275 if (tcpSrc != null) {
1276 tcpMatchBuilder.setTcpSourcePort(tcpSrc.getPort());
1277 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
1279 } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
1280 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDst tcpDst = ((TcpDstCase) ofMatch.getMatchEntryValue()).getTcpDst();
1281 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = tcpDst.getPort();
1282 if (portNumber != null) {
1283 tcpMatchBuilder.setTcpDestinationPort(portNumber);
1284 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
1286 } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
1287 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrc udpSrc = ((UdpSrcCase) ofMatch.getMatchEntryValue()).getUdpSrc();
1288 if (udpSrc != null) {
1289 udpMatchBuilder.setUdpSourcePort(udpSrc.getPort());
1290 matchBuilder.setLayer4Match(udpMatchBuilder.build());
1292 } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
1293 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.dst._case.UdpDst udpDst = ((UdpDstCase) ofMatch.getMatchEntryValue()).getUdpDst();
1294 if (udpDst != null) {
1295 udpMatchBuilder.setUdpDestinationPort(udpDst.getPort());
1296 matchBuilder.setLayer4Match(udpMatchBuilder.build());
1298 } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
1299 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.src._case.SctpSrc sctpSrc = ((SctpSrcCase) ofMatch.getMatchEntryValue()).getSctpSrc();
1300 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = sctpSrc.getPort();
1301 if (portNumber != null) {
1302 sctpMatchBuilder.setSctpSourcePort(portNumber);
1303 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
1305 } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
1306 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.sctp.dst._case.SctpDst sctpDst = ((SctpDstCase) ofMatch.getMatchEntryValue()).getSctpDst();
1307 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber portNumber = sctpDst.getPort();
1308 if (portNumber != null) {
1309 sctpMatchBuilder.setSctpDestinationPort(portNumber);
1310 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
1312 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
1313 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4Type icmpv4Type = ((Icmpv4TypeCase) ofMatch.getMatchEntryValue()).getIcmpv4Type();
1314 Short type = icmpv4Type.getIcmpv4Type();
1316 icmpv4MatchBuilder.setIcmpv4Type(type);
1317 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
1319 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
1320 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4Code icmpv4Code = ((Icmpv4CodeCase) ofMatch.getMatchEntryValue()).getIcmpv4Code();
1321 Short v4code = icmpv4Code.getIcmpv4Code();
1322 if (v4code != null) {
1323 icmpv4MatchBuilder.setIcmpv4Code(v4code);
1324 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
1326 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
1327 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6Type icmpv6Type = ((Icmpv6TypeCase) ofMatch.getMatchEntryValue()).getIcmpv6Type();
1328 Short v6type = icmpv6Type.getIcmpv6Type();
1329 if (v6type != null) {
1330 icmpv6MatchBuilder.setIcmpv6Type(v6type);
1331 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
1333 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
1334 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.code._case.Icmpv6Code icmpv6Code = ((Icmpv6CodeCase) ofMatch.getMatchEntryValue()).getIcmpv6Code();
1335 Short v6code = icmpv6Code.getIcmpv6Code();
1336 if (v6code != null) {
1337 icmpv6MatchBuilder.setIcmpv6Code(v6code);
1338 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
1340 } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
1341 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4Src ipv4Address = ((Ipv4SrcCase) ofMatch.getMatchEntryValue()).getIpv4Src();
1342 if (ipv4Address != null) {
1343 byte[] mask = ipv4Address.getMask();
1344 if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
1345 // case where ipv4dst is of type ipv4MatchBuilder and ipv4src is of type ipv4MatchArbitrary.
1346 // Needs to convert ipv4dst to ipv4MatchArbitrary.
1347 if (ipv4MatchBuilder.getIpv4Destination() != null) {
1348 Ipv4Prefix ipv4PrefixDestinationAddress = ipv4MatchBuilder.getIpv4Destination();
1349 Ipv4Address ipv4DstAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixDestinationAddress);
1350 DottedQuad dstDottedQuadMask = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixDestinationAddress);
1351 setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
1352 dstDottedQuadMask, ipv4DstAddress.getValue());
1354 DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
1355 String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
1356 setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
1357 srcDottedQuadMask, stringIpv4SrcAddress);
1358 matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
1359 } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4DestinationAddressNoMask() != null) {
1361 Case where destination is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
1362 source which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
1363 We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
1364 expected output example:-
1365 <ipv4-destination>36.36.36.0/24</ipv4-destination>
1366 <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
1367 <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
1368 after conversion output example:-
1369 <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
1370 <ipv4-destination-arbitrary-bitmask>255.255.255.0</ipv4-destination-arbitrary-bitmask>
1371 <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
1372 <ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
1374 DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
1375 String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
1376 setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
1377 srcDottedQuadMask, stringIpv4SrcAddress);
1378 matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
1380 String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
1381 setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, stringIpv4SrcAddress);
1382 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
1385 } else if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
1386 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst ipv4Address = ((Ipv4DstCase) ofMatch.getMatchEntryValue()).getIpv4Dst();
1387 if (ipv4Address != null) {
1388 byte[] mask = ipv4Address.getMask();
1389 if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
1390 // case where ipv4src is of type ipv4MatchBuilder and ipv4dst is of type ipv4MatchArbitrary.
1391 // Needs to convert ipv4src to ipv4MatchArbitrary.
1392 if (ipv4MatchBuilder.getIpv4Source() != null) {
1393 Ipv4Prefix ipv4PrefixSourceAddress = ipv4MatchBuilder.getIpv4Source();
1394 Ipv4Address ipv4SourceAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixSourceAddress);
1395 DottedQuad srcDottedQuad = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixSourceAddress);
1396 setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder,ofMatch,
1397 srcDottedQuad, ipv4SourceAddress.getValue());
1399 DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
1400 String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
1401 setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
1402 dstDottedQuadMask, stringIpv4DstAddress);
1403 matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
1404 } else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4SourceAddressNoMask() != null) {
1406 Case where source is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
1407 destination which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
1408 We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
1409 expected output example:-
1410 <ipv4-source>36.36.36.0/24</ipv4-source>
1411 <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
1412 <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
1413 after conversion output example:-
1414 <ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
1415 <ipv4-source-arbitrary-bitmask>255.255.255.0</ipv4-source-arbitrary-bitmask>
1416 <ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
1417 <ipv4-destination-arbitrary-bitmask>255.0.255.0</ipv4-destination-arbitrary-bitmask>
1419 DottedQuad dstDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
1420 String stringIpv4DstAddress = ipv4Address.getIpv4Address().getValue();
1421 setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, ofMatch,
1422 dstDottedQuadMask, stringIpv4DstAddress);
1423 matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
1426 String ipv4PrefixStr = ipv4Address.getIpv4Address().getValue();
1427 setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
1428 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
1431 } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
1432 || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
1433 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4Dst tunnelIpv4Dst = ((Ipv4DstCase) ofMatch.getMatchEntryValue()).getIpv4Dst();
1434 if (tunnelIpv4Dst != null) {
1435 String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
1436 byte[] mask = tunnelIpv4Dst.getMask();
1437 ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
1438 setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
1439 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
1441 } else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
1442 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4Src tunnelIpv4Dst = ((Ipv4SrcCase) ofMatch.getMatchEntryValue()).getIpv4Src();
1443 if (tunnelIpv4Dst != null) {
1444 String ipv4PrefixStr = tunnelIpv4Dst.getIpv4Address().getValue();
1445 byte[] mask = tunnelIpv4Dst.getMask();
1446 ipv4PrefixStr += IpConversionUtil.PREFIX_SEPARATOR + ByteBuffer.wrap(tunnelIpv4Dst.getMask()).getInt();
1447 setIpv4MatchBuilderFields(ipv4MatchBuilder, ofMatch, mask, ipv4PrefixStr);
1448 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
1450 } else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
1451 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.op._case.ArpOp arpOp = ((ArpOpCase) ofMatch.getMatchEntryValue()).getArpOp();
1452 if (arpOp != null) {
1453 arpMatchBuilder.setArpOp(arpOp.getOpCode());
1455 matchBuilder.setLayer3Match(arpMatchBuilder.build());
1457 } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
1458 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.spa._case.ArpSpa arpSpa = ((ArpSpaCase) ofMatch.getMatchEntryValue()).getArpSpa();
1459 if (arpSpa != null) {
1461 if (null != arpSpa.getMask()){
1462 mask = IpConversionUtil.countBits(arpSpa.getMask());
1464 Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpSpa.getIpv4Address(), mask);
1465 arpMatchBuilder.setArpSourceTransportAddress(ipv4Prefix);
1466 matchBuilder.setLayer3Match(arpMatchBuilder.build());
1468 } else if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
1469 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tpa._case.ArpTpa arpTpa = ((ArpTpaCase) ofMatch.getMatchEntryValue()).getArpTpa();
1470 if (arpTpa != null) {
1472 if (null != arpTpa.getMask()){
1473 mask = IpConversionUtil.countBits(arpTpa.getMask());
1475 Ipv4Prefix ipv4Prefix = IpConversionUtil.createPrefix(arpTpa.getIpv4Address(), mask);
1477 arpMatchBuilder.setArpTargetTransportAddress(ipv4Prefix);
1478 matchBuilder.setLayer3Match(arpMatchBuilder.build());
1480 } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
1481 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.sha._case.ArpSha arpSha = ((ArpShaCase) ofMatch.getMatchEntryValue()).getArpSha();
1482 MacAddress macAddress = arpSha.getMacAddress();
1483 if (macAddress != null) {
1484 if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
1485 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
1486 arpSourceHardwareAddressBuilder.setAddress(macAddress);
1487 byte[] mask = arpSha.getMask();
1489 arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
1490 .macAddressToString(mask)));
1492 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
1493 matchBuilder.setLayer3Match(arpMatchBuilder.build());
1496 } else if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
1497 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.tha._case.ArpTha arpTha = ((ArpThaCase) ofMatch.getMatchEntryValue()).getArpTha();
1498 MacAddress macAddress = arpTha.getMacAddress();
1499 if (macAddress != null) {
1500 if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
1501 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
1502 arpTargetHardwareAddressBuilder.setAddress(macAddress);
1503 byte[] mask = arpTha.getMask();
1505 arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
1506 .macAddressToString(mask)));
1508 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
1509 matchBuilder.setLayer3Match(arpMatchBuilder.build());
1512 } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
1513 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6Src ipv6Address = ((Ipv6SrcCase) ofMatch.getMatchEntryValue()).getIpv6Src();
1514 if (ipv6Address != null) {
1515 byte[] mask = ipv6Address.getMask();
1516 if (mask != null && IpConversionUtil.isIpv6ArbitraryBitMask(mask)) {
1517 // case where ipv6dst is of type ipv6MatchBuilder and ipv6src is of type ipv6MatchArbitrary.
1518 // Need to convert ipv6dst to ipv6MatchArbitrary.
1520 if (ipv6MatchBuilder.getIpv6Destination() != null) {
1521 Ipv6Prefix ipv6PrefixDestinationAddress = ipv6MatchBuilder.getIpv6Destination();
1522 Ipv6Address ipv6DstAddress = IpConversionUtil.extractIpv6Address(ipv6PrefixDestinationAddress);
1523 Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
1524 IpConversionUtil.extractIpv6AddressMask(ipv6PrefixDestinationAddress));
1525 setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1526 dstIpv6ArbitraryMask, IpConversionUtil.compressedIpv6Format(ipv6DstAddress.getValue()));
1528 Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
1529 IpConversionUtil.createIpv6ArbitraryBitMask(mask));
1530 String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1531 setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1532 srcIpv6ArbitraryMask, stringIpv6SrcAddress);
1533 matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
1534 } else if (ipv6MatchArbitraryBitMaskBuilder.getIpv6DestinationAddressNoMask() != null) {
1536 TODO Change comments
1537 Case where destination is of type ipv6MatchArbitraryBitMask already exists in Layer3Match,
1538 source which of type ipv6Match needs to be converted to ipv4MatchArbitraryBitMask.
1539 We convert 1::/32 to 1::/FFFF:FFFF::
1541 <ipv6-source>1::/32</ipv4-source>
1542 <ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
1543 <ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
1544 after conversion output example:-
1545 <ipv6-source-address-no-mask>1::</ipv6-source-address-no-mask>
1546 <ipv6-source-arbitrary-bitmask>FFFF:FFFF::</ipv6-source-arbitrary-bitmask>
1547 <ipv6-destination-address-no-mask>1::1</ipv6-destination-address-no-mask>
1548 <ipv6-destination-arbitrary-bitmask>FFFF::0001</ipv6-destination-arbitrary-bitmask>
1550 Ipv6ArbitraryMask srcIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
1551 IpConversionUtil.createIpv6ArbitraryBitMask(mask));
1552 String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1553 setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1554 srcIpv6ArbitraryMask, stringIpv6SrcAddress);
1555 matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
1557 String stringIpv6SrcAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1558 setIpv6MatchBuilderFields(ipv6MatchBuilder, ofMatch, mask, stringIpv6SrcAddress);
1559 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1562 } else if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
1563 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6Dst ipv6Address = ((Ipv6DstCase) ofMatch.getMatchEntryValue()).getIpv6Dst();
1564 if (ipv6Address != null) {
1565 byte[] mask = ipv6Address.getMask();
1566 if (mask != null && IpConversionUtil.isIpv6ArbitraryBitMask(mask)) {
1567 // case where ipv6src is of type ipv6MatchBuilder and ipv6dst is of type ipv6MatchArbitrary.
1568 // Need to convert ipv6src to ipv6MatchArbitrary.
1570 if (ipv6MatchBuilder.getIpv6Source() != null) {
1571 Ipv6Prefix ipv6PrefixSourceAddress = ipv6MatchBuilder.getIpv6Source();
1572 Ipv6Address ipv6SrcAddress = IpConversionUtil.extractIpv6Address(ipv6PrefixSourceAddress);
1573 Ipv6ArbitraryMask srcIpv6Arbitrary = IpConversionUtil.compressedIpv6MaskFormat(
1574 IpConversionUtil.extractIpv6AddressMask(ipv6PrefixSourceAddress));
1575 setSrcIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1576 srcIpv6Arbitrary, IpConversionUtil.compressedIpv6Format(ipv6SrcAddress.getValue()));
1578 Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
1579 IpConversionUtil.createIpv6ArbitraryBitMask(mask));
1580 String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1581 setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1582 dstIpv6ArbitraryMask, stringIpv6DstAddress);
1583 matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
1584 } else if (ipv6MatchArbitraryBitMaskBuilder.getIpv6SourceAddressNoMask() != null) {
1586 TODO Change comments
1587 Case where source is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
1588 source which of type ipv6Match needs to be converted to ipv6MatchArbitraryBitMask.
1589 We convert 1::/32 to 1::/FFFF:FFFF::
1591 <ipv6-destination>1::/32</ipv6-destination>
1592 <ipv6-source-address-no-mask>1::1</ipv6-source-address-no-mask>
1593 <ipv6-source-arbitrary-bitmask>FFFF::0001</ipv6-source-arbitrary-bitmask>
1594 after conversion output example:-
1595 <ipv6-destination-address-no-mask>1::</ipv6-destination-address-no-mask>
1596 <ipv6-destination-arbitrary-bitmask>FFFF:FFFF::</ipv6-destination-arbitrary-bitmask>
1597 <ipv6-source-address-no-mask>1::1</ipv6-source-address-no-mask>
1598 <ipv6-source-arbitrary-bitmask>FFFF::0001</ipv6-source-arbitrary-bitmask>
1600 Ipv6ArbitraryMask dstIpv6ArbitraryMask = IpConversionUtil.compressedIpv6MaskFormat(
1601 IpConversionUtil.createIpv6ArbitraryBitMask(mask));
1602 String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1603 setDstIpv6MatchArbitraryBitMaskBuilderFields(ipv6MatchArbitraryBitMaskBuilder, ofMatch,
1604 dstIpv6ArbitraryMask, stringIpv6DstAddress);
1605 matchBuilder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build());
1607 String stringIpv6DstAddress = IpConversionUtil.compressedIpv6Format(ipv6Address.getIpv6Address().getValue());
1608 setIpv6MatchBuilderFields(ipv6MatchBuilder, ofMatch, mask, stringIpv6DstAddress);
1609 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1612 } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
1613 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.flabel._case.Ipv6Flabel ipv6Flabel = ((Ipv6FlabelCase) ofMatch.getMatchEntryValue()).getIpv6Flabel();
1614 if (ipv6Flabel != null) {
1615 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
1616 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6Flabel.getIpv6Flabel()));
1617 byte[] mask = ipv6Flabel.getMask();
1619 ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(Long.valueOf(ByteUtil
1620 .bytesToUnsignedInt(mask))));
1622 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1623 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1625 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
1626 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.target._case.Ipv6NdTarget ipv6NdTarget = ((Ipv6NdTargetCase) ofMatch.getMatchEntryValue()).getIpv6NdTarget();
1627 if (ipv6NdTarget != null) {
1628 ipv6MatchBuilder.setIpv6NdTarget(ipv6NdTarget.getIpv6Address());
1629 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1631 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
1632 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.sll._case.Ipv6NdSll ipv6NdSll = ((Ipv6NdSllCase) ofMatch.getMatchEntryValue()).getIpv6NdSll();
1633 if (ipv6NdSll != null) {
1634 ipv6MatchBuilder.setIpv6NdSll(ipv6NdSll.getMacAddress());
1635 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1637 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
1638 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.tll._case.Ipv6NdTll ipv6NdTll = ((Ipv6NdTllCase) ofMatch.getMatchEntryValue()).getIpv6NdTll();
1639 if (ipv6NdTll != null) {
1640 ipv6MatchBuilder.setIpv6NdTll(ipv6NdTll.getMacAddress());
1641 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1643 } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
1644 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.exthdr._case.Ipv6Exthdr ipv6Exthdr = ((Ipv6ExthdrCase) ofMatch.getMatchEntryValue()).getIpv6Exthdr();
1645 if (ipv6Exthdr != null) {
1646 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
1648 Ipv6ExthdrFlags pField = ipv6Exthdr.getPseudoField();
1649 Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
1651 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
1652 byte[] mask = ipv6Exthdr.getMask();
1654 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(mask));
1656 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
1657 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
1659 } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
1660 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.label._case.MplsLabel mplsLabel = ((MplsLabelCase) ofMatch.getMatchEntryValue()).getMplsLabel();
1661 if (mplsLabel != null) {
1662 protocolMatchFieldsBuilder.setMplsLabel(mplsLabel.getMplsLabel());
1663 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1665 } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
1666 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.bos._case.MplsBos mplsBos = ((MplsBosCase) ofMatch.getMatchEntryValue()).getMplsBos();
1667 if (mplsBos != null) {
1668 protocolMatchFieldsBuilder.setMplsBos(mplsBos.isBos() ? (short) 1 : (short) 0);
1669 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1671 } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
1672 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.mpls.tc._case.MplsTc mplsTc = ((MplsTcCase) ofMatch.getMatchEntryValue()).getMplsTc();
1673 if (mplsTc != null) {
1674 protocolMatchFieldsBuilder.setMplsTc(mplsTc.getTc());
1675 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1677 } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
1678 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.pbb.isid._case.PbbIsid pbbIsid = ((PbbIsidCase) ofMatch.getMatchEntryValue()).getPbbIsid();
1679 if (pbbIsid != null) {
1680 PbbBuilder pbbBuilder = new PbbBuilder();
1681 pbbBuilder.setPbbIsid(pbbIsid.getIsid());
1682 byte[] mask = pbbIsid.getMask();
1684 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedMedium(mask));
1686 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
1687 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1689 } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
1690 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelId tunnelId = ((TunnelIdCase) ofMatch.getMatchEntryValue()).getTunnelId();
1691 TunnelBuilder tunnelBuilder = new TunnelBuilder();
1692 if (tunnelId.getTunnelId()!= null) {
1693 tunnelBuilder.setTunnelId(new BigInteger(OFConstants.SIGNUM_UNSIGNED, tunnelId.getTunnelId()));
1694 byte[] mask = tunnelId.getMask();
1696 tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, mask));
1698 matchBuilder.setTunnel(tunnelBuilder.build());
1700 } else if (ofMatch.getOxmMatchField().equals(TcpFlags.class)) {
1701 ExperimenterIdCase experimenterIdCase = ((ExperimenterIdCase) ofMatch.getMatchEntryValue());
1702 TcpFlagsContainer tcpFlagsContainer = experimenterIdCase.getAugmentation(TcpFlagsContainer.class);
1704 if (tcpFlagsContainer != null) {
1705 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.
1706 approved.extensions.rev160802.oxm.container.match.entry.
1707 value.experimenter.id._case.TcpFlags tcpFlags = tcpFlagsContainer.getTcpFlags();
1709 tcpFlagsMatchBuilder.setTcpFlags(tcpFlags.getFlags());
1710 byte[] mask = tcpFlags.getMask();
1712 tcpFlagsMatchBuilder.setTcpFlagsMask(ByteUtil.bytesToUnsignedShort(mask));
1714 matchBuilder.setTcpFlagsMatch(tcpFlagsMatchBuilder.build());
1718 return matchBuilder;
1721 private static void setIpv6MatchBuilderFields(final Ipv6MatchBuilder ipv6MatchBuilder, final MatchEntry ofMatch, final byte[] mask, final String ipv6PrefixStr) {
1722 Ipv6Prefix ipv6Prefix;
1725 ipv6Prefix = IpConversionUtil.createPrefix(new Ipv6Address(ipv6PrefixStr), mask);
1727 ipv6Prefix = IpConversionUtil.createPrefix(new Ipv6Address(ipv6PrefixStr));
1730 if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
1731 ipv6MatchBuilder.setIpv6Source(ipv6Prefix);
1733 if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
1734 ipv6MatchBuilder.setIpv6Destination(ipv6Prefix);
1738 private static void setIpv4MatchBuilderFields(final Ipv4MatchBuilder ipv4MatchBuilder, final MatchEntry ofMatch, final byte[] mask, final String ipv4PrefixStr) {
1739 final Ipv4Prefix ipv4Prefix;
1741 ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr), mask);
1743 //Openflow Spec : 1.3.2
1744 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
1745 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
1746 // statistics response.
1747 ipv4Prefix = IpConversionUtil.createPrefix(new Ipv4Address(ipv4PrefixStr));
1749 if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
1750 ipv4MatchBuilder.setIpv4Source(ipv4Prefix);
1752 if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
1753 ipv4MatchBuilder.setIpv4Destination(ipv4Prefix);
1757 private static void setSrcIpv4MatchArbitraryBitMaskBuilderFields(
1758 final Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder,
1759 final MatchEntry ofMatch, final DottedQuad mask, final String ipv4AddressStr) {
1760 Ipv4Address ipv4Address;
1762 ipv4MatchArbitraryBitMaskBuilder.setIpv4SourceArbitraryBitmask(mask);
1764 ipv4Address = new Ipv4Address(ipv4AddressStr);
1765 ipv4MatchArbitraryBitMaskBuilder.setIpv4SourceAddressNoMask(ipv4Address);
1768 private static void setDstIpv4MatchArbitraryBitMaskBuilderFields(
1769 final Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder,
1770 final MatchEntry ofMatch, final DottedQuad mask, final String ipv4AddressStr) {
1771 Ipv4Address ipv4Address;
1773 ipv4MatchArbitraryBitMaskBuilder.setIpv4DestinationArbitraryBitmask(mask);
1775 ipv4Address = new Ipv4Address(ipv4AddressStr);
1776 ipv4MatchArbitraryBitMaskBuilder.setIpv4DestinationAddressNoMask(ipv4Address);
1779 private static void setSrcIpv6MatchArbitraryBitMaskBuilderFields(
1780 final Ipv6MatchArbitraryBitMaskBuilder ipv6MatchArbitraryBitMaskBuilder,
1781 final MatchEntry ofMatch, final Ipv6ArbitraryMask mask, final String ipv6AddressStr) {
1782 Ipv6Address ipv6Address;
1784 ipv6MatchArbitraryBitMaskBuilder.setIpv6SourceArbitraryBitmask(mask);
1786 ipv6Address = new Ipv6Address(ipv6AddressStr);
1787 ipv6MatchArbitraryBitMaskBuilder.setIpv6SourceAddressNoMask(ipv6Address);
1790 private static void setDstIpv6MatchArbitraryBitMaskBuilderFields(
1791 final Ipv6MatchArbitraryBitMaskBuilder ipv6MatchArbitraryBitMaskBuilder,
1792 final MatchEntry ofMatch, final Ipv6ArbitraryMask mask, final String ipv6AddressStr) {
1793 Ipv6Address ipv6Address;
1795 ipv6MatchArbitraryBitMaskBuilder.setIpv6DestinationArbitraryBitmask(mask);
1797 ipv6Address = new Ipv6Address(ipv6AddressStr);
1798 ipv6MatchArbitraryBitMaskBuilder.setIpv6DestinationAddressNoMask(ipv6Address);
1801 private static MatchEntry toOfMplsPbb(final Pbb pbb) {
1802 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1803 boolean hasmask = false;
1804 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1805 matchEntryBuilder.setOxmMatchField(PbbIsid.class);
1806 PbbIsidCaseBuilder pbbIsidCaseBuilder = new PbbIsidCaseBuilder();
1807 PbbIsidBuilder pbbIsidBuilder = new PbbIsidBuilder();
1808 pbbIsidBuilder.setIsid(pbb.getPbbIsid());
1809 if (pbb.getPbbMask() != null) {
1811 pbbIsidBuilder.setMask(ByteUtil.unsignedMediumToBytes(pbb.getPbbMask()));
1813 pbbIsidCaseBuilder.setPbbIsid(pbbIsidBuilder.build());
1814 matchEntryBuilder.setMatchEntryValue(pbbIsidCaseBuilder.build());
1815 matchEntryBuilder.setHasMask(hasmask);
1816 return matchEntryBuilder.build();
1819 private static MatchEntry toOfMplsTc(final Short mplsTc) {
1820 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1821 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1822 matchEntryBuilder.setHasMask(false);
1823 matchEntryBuilder.setOxmMatchField(MplsTc.class);
1824 MplsTcCaseBuilder mplsTcCaseBuilder = new MplsTcCaseBuilder();
1825 MplsTcBuilder mplsTcBuilder = new MplsTcBuilder();
1826 mplsTcBuilder.setTc(mplsTc);
1827 mplsTcCaseBuilder.setMplsTc(mplsTcBuilder.build());
1828 matchEntryBuilder.setMatchEntryValue(mplsTcCaseBuilder.build());
1829 return matchEntryBuilder.build();
1832 private static MatchEntry toOfMplsBos(final Short mplsBos) {
1833 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1834 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1835 matchEntryBuilder.setHasMask(false);
1836 matchEntryBuilder.setOxmMatchField(MplsBos.class);
1837 MplsBosCaseBuilder mplsBosCaseBuilder = new MplsBosCaseBuilder();
1838 MplsBosBuilder mplsBosBuilder = new MplsBosBuilder();
1839 boolean isBos = false;
1840 if (mplsBos.shortValue() != 0) {
1843 mplsBosBuilder.setBos(isBos);
1844 mplsBosCaseBuilder.setMplsBos(mplsBosBuilder.build());
1846 matchEntryBuilder.setMatchEntryValue(mplsBosCaseBuilder.build());
1847 return matchEntryBuilder.build();
1850 private static MatchEntry toOfMplsLabel(final Long mplsLabel) {
1851 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1852 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1853 matchEntryBuilder.setHasMask(false);
1854 matchEntryBuilder.setOxmMatchField(MplsLabel.class);
1856 MplsLabelCaseBuilder mplsLabelCaseBuilder = new MplsLabelCaseBuilder();
1857 MplsLabelBuilder mplsLabelBuilder = new MplsLabelBuilder();
1858 mplsLabelBuilder.setMplsLabel(mplsLabel);
1859 mplsLabelCaseBuilder.setMplsLabel(mplsLabelBuilder.build());
1860 matchEntryBuilder.setMatchEntryValue(mplsLabelCaseBuilder.build());
1861 return matchEntryBuilder.build();
1864 private static MatchEntry toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
1865 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1866 boolean hasmask = false;
1867 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1868 matchEntryBuilder.setOxmMatchField(Ipv6Exthdr.class);
1869 Ipv6ExthdrCaseBuilder ipv6ExthdrCaseBuilder = new Ipv6ExthdrCaseBuilder();
1870 Ipv6ExthdrBuilder ipv6ExthdrBuilder = new Ipv6ExthdrBuilder();
1872 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
1873 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
1874 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
1875 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
1876 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
1877 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
1878 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
1879 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
1880 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
1881 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
1883 ipv6ExthdrBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
1884 //TODO ipv6ExthdrBuilder.setMask()
1885 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
1887 ipv6ExthdrBuilder.setMask(ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
1889 ipv6ExthdrCaseBuilder.setIpv6Exthdr(ipv6ExthdrBuilder.build());
1890 matchEntryBuilder.setMatchEntryValue(ipv6ExthdrCaseBuilder.build());
1891 matchEntryBuilder.setHasMask(hasmask);
1892 return matchEntryBuilder.build();
1895 private static MatchEntry toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
1896 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1897 boolean hasmask = false;
1898 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1899 matchEntryBuilder.setOxmMatchField(Ipv6Flabel.class);
1900 Ipv6FlabelCaseBuilder ipv6FlabelCaseBuilder = new Ipv6FlabelCaseBuilder();
1901 Ipv6FlabelBuilder ipv6FlabelBuilder = new Ipv6FlabelBuilder();
1902 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
1903 if (ipv6Label.getFlabelMask() != null) {
1905 ipv6FlabelBuilder.setMask(ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
1907 ipv6FlabelCaseBuilder.setIpv6Flabel(ipv6FlabelBuilder.build());
1908 matchEntryBuilder.setMatchEntryValue(ipv6FlabelCaseBuilder.build());
1909 matchEntryBuilder.setHasMask(hasmask);
1910 return matchEntryBuilder.build();
1913 private static MatchEntry toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
1914 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1915 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1916 matchEntryBuilder.setHasMask(false);
1917 matchEntryBuilder.setOxmMatchField(field);
1918 InPortCaseBuilder caseBuilder = new InPortCaseBuilder();
1919 InPortBuilder portBuilder = new InPortBuilder();
1920 portBuilder.setPortNumber(new PortNumber(portNumber));
1921 caseBuilder.setInPort(portBuilder.build());
1922 matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
1924 return matchEntryBuilder.build();
1927 private static MatchEntry toOfPhyPort(final Class<? extends MatchField> field, final Long portNumber) {
1928 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1929 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1930 matchEntryBuilder.setHasMask(false);
1931 matchEntryBuilder.setOxmMatchField(field);
1932 InPhyPortCaseBuilder caseBuilder = new InPhyPortCaseBuilder();
1933 InPhyPortBuilder portBuilder = new InPhyPortBuilder();
1934 portBuilder.setPortNumber(new PortNumber(portNumber));
1935 caseBuilder.setInPhyPort(portBuilder.build());
1936 matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
1938 return matchEntryBuilder.build();
1941 private static MatchEntry toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
1942 final BigInteger metadataMask) {
1943 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1944 boolean hasmask = false;
1945 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1946 matchEntryBuilder.setOxmMatchField(field);
1947 MetadataCaseBuilder metadataCaseBuilder = new MetadataCaseBuilder();
1948 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.MetadataBuilder metadataBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.metadata._case.MetadataBuilder();
1949 metadataBuilder.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
1950 if (metadataMask != null) {
1952 metadataBuilder.setMask(ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
1954 metadataCaseBuilder.setMetadata(metadataBuilder.build());
1955 matchEntryBuilder.setMatchEntryValue(metadataCaseBuilder.build());
1956 matchEntryBuilder.setHasMask(hasmask);
1957 return matchEntryBuilder.build();
1960 private static MatchEntry toOfEthernetType(final EthernetType ethernetType) {
1961 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1962 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1963 matchEntryBuilder.setHasMask(false);
1964 matchEntryBuilder.setOxmMatchField(EthType.class);
1965 EthTypeCaseBuilder ethTypeCaseBuilder = new EthTypeCaseBuilder();
1966 EthTypeBuilder ethTypeBuilder = new EthTypeBuilder();
1967 EtherType etherType = new EtherType(ethernetType.getType().getValue().intValue());
1968 ethTypeBuilder.setEthType(etherType);
1969 ethTypeCaseBuilder.setEthType(ethTypeBuilder.build());
1970 matchEntryBuilder.setMatchEntryValue(ethTypeCaseBuilder.build());
1971 return matchEntryBuilder.build();
1974 private static MatchEntry toOfIcmpv4Type(final Short icmpv4Type) {
1975 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1976 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1977 matchEntryBuilder.setHasMask(false);
1978 matchEntryBuilder.setOxmMatchField(Icmpv4Type.class);
1979 Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder();
1980 Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder();
1981 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1982 icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build());
1983 matchEntryBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build());
1984 return matchEntryBuilder.build();
1987 private static MatchEntry toOfIcmpv4Code(final Short icmpv4Code) {
1988 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
1989 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
1990 matchEntryBuilder.setHasMask(false);
1991 matchEntryBuilder.setOxmMatchField(Icmpv4Code.class);
1992 Icmpv4CodeCaseBuilder icmpv4CodeCaseBuilder = new Icmpv4CodeCaseBuilder();
1993 Icmpv4CodeBuilder icmpv4CodeBuilder = new Icmpv4CodeBuilder();
1994 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1995 icmpv4CodeCaseBuilder.setIcmpv4Code(icmpv4CodeBuilder.build());
1996 matchEntryBuilder.setMatchEntryValue(icmpv4CodeCaseBuilder.build());
1997 return matchEntryBuilder.build();
2000 private static MatchEntry toOfIcmpv6Type(final Short icmpv6Type) {
2001 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2002 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2003 matchEntryBuilder.setHasMask(false);
2004 matchEntryBuilder.setOxmMatchField(Icmpv6Type.class);
2005 Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder();
2006 Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder();
2007 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
2008 icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build());
2009 matchEntryBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build());
2010 return matchEntryBuilder.build();
2013 private static MatchEntry toOfIcmpv6Code(final Short icmpv6Code) {
2014 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2015 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2016 matchEntryBuilder.setHasMask(false);
2017 matchEntryBuilder.setOxmMatchField(Icmpv6Code.class);
2018 Icmpv6CodeCaseBuilder icmpv6CodeCaseBuilder = new Icmpv6CodeCaseBuilder();
2019 Icmpv6CodeBuilder icmpv6CodeBuilder = new Icmpv6CodeBuilder();
2020 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
2021 icmpv6CodeCaseBuilder.setIcmpv6Code(icmpv6CodeBuilder.build());
2022 matchEntryBuilder.setMatchEntryValue(icmpv6CodeCaseBuilder.build());
2023 return matchEntryBuilder.build();
2026 public static MatchEntry toOfIpDscp(final Dscp ipDscp) {
2027 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2028 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2029 matchEntryBuilder.setHasMask(false);
2030 matchEntryBuilder.setOxmMatchField(IpDscp.class);
2032 IpDscpCaseBuilder ipDscpCaseBuilder = new IpDscpCaseBuilder();
2033 IpDscpBuilder ipDscpBuilder = new IpDscpBuilder();
2034 ipDscpBuilder.setDscp(ipDscp);
2035 ipDscpCaseBuilder.setIpDscp(ipDscpBuilder.build());
2036 matchEntryBuilder.setMatchEntryValue(ipDscpCaseBuilder.build());
2037 return matchEntryBuilder.build();
2040 public static MatchEntry toOfVlanPcp(
2041 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
2042 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2043 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2044 matchEntryBuilder.setHasMask(false);
2045 matchEntryBuilder.setOxmMatchField(VlanPcp.class);
2046 VlanPcpCaseBuilder vlanPcpCaseBuilder = new VlanPcpCaseBuilder();
2047 VlanPcpBuilder vlanPcpBuilder = new VlanPcpBuilder();
2048 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
2049 vlanPcpCaseBuilder.setVlanPcp(vlanPcpBuilder.build());
2050 matchEntryBuilder.setMatchEntryValue(vlanPcpCaseBuilder.build());
2051 return matchEntryBuilder.build();
2055 private static MatchEntry toOfIpProto(final Short ipProtocol) {
2056 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2057 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2058 matchEntryBuilder.setHasMask(false);
2059 matchEntryBuilder.setOxmMatchField(IpProto.class);
2060 IpProtoCaseBuilder ipProtoCaseBuilder = new IpProtoCaseBuilder();
2061 IpProtoBuilder ipProtoBuilder = new IpProtoBuilder();
2062 ipProtoBuilder.setProtocolNumber(ipProtocol);
2063 ipProtoCaseBuilder.setIpProto(ipProtoBuilder.build());
2064 matchEntryBuilder.setMatchEntryValue(ipProtoCaseBuilder.build());
2065 return matchEntryBuilder.build();
2068 private static MatchEntry toOfIpEcn(final Short ipEcn) {
2069 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2070 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2071 matchEntryBuilder.setHasMask(false);
2072 matchEntryBuilder.setOxmMatchField(IpEcn.class);
2073 IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
2074 IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
2075 ipEcnBuilder.setEcn(ipEcn);
2076 ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
2077 matchEntryBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
2078 return matchEntryBuilder.build();
2081 private static MatchEntry toOfArpOpCode(final Integer arpOp) {
2082 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2083 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2084 matchEntryBuilder.setHasMask(false);
2085 matchEntryBuilder.setOxmMatchField(ArpOp.class);
2086 ArpOpCaseBuilder arpOpCaseBuilder = new ArpOpCaseBuilder();
2087 ArpOpBuilder arpOpBuilder = new ArpOpBuilder();
2088 arpOpBuilder.setOpCode(arpOp);
2089 arpOpCaseBuilder.setArpOp(arpOpBuilder.build());
2090 matchEntryBuilder.setMatchEntryValue(arpOpCaseBuilder.build());
2091 return matchEntryBuilder.build();
2094 private static MatchEntry toOfIpv6NdTargetAddress(final Ipv6Address address) {
2095 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
2096 matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
2097 matchEntryBuilder.setHasMask(false);
2098 matchEntryBuilder.setOxmMatchField(Ipv6NdTarget.class);
2100 Ipv6NdTargetCaseBuilder ipv6NdTargetCaseBuilder = new Ipv6NdTargetCaseBuilder();
2101 Ipv6NdTargetBuilder ipv6NdTargetBuilder = new Ipv6NdTargetBuilder();
2102 ipv6NdTargetBuilder.setIpv6Address(address);
2103 ipv6NdTargetCaseBuilder.setIpv6NdTarget(ipv6NdTargetBuilder.build());
2104 matchEntryBuilder.setMatchEntryValue(ipv6NdTargetCaseBuilder.build());
2105 return matchEntryBuilder.build();
2112 * Method converts OF SetField action to SAL SetFiled action.
2114 * @param action input action
2115 * @param ofVersion current ofp version
2116 * @return set field builder
2118 public static SetField fromOFSetFieldToSALSetFieldAction(
2119 final Action action, final OpenflowVersion ofVersion) {
2120 logger.debug("Converting OF SetField action to SAL SetField action");
2121 SetFieldCase setFieldCase = (SetFieldCase) action.getActionChoice();
2122 SetFieldAction setFieldAction = setFieldCase.getSetFieldAction();
2124 SetFieldBuilder setField = new SetFieldBuilder();
2125 MatchBuilder match = OfMatchToSALMatchConvertor(setFieldAction.getMatchEntry(), null, ofVersion);
2126 setField.fieldsFrom(match.build());
2127 return setField.build();