2 * Copyright (c) 2013-2014 Ericsson. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
11 import java.math.BigInteger;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
19 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
20 import org.opendaylight.openflowplugin.api.OFConstants;
21 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers;
22 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
23 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
24 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
25 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
26 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatch;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
185 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
186 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
187 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
188 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
189 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
190 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
191 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
192 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
193 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
194 import org.slf4j.Logger;
195 import org.slf4j.LoggerFactory;
197 import com.google.common.base.Optional;
198 import com.google.common.base.Splitter;
201 * Utility class for converting a MD-SAL Flow into the OF flow mod
203 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
204 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
205 static final String PREFIX_SEPARATOR = "/";
206 static final Splitter PREFIX_SPLITTER = Splitter.on('/');
207 private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
208 private static final short PROTO_TCP = 6;
209 private static final short PROTO_UDP = 17;
210 private static final String noIp = "0.0.0.0/0";
213 public List<MatchEntries> convert(
214 final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
215 List<MatchEntries> matchEntriesList = new ArrayList<>();
216 if (match == null) return matchEntriesList;
217 if (match.getInPort() != null) {
218 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
219 matchEntriesList.add(toOfPort(InPort.class,
220 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPort())));
223 if (match.getInPhyPort() != null) {
224 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
225 matchEntriesList.add(toOfPort(InPhyPort.class,
226 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPhyPort())));
229 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
231 if (metadata != null) {
232 matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
235 EthernetMatch ethernetMatch = match.getEthernetMatch();
236 if (ethernetMatch != null) {
237 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
238 if (ethernetDestination != null) {
239 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
240 ethernetDestination.getMask()));
243 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
244 if (ethernetSource != null) {
246 .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
249 if (ethernetMatch.getEthernetType() != null) {
250 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
254 VlanMatch vlanMatch = match.getVlanMatch();
255 if (vlanMatch != null) {
256 if (vlanMatch.getVlanId() != null) {
257 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
260 if (vlanMatch.getVlanPcp() != null) {
261 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
265 IpMatch ipMatch = match.getIpMatch();
266 if (ipMatch != null) {
267 if (ipMatch.getIpDscp() != null) {
268 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
271 if (ipMatch.getIpEcn() != null) {
272 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
275 if (ipMatch.getIpProtocol() != null) {
276 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
281 Layer4Match layer4Match = match.getLayer4Match();
282 if (layer4Match != null) {
283 if (layer4Match instanceof TcpMatch) {
284 TcpMatch tcpMatch = (TcpMatch) layer4Match;
285 if (tcpMatch.getTcpSourcePort() != null) {
286 matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
289 if (tcpMatch.getTcpDestinationPort() != null) {
290 matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
292 } else if (layer4Match instanceof UdpMatch) {
293 UdpMatch udpMatch = (UdpMatch) layer4Match;
294 if (udpMatch.getUdpSourcePort() != null) {
295 matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
298 if (udpMatch.getUdpDestinationPort() != null) {
299 matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
301 } else if (layer4Match instanceof SctpMatch) {
302 SctpMatch sctpMatch = (SctpMatch) layer4Match;
303 if (sctpMatch.getSctpSourcePort() != null) {
304 matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
307 if (sctpMatch.getSctpDestinationPort() != null) {
308 matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
313 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
314 if (icmpv4Match != null) {
315 if (icmpv4Match.getIcmpv4Type() != null) {
316 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
319 if (icmpv4Match.getIcmpv4Code() != null) {
320 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
324 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
325 if (icmpv6Match != null) {
326 if (icmpv6Match.getIcmpv6Type() != null) {
327 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
330 if (icmpv6Match.getIcmpv6Code() != null) {
331 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
335 Layer3Match layer3Match = match.getLayer3Match();
336 if (layer3Match != null) {
337 if (layer3Match instanceof Ipv4Match) {
338 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
339 if (ipv4Match.getIpv4Source() != null) {
340 matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
342 if (ipv4Match.getIpv4Destination() != null) {
343 matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
346 if (layer3Match instanceof TunnelIpv4Match) {
347 TunnelIpv4Match tunnelIpv4Src = (TunnelIpv4Match) layer3Match;
348 if (tunnelIpv4Src.getTunnelIpv4Source() != null) {
349 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Src.class, tunnelIpv4Src.getTunnelIpv4Source()));
351 if (tunnelIpv4Src.getTunnelIpv4Destination() != null) {
352 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Dst.class, tunnelIpv4Src.getTunnelIpv4Destination()));
354 } else if (layer3Match instanceof ArpMatch) {
355 ArpMatch arpMatch = (ArpMatch) layer3Match;
356 if (arpMatch.getArpOp() != null) {
357 matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
360 if (arpMatch.getArpSourceTransportAddress() != null) {
361 matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
364 if (arpMatch.getArpTargetTransportAddress() != null) {
365 matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
368 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
369 if (arpSourceHardwareAddress != null) {
370 matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
371 arpSourceHardwareAddress.getMask()));
374 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
375 if (arpTargetHardwareAddress != null) {
376 matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
377 arpTargetHardwareAddress.getMask()));
381 else if (layer3Match instanceof Ipv6Match) {
382 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
383 if (ipv6Match.getIpv6Source() != null) {
384 matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
387 if (ipv6Match.getIpv6Destination() != null) {
388 matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
391 if (ipv6Match.getIpv6Label() != null) {
392 matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
395 if (ipv6Match.getIpv6NdTarget() != null) {
396 matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
399 if (ipv6Match.getIpv6NdSll() != null) {
400 matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
403 if (ipv6Match.getIpv6NdTll() != null) {
404 matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
407 if (ipv6Match.getIpv6ExtHeader() != null) {
408 matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
413 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
414 if (protocolMatchFields != null) {
415 if (protocolMatchFields.getMplsLabel() != null) {
416 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
419 if (protocolMatchFields.getMplsBos() != null) {
420 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
423 if (protocolMatchFields.getMplsTc() != null) {
424 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
427 if (protocolMatchFields.getPbb() != null) {
428 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
432 //FIXME: move to extensible support
433 // TODO: Move to seperate bundle as soon as OF extensibility is supported by ofplugin/java
434 TcpFlagMatch tcpFlagMatch = match.getTcpFlagMatch();
435 if (tcpFlagMatch != null) {
436 if (tcpFlagMatch.getTcpFlag() != null) {
437 matchEntriesList.add(NxmExtensionsConvertor.toNxmTcpFlag(tcpFlagMatch.getTcpFlag()));
441 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
443 if (tunnel != null) {
444 matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
449 * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
450 * - we might need version for conversion and for key
453 Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
454 if (extensionListOpt.isPresent()) {
455 for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
456 // TODO: get real version
457 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
458 ConvertorToOFJava<MatchEntries> convertor =
459 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
460 MatchEntries ofMatch = convertor.convert(extensionItem.getExtension());
461 matchEntriesList.add(ofMatch);
465 return matchEntriesList;
469 * Method convert Openflow 1.0 specific flow match to MD-SAL format flow
474 * @author avishnoi@in.ibm.com
476 public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
477 MatchBuilder matchBuilder = new MatchBuilder();
478 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
479 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
480 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
481 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
482 if (!swMatch.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
483 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
484 (long) swMatch.getInPort(), ofVersion));
487 if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
488 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
489 ethSrcBuilder.setAddress(swMatch.getDlSrc());
490 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
491 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
493 if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
494 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
495 ethDstBuilder.setAddress(swMatch.getDlDst());
496 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
497 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
499 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
500 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
501 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
502 (long) swMatch.getDlType()));
503 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
504 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
506 if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
507 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
508 int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
509 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
510 vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false: true);
511 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
512 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
514 if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp() != null) {
515 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
516 swMatch.getDlVlanPcp()));
517 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
519 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
520 String ipv4PrefixStr = swMatch.getNwSrc().getValue();
521 if (swMatch.getNwSrcMask() != null) {
522 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
524 if (!ipv4PrefixStr.equals(noIp)) {
525 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
526 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
529 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
530 String ipv4PrefixStr = swMatch.getNwDst().getValue();
531 if (swMatch.getNwDstMask() != null) {
532 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
534 if (!ipv4PrefixStr.equals(noIp)) {
535 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
536 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
539 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
540 ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
541 matchBuilder.setIpMatch(ipMatchBuilder.build());
543 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
544 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
545 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
547 .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
548 swMatch.getTpSrc()));
550 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
552 .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
553 swMatch.getTpDst()));
556 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
557 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
560 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
561 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
562 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
564 .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
565 swMatch.getTpSrc()));
567 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
569 .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
570 swMatch.getTpDst()));
573 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
574 matchBuilder.setLayer4Match(udpMatchBuilder.build());
577 if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
578 // DSCP default value is 0 from the library but controller side it
580 // look if there better solution
581 if (0 != swMatch.getNwTos()) {
582 ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
584 matchBuilder.setIpMatch(ipMatchBuilder.build());
587 return matchBuilder.build();
591 * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
598 * @return md-sal match instance
599 * @author avishnoi@in.ibm.com
601 public static MatchBuilder fromOFMatchToSALMatch(
602 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch,
603 final BigInteger datapathid, final OpenflowVersion ofVersion) {
604 return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid, ofVersion);
607 private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
608 OpenflowVersion ofVersion){
610 MatchBuilder matchBuilder = new MatchBuilder();
611 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
612 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
613 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
614 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
615 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
616 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
617 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
618 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
619 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
620 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
621 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
622 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
623 TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
624 TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
626 for (MatchEntries ofMatch : swMatchList) {
628 if (ofMatch.getOxmMatchField().equals(InPort.class)) {
629 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
630 if(portNumber != null){
631 Long portNo = portNumber.getPortNumber().getValue();
632 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, portNo, ofVersion));
634 } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
635 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
636 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
637 portNumber.getPortNumber().getValue(), ofVersion));
638 } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
639 MetadataBuilder metadataBuilder = new MetadataBuilder();
640 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
641 if (metadataMatchEntry != null) {
642 metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
643 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
644 if (maskMatchEntry != null) {
645 metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
648 matchBuilder.setMetadata(metadataBuilder.build());
650 } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
651 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
652 if (macAddressMatchEntry != null) {
653 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
654 ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
655 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
656 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
658 } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
659 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
660 if (macAddressMatchEntry != null) {
661 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
662 ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
663 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
664 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
666 } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
667 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
668 if (ethTypeMatchEntry != null) {
669 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
671 .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
672 (long) ethTypeMatchEntry.getEthType().getValue()));
673 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
674 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
676 } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
677 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
678 if (vlanVidMatchEntry != null) {
679 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
680 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
681 vlanVidMatchEntry.getVlanVid()))
682 .setVlanIdPresent(vlanVidMatchEntry.isCfiBit());
683 vlanMatchBuilder.setVlanId(vlanBuilder.build());
684 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
686 } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
687 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
688 if (vlanPcpMatchEntry != null) {
690 .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
691 vlanPcpMatchEntry.getVlanPcp()));
692 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
694 } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
695 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
696 if (dscpMatchEntry != null) {
697 ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
698 matchBuilder.setIpMatch(ipMatchBuilder.build());
700 } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
701 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
702 if (ecnMatchEntry != null) {
703 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
704 matchBuilder.setIpMatch(ipMatchBuilder.build());
706 } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
707 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch
708 .getAugmentation(ProtocolNumberMatchEntry.class);
709 if (protocolNumberMatchEntry != null) {
710 ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
711 matchBuilder.setIpMatch(ipMatchBuilder.build());
713 } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
714 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
715 if (portMatchEntry != null) {
716 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
717 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
719 } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
720 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
721 if (portMatchEntry != null) {
722 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
723 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
725 } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
726 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
727 if (portMatchEntry != null) {
728 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
729 matchBuilder.setLayer4Match(udpMatchBuilder.build());
731 } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
732 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
733 if (portMatchEntry != null) {
734 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
735 matchBuilder.setLayer4Match(udpMatchBuilder.build());
737 } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
738 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
739 if (portMatchEntry != null) {
740 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
741 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
743 } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
744 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
745 if (portMatchEntry != null) {
746 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
747 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
749 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
750 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
751 if (icmpv4TypeMatchEntry != null) {
752 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
753 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
755 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
756 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
757 if (icmpv4CodeMatchEntry != null) {
758 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
759 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
761 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
762 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
763 if (icmpv6TypeMatchEntry != null) {
764 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
765 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
767 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
768 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
769 if (icmpv6CodeMatchEntry != null) {
770 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
771 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
773 } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)
774 || ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
775 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
776 if (ipv4AddressMatchEntry != null) {
777 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
778 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
779 if (maskMatchEntry != null) {
780 int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
782 while(receivedMask != 0xffffffff){
783 receivedMask = receivedMask >> 1;
786 ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount);
788 //Openflow Spec : 1.3.2
789 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
790 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
791 // statistics response.
793 ipv4PrefixStr+=PREFIX_SEPARATOR + "32";
795 if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
796 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
798 if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
799 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
801 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
805 else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
806 || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
807 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
808 if (ipv4AddressMatchEntry != null) {
809 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
810 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
811 if (maskMatchEntry != null) {
812 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
814 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)) {
815 tunnelIpv4MatchBuilder.setTunnelIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
817 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
818 tunnelIpv4MatchBuilder.setTunnelIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
820 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
823 else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
824 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
825 if (opCodeMatchEntry != null) {
826 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
827 matchBuilder.setLayer3Match(arpMatchBuilder.build());
829 } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)
830 || ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
831 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
832 if (ipv4AddressMatchEntry != null) {
833 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
834 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
835 if (maskMatchEntry != null) {
836 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
838 if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
839 arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
841 if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
842 arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
844 matchBuilder.setLayer3Match(arpMatchBuilder.build());
846 } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)
847 || ofMatch.getOxmMatchField().equals(ArpTha.class)) {
848 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
849 if (macAddressMatchEntry != null) {
850 if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
851 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
852 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
853 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
854 if (maskMatchEntry != null) {
855 arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
856 .macAddressToString(maskMatchEntry.getMask())));
858 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
859 matchBuilder.setLayer3Match(arpMatchBuilder.build());
861 if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
862 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
863 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
864 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
865 if (maskMatchEntry != null) {
866 arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
867 .macAddressToString(maskMatchEntry.getMask())));
869 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
870 matchBuilder.setLayer3Match(arpMatchBuilder.build());
873 } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)
874 || ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
875 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
876 if (ipv6AddressMatchEntry != null) {
877 String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
878 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
879 if(maskMatchEntry != null){
880 ipv6PrefixStr += PREFIX_SEPARATOR
881 + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
884 if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
885 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
887 if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
888 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
890 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
892 } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
893 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
894 if (ipv6FlabelMatchEntry != null) {
895 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
896 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
897 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
898 if (maskMatchEntry != null) {
899 ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(Long.valueOf(ByteUtil
900 .bytesToUnsignedInt(maskMatchEntry.getMask()))));
902 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
903 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
905 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
906 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
907 if (ipv6AddressMatchEntry != null) {
908 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
909 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
911 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
912 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
913 if (macAddressMatchEntry != null) {
914 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
915 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
917 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
918 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
919 if (macAddressMatchEntry != null) {
920 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
921 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
923 } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
924 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
925 if (pseudoFieldMatchEntry != null) {
926 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
928 Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
929 Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
931 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
932 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
933 if (maskMatchEntry != null) {
934 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(maskMatchEntry.getMask()));
936 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
937 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
939 } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
940 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
941 if (mplsLabelMatchEntry != null) {
942 protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
943 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
945 } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
946 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
947 if (bosMatchEntry != null) {
948 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos() ? (short) 1 : (short) 0);
949 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
951 } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
952 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
953 if (tcMatchEntry != null) {
954 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
955 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
957 } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
958 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
959 if (isidMatchEntry != null) {
960 PbbBuilder pbbBuilder = new PbbBuilder();
961 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
962 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
963 if (maskMatchEntry != null) {
964 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedInt(maskMatchEntry.getMask()));
966 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
967 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
969 } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
970 TunnelBuilder tunnelBuilder = new TunnelBuilder();
971 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
972 if (metadataMatchEntry != null) {
973 tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
974 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
975 if (maskMatchEntry != null) {
976 tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
979 matchBuilder.setTunnel(tunnelBuilder.build());
981 } else if (ofMatch.getOxmMatchField().equals(TcpFlag.class)) {
982 //FIXME: move to extensible support
983 TcpFlagMatchEntry tcpFlagMatch = ofMatch.getAugmentation(TcpFlagMatchEntry.class);
984 if (tcpFlagMatch != null) {
985 tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
986 matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
992 private static MatchEntries toOfMplsPbb(final Pbb pbb) {
993 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
994 boolean hasmask = false;
995 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
996 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
997 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
998 isidBuilder.setIsid(pbb.getPbbIsid());
999 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
1000 if (pbb.getPbbMask() != null) {
1002 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(pbb.getPbbMask()));
1004 matchEntriesBuilder.setHasMask(hasmask);
1005 return matchEntriesBuilder.build();
1008 private static MatchEntries toOfMplsTc(final Short mplsTc) {
1009 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1010 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1011 matchEntriesBuilder.setHasMask(false);
1012 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
1013 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
1014 tcBuilder.setTc(mplsTc);
1015 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
1016 return matchEntriesBuilder.build();
1019 private static MatchEntries toOfMplsBos(final Short mplsBos) {
1020 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1021 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1022 matchEntriesBuilder.setHasMask(false);
1023 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
1024 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
1026 bosBuilder.setBos(true);
1028 bosBuilder.setBos(false);
1030 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
1031 return matchEntriesBuilder.build();
1034 private static MatchEntries toOfMplsLabel(final Long mplsLabel) {
1035 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1036 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1037 matchEntriesBuilder.setHasMask(false);
1038 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
1039 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
1040 mplsLabelBuilder.setMplsLabel(mplsLabel);
1041 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
1042 return matchEntriesBuilder.build();
1045 private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
1046 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1047 boolean hasmask = false;
1048 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1049 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
1050 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
1051 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
1052 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
1053 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
1054 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
1055 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
1056 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
1057 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
1058 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
1059 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
1060 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
1061 pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
1062 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
1063 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
1065 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
1067 matchEntriesBuilder.setHasMask(hasmask);
1068 return matchEntriesBuilder.build();
1071 private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
1072 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1073 boolean hasmask = false;
1074 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1075 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
1076 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
1077 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
1078 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
1079 if (ipv6Label.getFlabelMask() != null) {
1081 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
1083 matchEntriesBuilder.setHasMask(hasmask);
1084 return matchEntriesBuilder.build();
1087 private static MatchEntries toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
1088 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1089 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1090 matchEntriesBuilder.setHasMask(false);
1091 matchEntriesBuilder.setOxmMatchField(field);
1092 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
1093 port.setPortNumber(new PortNumber(portNumber));
1094 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
1095 return matchEntriesBuilder.build();
1098 private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
1099 final BigInteger metadataMask) {
1100 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1101 boolean hasmask = false;
1102 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1103 matchEntriesBuilder.setOxmMatchField(field);
1104 addMetadataAugmentation(matchEntriesBuilder, metadata);
1105 if (metadataMask != null) {
1107 addMaskAugmentation(matchEntriesBuilder,
1108 ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
1110 matchEntriesBuilder.setHasMask(hasmask);
1111 return matchEntriesBuilder.build();
1114 public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
1115 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
1116 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
1117 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1118 boolean hasmask = false;
1119 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1120 matchEntriesBuilder.setOxmMatchField(field);
1121 addMacAddressAugmentation(matchEntriesBuilder, macAddress);
1124 addMaskAugmentation(matchEntriesBuilder, ByteBufUtils.macAddressToBytes(mask.getValue()));
1126 matchEntriesBuilder.setHasMask(hasmask);
1127 return matchEntriesBuilder.build();
1130 private static MatchEntries toOfEthernetType(final EthernetType ethernetType) {
1131 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1132 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1133 matchEntriesBuilder.setHasMask(false);
1134 matchEntriesBuilder.setOxmMatchField(EthType.class);
1135 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
1136 ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
1137 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
1138 return matchEntriesBuilder.build();
1141 private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
1142 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
1143 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1144 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1145 matchEntriesBuilder.setHasMask(false);
1146 matchEntriesBuilder.setOxmMatchField(field);
1147 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
1148 portBuilder.setPort(portNumber);
1149 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
1150 return matchEntriesBuilder.build();
1153 private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) {
1154 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1155 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1156 matchEntriesBuilder.setHasMask(false);
1157 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1158 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1159 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1160 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1161 return matchEntriesBuilder.build();
1164 private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) {
1165 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1166 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1167 matchEntriesBuilder.setHasMask(false);
1168 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1169 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1170 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1171 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1172 return matchEntriesBuilder.build();
1175 private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) {
1176 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1177 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1178 matchEntriesBuilder.setHasMask(false);
1179 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1180 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1181 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1182 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1183 return matchEntriesBuilder.build();
1186 private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) {
1187 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1188 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1189 matchEntriesBuilder.setHasMask(false);
1190 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1191 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1192 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1193 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1194 return matchEntriesBuilder.build();
1197 public static MatchEntries toOfIpv4Prefix(final Class<? extends MatchField> field, final Ipv4Prefix ipv4Prefix) {
1198 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1199 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1200 matchEntriesBuilder.setOxmMatchField(field);
1201 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1202 matchEntriesBuilder.setHasMask(hasMask);
1203 return matchEntriesBuilder.build();
1206 private static MatchEntries toOfIpv6Prefix(final Class<? extends MatchField> field, final Ipv6Prefix ipv6Prefix) {
1207 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1208 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1209 matchEntriesBuilder.setOxmMatchField(field);
1210 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1211 matchEntriesBuilder.setHasMask(hasmask);
1212 return matchEntriesBuilder.build();
1215 public static MatchEntries toOfIpDscp(final Dscp ipDscp) {
1216 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1217 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1218 matchEntriesBuilder.setHasMask(false);
1219 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1220 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1221 dscpBuilder.setDscp(ipDscp);
1222 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1223 return matchEntriesBuilder.build();
1226 public static MatchEntries toOfVlanPcp(
1227 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1228 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1229 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1230 matchEntriesBuilder.setHasMask(false);
1231 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1232 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1233 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1234 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1235 return matchEntriesBuilder.build();
1238 private static MatchEntries toOfVlanVid(final VlanId vlanId) {
1240 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1241 boolean hasmask = false;
1242 boolean setCfiBit = false;
1243 Integer vidEntryValue = 0;
1244 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1245 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1246 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1247 if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
1249 if (vlanId.getVlanId() != null) {
1250 vidEntryValue = vlanId.getVlanId().getValue();
1252 hasmask = (vidEntryValue == 0);
1254 vlanVidBuilder.setCfiBit(setCfiBit);
1255 vlanVidBuilder.setVlanVid(vidEntryValue);
1256 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1258 addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1260 matchEntriesBuilder.setHasMask(hasmask);
1261 return matchEntriesBuilder.build();
1264 private static MatchEntries toOfIpProto(final Short ipProtocol) {
1265 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1266 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1267 matchEntriesBuilder.setHasMask(false);
1268 matchEntriesBuilder.setOxmMatchField(IpProto.class);
1269 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1270 protoNumberBuilder.setProtocolNumber(ipProtocol);
1271 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1272 return matchEntriesBuilder.build();
1275 private static MatchEntries toOfIpEcn(final Short ipEcn) {
1276 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1277 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1278 matchEntriesBuilder.setHasMask(false);
1279 matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1280 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1281 ecnBuilder.setEcn(ipEcn);
1282 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1283 return matchEntriesBuilder.build();
1286 private static MatchEntries toOfArpOpCode(final Integer arpOp) {
1287 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1288 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1289 matchEntriesBuilder.setHasMask(false);
1290 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1291 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1292 opcodeBuilder.setOpCode(arpOp);
1293 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1294 return matchEntriesBuilder.build();
1297 private static MatchEntries toOfIpv6Address(final Ipv6Address address) {
1298 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1299 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1300 matchEntriesBuilder.setHasMask(false);
1301 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1302 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1303 ipv6AddressBuilder.setIpv6Address(address);
1304 matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1305 return matchEntriesBuilder.build();
1308 private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) {
1309 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1310 maskBuilder.setMask(mask);
1311 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1314 private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) {
1315 boolean hasMask = false;
1316 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1317 Ipv6Address ipv6Address = new Ipv6Address(addressParts.next());
1319 Integer prefix = null;
1320 if (addressParts.hasNext()) {
1321 prefix = Integer.parseInt(addressParts.next());
1324 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1325 ipv6AddressBuilder.setIpv6Address(ipv6Address);
1326 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1327 if (prefix != null) {
1329 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1334 private static byte[] convertIpv6PrefixToByteArray(final int prefix) {
1335 // TODO: Temporary fix. Has performance impacts.
1336 byte[] mask = new byte[16];
1337 int oneCount = prefix;
1338 for (int count = 0; count < 16; count++) {
1340 if (oneCount >= 8) {
1342 oneCount = oneCount - 8;
1344 byteBits = oneCount;
1348 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1353 private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) {
1354 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1355 metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
1356 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1360 * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1363 private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
1364 boolean hasMask = false;
1365 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1366 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
1369 if (addressParts.hasNext()) {
1370 prefix = Integer.parseInt(addressParts.next());
1375 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1376 ipv4AddressBuilder.setIpv4Address(ipv4Address);
1377 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1379 int mask = 0xffffffff << (32 - prefix);
1380 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1382 addMaskAugmentation(builder, maskBytes);
1388 private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) {
1389 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1390 macAddress.setMacAddress(address);
1391 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1395 * Method converts OF SetField action to SAL SetFiled action.
1398 * @param ofVersion current ofp version
1401 public static SetField fromOFSetFieldToSALSetFieldAction(
1402 final Action action, OpenflowVersion ofVersion) {
1403 logger.debug("Converting OF SetField action to SAL SetField action");
1404 SetFieldBuilder setField = new SetFieldBuilder();
1405 OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
1406 MatchBuilder match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntries(), null, ofVersion);
1407 setField.fieldsFrom(match.build());
1408 return setField.build();