2 * Copyright (c) 2013 Ericsson. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
11 import java.math.BigInteger;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
19 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
20 import org.opendaylight.openflowplugin.openflow.md.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.OpenflowVersion;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6FlowLabel;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeader;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6ExtHeaderBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6Label;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatch;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagMatchBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4Match;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcpFlagMatchEntry;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpFlag;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Dst;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelIpv4Src;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
185 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
186 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
187 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
188 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
189 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
190 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
191 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
192 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
193 import org.slf4j.Logger;
194 import org.slf4j.LoggerFactory;
196 import com.google.common.base.Optional;
197 import com.google.common.base.Splitter;
200 * Utility class for converting a MD-SAL Flow into the OF flow mod
202 public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
203 private static final Logger logger = LoggerFactory.getLogger(MatchConvertorImpl.class);
204 static final String PREFIX_SEPARATOR = "/";
205 static final Splitter PREFIX_SPLITTER = Splitter.on('/');
206 private static final byte[] VLAN_VID_MASK = new byte[] { 16, 0 };
207 private static final short PROTO_TCP = 6;
208 private static final short PROTO_UDP = 17;
209 private static final String noIp = "0.0.0.0/0";
212 public List<MatchEntries> convert(
213 final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) {
214 List<MatchEntries> matchEntriesList = new ArrayList<>();
215 if (match == null) return matchEntriesList;
216 if (match.getInPort() != null) {
217 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
218 matchEntriesList.add(toOfPort(InPort.class,
219 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPort())));
222 if (match.getInPhyPort() != null) {
223 //TODO: currently this matchconverter is mapped to OF1.3 in MatchReactorMappingFactory. Will need to revisit during 1.4+
224 matchEntriesList.add(toOfPort(InPhyPort.class,
225 InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, match.getInPhyPort())));
228 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata metadata = match
230 if (metadata != null) {
231 matchEntriesList.add(toOfMetadata(Metadata.class, metadata.getMetadata(), metadata.getMetadataMask()));
234 EthernetMatch ethernetMatch = match.getEthernetMatch();
235 if (ethernetMatch != null) {
236 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
237 if (ethernetDestination != null) {
238 matchEntriesList.add(toOfMacAddress(EthDst.class, ethernetDestination.getAddress(),
239 ethernetDestination.getMask()));
242 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
243 if (ethernetSource != null) {
245 .add(toOfMacAddress(EthSrc.class, ethernetSource.getAddress(), ethernetSource.getMask()));
248 if (ethernetMatch.getEthernetType() != null) {
249 matchEntriesList.add(toOfEthernetType(ethernetMatch.getEthernetType()));
253 VlanMatch vlanMatch = match.getVlanMatch();
254 if (vlanMatch != null) {
255 if (vlanMatch.getVlanId() != null) {
256 matchEntriesList.add(toOfVlanVid(vlanMatch.getVlanId()));
259 if (vlanMatch.getVlanPcp() != null) {
260 matchEntriesList.add(toOfVlanPcp(vlanMatch.getVlanPcp()));
264 IpMatch ipMatch = match.getIpMatch();
265 if (ipMatch != null) {
266 if (ipMatch.getIpDscp() != null) {
267 matchEntriesList.add(toOfIpDscp(ipMatch.getIpDscp()));
270 if (ipMatch.getIpEcn() != null) {
271 matchEntriesList.add(toOfIpEcn(ipMatch.getIpEcn()));
274 if (ipMatch.getIpProtocol() != null) {
275 matchEntriesList.add(toOfIpProto(ipMatch.getIpProtocol()));
280 Layer4Match layer4Match = match.getLayer4Match();
281 if (layer4Match != null) {
282 if (layer4Match instanceof TcpMatch) {
283 TcpMatch tcpMatch = (TcpMatch) layer4Match;
284 if (tcpMatch.getTcpSourcePort() != null) {
285 matchEntriesList.add(toOfLayer3Port(TcpSrc.class, tcpMatch.getTcpSourcePort()));
288 if (tcpMatch.getTcpDestinationPort() != null) {
289 matchEntriesList.add(toOfLayer3Port(TcpDst.class, tcpMatch.getTcpDestinationPort()));
291 } else if (layer4Match instanceof UdpMatch) {
292 UdpMatch udpMatch = (UdpMatch) layer4Match;
293 if (udpMatch.getUdpSourcePort() != null) {
294 matchEntriesList.add(toOfLayer3Port(UdpSrc.class, udpMatch.getUdpSourcePort()));
297 if (udpMatch.getUdpDestinationPort() != null) {
298 matchEntriesList.add(toOfLayer3Port(UdpDst.class, udpMatch.getUdpDestinationPort()));
300 } else if (layer4Match instanceof SctpMatch) {
301 SctpMatch sctpMatch = (SctpMatch) layer4Match;
302 if (sctpMatch.getSctpSourcePort() != null) {
303 matchEntriesList.add(toOfLayer3Port(SctpSrc.class, sctpMatch.getSctpSourcePort()));
306 if (sctpMatch.getSctpDestinationPort() != null) {
307 matchEntriesList.add(toOfLayer3Port(SctpDst.class, sctpMatch.getSctpDestinationPort()));
312 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
313 if (icmpv4Match != null) {
314 if (icmpv4Match.getIcmpv4Type() != null) {
315 matchEntriesList.add(toOfIcmpv4Type(icmpv4Match.getIcmpv4Type()));
318 if (icmpv4Match.getIcmpv4Code() != null) {
319 matchEntriesList.add(toOfIcmpv4Code(icmpv4Match.getIcmpv4Code()));
323 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
324 if (icmpv6Match != null) {
325 if (icmpv6Match.getIcmpv6Type() != null) {
326 matchEntriesList.add(toOfIcmpv6Type(icmpv6Match.getIcmpv6Type()));
329 if (icmpv6Match.getIcmpv6Code() != null) {
330 matchEntriesList.add(toOfIcmpv6Code(icmpv6Match.getIcmpv6Code()));
334 Layer3Match layer3Match = match.getLayer3Match();
335 if (layer3Match != null) {
336 if (layer3Match instanceof Ipv4Match) {
337 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
338 if (ipv4Match.getIpv4Source() != null) {
339 matchEntriesList.add(toOfIpv4Prefix(Ipv4Src.class, ipv4Match.getIpv4Source()));
341 if (ipv4Match.getIpv4Destination() != null) {
342 matchEntriesList.add(toOfIpv4Prefix(Ipv4Dst.class, ipv4Match.getIpv4Destination()));
345 if (layer3Match instanceof TunnelIpv4Match) {
346 TunnelIpv4Match tunnelIpv4Src = (TunnelIpv4Match) layer3Match;
347 if (tunnelIpv4Src.getTunnelIpv4Source() != null) {
348 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Src.class, tunnelIpv4Src.getTunnelIpv4Source()));
350 if (tunnelIpv4Src.getTunnelIpv4Destination() != null) {
351 matchEntriesList.add(NxmExtensionsConvertor.toNxmIpv4Tunnel(TunnelIpv4Dst.class, tunnelIpv4Src.getTunnelIpv4Destination()));
353 } else if (layer3Match instanceof ArpMatch) {
354 ArpMatch arpMatch = (ArpMatch) layer3Match;
355 if (arpMatch.getArpOp() != null) {
356 matchEntriesList.add(toOfArpOpCode(arpMatch.getArpOp()));
359 if (arpMatch.getArpSourceTransportAddress() != null) {
360 matchEntriesList.add(toOfIpv4Prefix(ArpSpa.class, arpMatch.getArpSourceTransportAddress()));
363 if (arpMatch.getArpTargetTransportAddress() != null) {
364 matchEntriesList.add(toOfIpv4Prefix(ArpTpa.class, arpMatch.getArpTargetTransportAddress()));
367 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
368 if (arpSourceHardwareAddress != null) {
369 matchEntriesList.add(toOfMacAddress(ArpSha.class, arpSourceHardwareAddress.getAddress(),
370 arpSourceHardwareAddress.getMask()));
373 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
374 if (arpTargetHardwareAddress != null) {
375 matchEntriesList.add(toOfMacAddress(ArpTha.class, arpTargetHardwareAddress.getAddress(),
376 arpTargetHardwareAddress.getMask()));
380 else if (layer3Match instanceof Ipv6Match) {
381 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
382 if (ipv6Match.getIpv6Source() != null) {
383 matchEntriesList.add(toOfIpv6Prefix(Ipv6Src.class, ipv6Match.getIpv6Source()));
386 if (ipv6Match.getIpv6Destination() != null) {
387 matchEntriesList.add(toOfIpv6Prefix(Ipv6Dst.class, ipv6Match.getIpv6Destination()));
390 if (ipv6Match.getIpv6Label() != null) {
391 matchEntriesList.add(toOfIpv6FlowLabel(ipv6Match.getIpv6Label()));
394 if (ipv6Match.getIpv6NdTarget() != null) {
395 matchEntriesList.add(toOfIpv6Address(ipv6Match.getIpv6NdTarget()));
398 if (ipv6Match.getIpv6NdSll() != null) {
399 matchEntriesList.add(toOfMacAddress(Ipv6NdSll.class, ipv6Match.getIpv6NdSll(), null));
402 if (ipv6Match.getIpv6NdTll() != null) {
403 matchEntriesList.add(toOfMacAddress(Ipv6NdTll.class, ipv6Match.getIpv6NdTll(), null));
406 if (ipv6Match.getIpv6ExtHeader() != null) {
407 matchEntriesList.add(toOfIpv6ExtHeader(ipv6Match.getIpv6ExtHeader()));
412 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
413 if (protocolMatchFields != null) {
414 if (protocolMatchFields.getMplsLabel() != null) {
415 matchEntriesList.add(toOfMplsLabel(protocolMatchFields.getMplsLabel()));
418 if (protocolMatchFields.getMplsBos() != null) {
419 matchEntriesList.add(toOfMplsBos(protocolMatchFields.getMplsBos()));
422 if (protocolMatchFields.getMplsTc() != null) {
423 matchEntriesList.add(toOfMplsTc(protocolMatchFields.getMplsTc()));
426 if (protocolMatchFields.getPbb() != null) {
427 matchEntriesList.add(toOfMplsPbb(protocolMatchFields.getPbb()));
431 //FIXME: move to extensible support
432 // TODO: Move to seperate bundle as soon as OF extensibility is supported by ofplugin/java
433 TcpFlagMatch tcpFlagMatch = match.getTcpFlagMatch();
434 if (tcpFlagMatch != null) {
435 if (tcpFlagMatch.getTcpFlag() != null) {
436 matchEntriesList.add(NxmExtensionsConvertor.toNxmTcpFlag(tcpFlagMatch.getTcpFlag()));
440 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel tunnel = match
442 if (tunnel != null) {
443 matchEntriesList.add(toOfMetadata(TunnelId.class, tunnel.getTunnelId(), tunnel.getTunnelMask()));
448 * TODO: EXTENSION PROPOSAL (match, MD-SAL to OFJava)
449 * - we might need version for conversion and for key
452 Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(match);
453 if (extensionListOpt.isPresent()) {
454 for (ExtensionList extensionItem : extensionListOpt.get().getExtensionList()) {
455 // TODO: get real version
456 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
457 ConvertorToOFJava<MatchEntries> convertor =
458 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
459 MatchEntries ofMatch = convertor.convert(extensionItem.getExtension());
460 matchEntriesList.add(ofMatch);
464 return matchEntriesList;
468 * Method convert Openflow 1.0 specific flow match to MD-SAL format flow
473 * @author avishnoi@in.ibm.com
475 public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
476 MatchBuilder matchBuilder = new MatchBuilder();
477 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
478 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
479 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
480 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
481 if (!swMatch.getWildcards().isINPORT().booleanValue() && swMatch.getInPort() != null) {
482 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
483 (long) swMatch.getInPort(), ofVersion));
486 if (!swMatch.getWildcards().isDLSRC().booleanValue() && swMatch.getDlSrc() != null) {
487 EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
488 ethSrcBuilder.setAddress(swMatch.getDlSrc());
489 ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
490 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
492 if (!swMatch.getWildcards().isDLDST().booleanValue() && swMatch.getDlDst() != null) {
493 EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
494 ethDstBuilder.setAddress(swMatch.getDlDst());
495 ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
496 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
498 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getDlType() != null) {
499 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
500 ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
501 (long) swMatch.getDlType()));
502 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
503 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
505 if (!swMatch.getWildcards().isDLVLAN().booleanValue() && swMatch.getDlVlan() != null) {
506 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
507 int vlanId = (swMatch.getDlVlan() == ((int) 0xffff)) ? 0 : swMatch.getDlVlan();
508 vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
509 vlanIdBuilder.setVlanIdPresent(vlanId == 0 ? false: true);
510 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
511 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
513 if (!swMatch.getWildcards().isDLVLANPCP().booleanValue() && swMatch.getDlVlanPcp() != null) {
514 vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
515 swMatch.getDlVlanPcp()));
516 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
518 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwSrc() != null) {
519 String ipv4PrefixStr = swMatch.getNwSrc().getValue();
520 if (swMatch.getNwSrcMask() != null) {
521 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwSrcMask();
523 if (!ipv4PrefixStr.equals(noIp)) {
524 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
525 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
528 if (!swMatch.getWildcards().isDLTYPE().booleanValue() && swMatch.getNwDst() != null) {
529 String ipv4PrefixStr = swMatch.getNwDst().getValue();
530 if (swMatch.getNwDstMask() != null) {
531 ipv4PrefixStr += PREFIX_SEPARATOR + swMatch.getNwDstMask();
533 if (!ipv4PrefixStr.equals(noIp)) {
534 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
535 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
538 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() != null) {
539 ipMatchBuilder.setIpProtocol(swMatch.getNwProto());
540 matchBuilder.setIpMatch(ipMatchBuilder.build());
542 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_TCP) {
543 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
544 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
546 .setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
547 swMatch.getTpSrc()));
549 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
551 .setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
552 swMatch.getTpDst()));
555 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
556 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
559 if (!swMatch.getWildcards().isNWPROTO().booleanValue() && swMatch.getNwProto() == PROTO_UDP) {
560 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
561 if (!swMatch.getWildcards().isTPSRC().booleanValue() && swMatch.getTpSrc() != null) {
563 .setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
564 swMatch.getTpSrc()));
566 if (!swMatch.getWildcards().isTPDST().booleanValue() && swMatch.getTpDst() != null) {
568 .setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(
569 swMatch.getTpDst()));
572 if (!swMatch.getWildcards().isTPSRC().booleanValue() || !swMatch.getWildcards().isTPDST().booleanValue()) {
573 matchBuilder.setLayer4Match(udpMatchBuilder.build());
576 if (!swMatch.getWildcards().isNWTOS().booleanValue() && swMatch.getNwTos() != null) {
577 // DSCP default value is 0 from the library but controller side it
579 // look if there better solution
580 if (0 != swMatch.getNwTos()) {
581 ipMatchBuilder.setIpDscp(new Dscp(swMatch.getNwTos()));
583 matchBuilder.setIpMatch(ipMatchBuilder.build());
586 return matchBuilder.build();
590 * Method converts Openflow 1.3+ specific flow match to MD-SAL format flow
597 * @return md-sal match instance
598 * @author avishnoi@in.ibm.com
600 public static MatchBuilder fromOFMatchToSALMatch(
601 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match swMatch,
602 final BigInteger datapathid, final OpenflowVersion ofVersion) {
603 return OfMatchToSALMatchConvertor(swMatch.getMatchEntries(), datapathid, ofVersion);
606 private static MatchBuilder OfMatchToSALMatchConvertor(List<MatchEntries> swMatchList, final BigInteger datapathid,
607 OpenflowVersion ofVersion){
609 MatchBuilder matchBuilder = new MatchBuilder();
610 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
611 VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
612 IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
613 TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
614 UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
615 SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
616 Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
617 Icmpv6MatchBuilder icmpv6MatchBuilder = new Icmpv6MatchBuilder();
618 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
619 ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
620 Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
621 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
622 TcpFlagMatchBuilder tcpFlagMatchBuilder = new TcpFlagMatchBuilder();
623 TunnelIpv4MatchBuilder tunnelIpv4MatchBuilder = new TunnelIpv4MatchBuilder();
625 for (MatchEntries ofMatch : swMatchList) {
627 if (ofMatch.getOxmMatchField().equals(InPort.class)) {
628 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
629 matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
630 portNumber.getPortNumber().getValue(), ofVersion));
631 } else if (ofMatch.getOxmMatchField().equals(InPhyPort.class)) {
632 PortNumberMatchEntry portNumber = ofMatch.getAugmentation(PortNumberMatchEntry.class);
633 matchBuilder.setInPhyPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid,
634 portNumber.getPortNumber().getValue(), ofVersion));
635 } else if (ofMatch.getOxmMatchField().equals(Metadata.class)) {
636 MetadataBuilder metadataBuilder = new MetadataBuilder();
637 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
638 if (metadataMatchEntry != null) {
639 metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
640 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
641 if (maskMatchEntry != null) {
642 metadataBuilder.setMetadataMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
645 matchBuilder.setMetadata(metadataBuilder.build());
647 } else if (ofMatch.getOxmMatchField().equals(EthSrc.class)) {
648 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
649 if (macAddressMatchEntry != null) {
650 EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
651 ethSourceBuilder.setAddress(macAddressMatchEntry.getMacAddress());
652 ethMatchBuilder.setEthernetSource(ethSourceBuilder.build());
653 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
655 } else if (ofMatch.getOxmMatchField().equals(EthDst.class)) {
656 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
657 if (macAddressMatchEntry != null) {
658 EthernetDestinationBuilder ethDestinationBuilder = new EthernetDestinationBuilder();
659 ethDestinationBuilder.setAddress(macAddressMatchEntry.getMacAddress());
660 ethMatchBuilder.setEthernetDestination(ethDestinationBuilder.build());
661 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
663 } else if (ofMatch.getOxmMatchField().equals(EthType.class)) {
664 EthTypeMatchEntry ethTypeMatchEntry = ofMatch.getAugmentation(EthTypeMatchEntry.class);
665 if (ethTypeMatchEntry != null) {
666 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
668 .setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType(
669 (long) ethTypeMatchEntry.getEthType().getValue()));
670 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
671 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
673 } else if (ofMatch.getOxmMatchField().equals(VlanVid.class)) {
674 VlanVidMatchEntry vlanVidMatchEntry = ofMatch.getAugmentation(VlanVidMatchEntry.class);
675 if (vlanVidMatchEntry != null) {
676 VlanIdBuilder vlanBuilder = new VlanIdBuilder();
677 vlanBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(
678 vlanVidMatchEntry.getVlanVid()));
679 vlanMatchBuilder.setVlanId(vlanBuilder.build());
680 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
682 } else if (ofMatch.getOxmMatchField().equals(VlanPcp.class)) {
683 VlanPcpMatchEntry vlanPcpMatchEntry = ofMatch.getAugmentation(VlanPcpMatchEntry.class);
684 if (vlanPcpMatchEntry != null) {
686 .setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(
687 vlanPcpMatchEntry.getVlanPcp()));
688 matchBuilder.setVlanMatch(vlanMatchBuilder.build());
690 } else if (ofMatch.getOxmMatchField().equals(IpDscp.class)) {
691 DscpMatchEntry dscpMatchEntry = ofMatch.getAugmentation(DscpMatchEntry.class);
692 if (dscpMatchEntry != null) {
693 ipMatchBuilder.setIpDscp(new Dscp(dscpMatchEntry.getDscp().getValue()));
694 matchBuilder.setIpMatch(ipMatchBuilder.build());
696 } else if (ofMatch.getOxmMatchField().equals(IpEcn.class)) {
697 EcnMatchEntry ecnMatchEntry = ofMatch.getAugmentation(EcnMatchEntry.class);
698 if (ecnMatchEntry != null) {
699 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
700 matchBuilder.setIpMatch(ipMatchBuilder.build());
702 } else if (ofMatch.getOxmMatchField().equals(IpProto.class)) {
703 ProtocolNumberMatchEntry protocolNumberMatchEntry = ofMatch
704 .getAugmentation(ProtocolNumberMatchEntry.class);
705 if (protocolNumberMatchEntry != null) {
706 ipMatchBuilder.setIpProtocol(protocolNumberMatchEntry.getProtocolNumber());
707 matchBuilder.setIpMatch(ipMatchBuilder.build());
709 } else if (ofMatch.getOxmMatchField().equals(TcpSrc.class)) {
710 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
711 if (portMatchEntry != null) {
712 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
713 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
715 } else if (ofMatch.getOxmMatchField().equals(TcpDst.class)) {
716 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
717 if (portMatchEntry != null) {
718 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
719 matchBuilder.setLayer4Match(tcpMatchBuilder.build());
721 } else if (ofMatch.getOxmMatchField().equals(UdpSrc.class)) {
722 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
723 if (portMatchEntry != null) {
724 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
725 matchBuilder.setLayer4Match(udpMatchBuilder.build());
727 } else if (ofMatch.getOxmMatchField().equals(UdpDst.class)) {
728 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
729 if (portMatchEntry != null) {
730 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
731 matchBuilder.setLayer4Match(udpMatchBuilder.build());
733 } else if (ofMatch.getOxmMatchField().equals(SctpSrc.class)) {
734 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
735 if (portMatchEntry != null) {
736 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
737 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
739 } else if (ofMatch.getOxmMatchField().equals(SctpDst.class)) {
740 PortMatchEntry portMatchEntry = ofMatch.getAugmentation(PortMatchEntry.class);
741 if (portMatchEntry != null) {
742 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
743 matchBuilder.setLayer4Match(sctpMatchBuilder.build());
745 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Type.class)) {
746 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = ofMatch.getAugmentation(Icmpv4TypeMatchEntry.class);
747 if (icmpv4TypeMatchEntry != null) {
748 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
749 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
751 } else if (ofMatch.getOxmMatchField().equals(Icmpv4Code.class)) {
752 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = ofMatch.getAugmentation(Icmpv4CodeMatchEntry.class);
753 if (icmpv4CodeMatchEntry != null) {
754 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
755 matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
757 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Type.class)) {
758 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = ofMatch.getAugmentation(Icmpv6TypeMatchEntry.class);
759 if (icmpv6TypeMatchEntry != null) {
760 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
761 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
763 } else if (ofMatch.getOxmMatchField().equals(Icmpv6Code.class)) {
764 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = ofMatch.getAugmentation(Icmpv6CodeMatchEntry.class);
765 if (icmpv6CodeMatchEntry != null) {
766 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
767 matchBuilder.setIcmpv6Match(icmpv6MatchBuilder.build());
769 } else if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)
770 || ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
771 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
772 if (ipv4AddressMatchEntry != null) {
773 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
774 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
775 if (maskMatchEntry != null) {
776 int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
778 while(receivedMask != 0xffffffff){
779 receivedMask = receivedMask >> 1;
782 ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount);
784 //Openflow Spec : 1.3.2
785 //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
786 // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
787 // statistics response.
789 ipv4PrefixStr+=PREFIX_SEPARATOR + "32";
791 if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) {
792 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
794 if (ofMatch.getOxmMatchField().equals(Ipv4Dst.class)) {
795 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
797 matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
801 else if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)
802 || ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
803 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
804 if (ipv4AddressMatchEntry != null) {
805 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
806 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
807 if (maskMatchEntry != null) {
808 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
810 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Dst.class)) {
811 tunnelIpv4MatchBuilder.setTunnelIpv4Destination(new Ipv4Prefix(ipv4PrefixStr));
813 if (ofMatch.getOxmMatchField().equals(TunnelIpv4Src.class)) {
814 tunnelIpv4MatchBuilder.setTunnelIpv4Source(new Ipv4Prefix(ipv4PrefixStr));
816 matchBuilder.setLayer3Match(tunnelIpv4MatchBuilder.build());
819 else if (ofMatch.getOxmMatchField().equals(ArpOp.class)) {
820 OpCodeMatchEntry opCodeMatchEntry = ofMatch.getAugmentation(OpCodeMatchEntry.class);
821 if (opCodeMatchEntry != null) {
822 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
823 matchBuilder.setLayer3Match(arpMatchBuilder.build());
825 } else if (ofMatch.getOxmMatchField().equals(ArpSpa.class)
826 || ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
827 Ipv4AddressMatchEntry ipv4AddressMatchEntry = ofMatch.getAugmentation(Ipv4AddressMatchEntry.class);
828 if (ipv4AddressMatchEntry != null) {
829 String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue();
830 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
831 if (maskMatchEntry != null) {
832 ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt();
834 if (ofMatch.getOxmMatchField().equals(ArpSpa.class)) {
835 arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
837 if (ofMatch.getOxmMatchField().equals(ArpTpa.class)) {
838 arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix(ipv4PrefixStr));
840 matchBuilder.setLayer3Match(arpMatchBuilder.build());
842 } else if (ofMatch.getOxmMatchField().equals(ArpSha.class)
843 || ofMatch.getOxmMatchField().equals(ArpTha.class)) {
844 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
845 if (macAddressMatchEntry != null) {
846 if (ofMatch.getOxmMatchField().equals(ArpSha.class)) {
847 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
848 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
849 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
850 if (maskMatchEntry != null) {
851 arpSourceHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
852 .macAddressToString(maskMatchEntry.getMask())));
854 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
855 matchBuilder.setLayer3Match(arpMatchBuilder.build());
857 if (ofMatch.getOxmMatchField().equals(ArpTha.class)) {
858 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
859 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
860 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
861 if (maskMatchEntry != null) {
862 arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils
863 .macAddressToString(maskMatchEntry.getMask())));
865 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
866 matchBuilder.setLayer3Match(arpMatchBuilder.build());
869 } else if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)
870 || ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
871 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
872 if (ipv6AddressMatchEntry != null) {
873 String ipv6PrefixStr = ipv6AddressMatchEntry.getIpv6Address().getValue();
874 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
875 if(maskMatchEntry != null){
876 ipv6PrefixStr += PREFIX_SEPARATOR
877 + MatchConvertorUtil.ipv6NetmaskArrayToCIDRValue(maskMatchEntry.getMask());
880 if (ofMatch.getOxmMatchField().equals(Ipv6Src.class)) {
881 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix(ipv6PrefixStr));
883 if (ofMatch.getOxmMatchField().equals(Ipv6Dst.class)) {
884 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix(ipv6PrefixStr));
886 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
888 } else if (ofMatch.getOxmMatchField().equals(Ipv6Flabel.class)) {
889 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = ofMatch.getAugmentation(Ipv6FlabelMatchEntry.class);
890 if (ipv6FlabelMatchEntry != null) {
891 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
892 ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(ipv6FlabelMatchEntry.getIpv6Flabel()));
893 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
894 if (maskMatchEntry != null) {
895 ipv6LabelBuilder.setFlabelMask(new Ipv6FlowLabel(Long.valueOf(ByteUtil
896 .bytesToUnsignedInt(maskMatchEntry.getMask()))));
898 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
899 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
901 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTarget.class)) {
902 Ipv6AddressMatchEntry ipv6AddressMatchEntry = ofMatch.getAugmentation(Ipv6AddressMatchEntry.class);
903 if (ipv6AddressMatchEntry != null) {
904 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
905 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
907 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdSll.class)) {
908 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
909 if (macAddressMatchEntry != null) {
910 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
911 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
913 } else if (ofMatch.getOxmMatchField().equals(Ipv6NdTll.class)) {
914 MacAddressMatchEntry macAddressMatchEntry = ofMatch.getAugmentation(MacAddressMatchEntry.class);
915 if (macAddressMatchEntry != null) {
916 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
917 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
919 } else if (ofMatch.getOxmMatchField().equals(Ipv6Exthdr.class)) {
920 PseudoFieldMatchEntry pseudoFieldMatchEntry = ofMatch.getAugmentation(PseudoFieldMatchEntry.class);
921 if (pseudoFieldMatchEntry != null) {
922 Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
924 Ipv6ExthdrFlags pField = pseudoFieldMatchEntry.getPseudoField();
925 Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(pField);
927 ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
928 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
929 if (maskMatchEntry != null) {
930 ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(maskMatchEntry.getMask()));
932 ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
933 matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
935 } else if (ofMatch.getOxmMatchField().equals(MplsLabel.class)) {
936 MplsLabelMatchEntry mplsLabelMatchEntry = ofMatch.getAugmentation(MplsLabelMatchEntry.class);
937 if (mplsLabelMatchEntry != null) {
938 protocolMatchFieldsBuilder.setMplsLabel(mplsLabelMatchEntry.getMplsLabel());
939 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
941 } else if (ofMatch.getOxmMatchField().equals(MplsBos.class)) {
942 BosMatchEntry bosMatchEntry = ofMatch.getAugmentation(BosMatchEntry.class);
943 if (bosMatchEntry != null) {
944 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos() ? (short) 1 : (short) 0);
945 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
947 } else if (ofMatch.getOxmMatchField().equals(MplsTc.class)) {
948 TcMatchEntry tcMatchEntry = ofMatch.getAugmentation(TcMatchEntry.class);
949 if (tcMatchEntry != null) {
950 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
951 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
953 } else if (ofMatch.getOxmMatchField().equals(PbbIsid.class)) {
954 IsidMatchEntry isidMatchEntry = ofMatch.getAugmentation(IsidMatchEntry.class);
955 if (isidMatchEntry != null) {
956 PbbBuilder pbbBuilder = new PbbBuilder();
957 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
958 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
959 if (maskMatchEntry != null) {
960 pbbBuilder.setPbbMask(ByteUtil.bytesToUnsignedInt(maskMatchEntry.getMask()));
962 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
963 matchBuilder.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
965 } else if (ofMatch.getOxmMatchField().equals(TunnelId.class)) {
966 TunnelBuilder tunnelBuilder = new TunnelBuilder();
967 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
968 if (metadataMatchEntry != null) {
969 tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
970 MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
971 if (maskMatchEntry != null) {
972 tunnelBuilder.setTunnelMask(new BigInteger(OFConstants.SIGNUM_UNSIGNED, maskMatchEntry
975 matchBuilder.setTunnel(tunnelBuilder.build());
977 } else if (ofMatch.getOxmMatchField().equals(TcpFlag.class)) {
978 //FIXME: move to extensible support
979 TcpFlagMatchEntry tcpFlagMatch = ofMatch.getAugmentation(TcpFlagMatchEntry.class);
980 if (tcpFlagMatch != null) {
981 tcpFlagMatchBuilder.setTcpFlag(tcpFlagMatch.getTcpFlag());
982 matchBuilder.setTcpFlagMatch(tcpFlagMatchBuilder.build());
988 private static MatchEntries toOfMplsPbb(final Pbb pbb) {
989 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
990 boolean hasmask = false;
991 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
992 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
993 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
994 isidBuilder.setIsid(pbb.getPbbIsid());
995 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
996 if (pbb.getPbbMask() != null) {
998 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(pbb.getPbbMask()));
1000 matchEntriesBuilder.setHasMask(hasmask);
1001 return matchEntriesBuilder.build();
1004 private static MatchEntries toOfMplsTc(final Short mplsTc) {
1005 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1006 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1007 matchEntriesBuilder.setHasMask(false);
1008 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
1009 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
1010 tcBuilder.setTc(mplsTc);
1011 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
1012 return matchEntriesBuilder.build();
1015 private static MatchEntries toOfMplsBos(final Short mplsBos) {
1016 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1017 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1018 matchEntriesBuilder.setHasMask(false);
1019 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
1020 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
1022 bosBuilder.setBos(true);
1024 bosBuilder.setBos(false);
1026 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
1027 return matchEntriesBuilder.build();
1030 private static MatchEntries toOfMplsLabel(final Long mplsLabel) {
1031 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1032 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1033 matchEntriesBuilder.setHasMask(false);
1034 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
1035 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
1036 mplsLabelBuilder.setMplsLabel(mplsLabel);
1037 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
1038 return matchEntriesBuilder.build();
1041 private static MatchEntries toOfIpv6ExtHeader(final Ipv6ExtHeader ipv6ExtHeader) {
1042 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1043 boolean hasmask = false;
1044 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1045 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
1046 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
1047 Integer bitmap = ipv6ExtHeader.getIpv6Exthdr();
1048 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
1049 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
1050 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
1051 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
1052 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
1053 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
1054 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
1055 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
1056 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
1057 pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
1058 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
1059 if (ipv6ExtHeader.getIpv6ExthdrMask() != null) {
1061 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedShortToBytes(ipv6ExtHeader.getIpv6ExthdrMask()));
1063 matchEntriesBuilder.setHasMask(hasmask);
1064 return matchEntriesBuilder.build();
1067 private static MatchEntries toOfIpv6FlowLabel(final Ipv6Label ipv6Label) {
1068 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1069 boolean hasmask = false;
1070 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1071 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
1072 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
1073 ipv6FlabelBuilder.setIpv6Flabel(ipv6Label.getIpv6Flabel());
1074 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
1075 if (ipv6Label.getFlabelMask() != null) {
1077 addMaskAugmentation(matchEntriesBuilder, ByteUtil.unsignedIntToBytes(ipv6Label.getFlabelMask().getValue()));
1079 matchEntriesBuilder.setHasMask(hasmask);
1080 return matchEntriesBuilder.build();
1083 private static MatchEntries toOfPort(final Class<? extends MatchField> field, final Long portNumber) {
1084 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1085 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1086 matchEntriesBuilder.setHasMask(false);
1087 matchEntriesBuilder.setOxmMatchField(field);
1088 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
1089 port.setPortNumber(new PortNumber(portNumber));
1090 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
1091 return matchEntriesBuilder.build();
1094 private static MatchEntries toOfMetadata(final Class<? extends MatchField> field, final BigInteger metadata,
1095 final BigInteger metadataMask) {
1096 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1097 boolean hasmask = false;
1098 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1099 matchEntriesBuilder.setOxmMatchField(field);
1100 addMetadataAugmentation(matchEntriesBuilder, metadata);
1101 if (metadataMask != null) {
1103 addMaskAugmentation(matchEntriesBuilder,
1104 ByteUtil.convertBigIntegerToNBytes(metadataMask, OFConstants.SIZE_OF_LONG_IN_BYTES));
1106 matchEntriesBuilder.setHasMask(hasmask);
1107 return matchEntriesBuilder.build();
1110 public static MatchEntries toOfMacAddress(final Class<? extends MatchField> field,
1111 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress macAddress,
1112 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress mask) {
1113 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1114 boolean hasmask = false;
1115 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1116 matchEntriesBuilder.setOxmMatchField(field);
1117 addMacAddressAugmentation(matchEntriesBuilder, macAddress);
1120 addMaskAugmentation(matchEntriesBuilder, ByteBufUtils.macAddressToBytes(mask.getValue()));
1122 matchEntriesBuilder.setHasMask(hasmask);
1123 return matchEntriesBuilder.build();
1126 private static MatchEntries toOfEthernetType(final EthernetType ethernetType) {
1127 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1128 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1129 matchEntriesBuilder.setHasMask(false);
1130 matchEntriesBuilder.setOxmMatchField(EthType.class);
1131 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
1132 ethertypeBuilder.setEthType(new EtherType(ethernetType.getType().getValue().intValue()));
1133 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
1134 return matchEntriesBuilder.build();
1137 private static MatchEntries toOfLayer3Port(final Class<? extends MatchField> field,
1138 final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber portNumber) {
1139 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1140 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1141 matchEntriesBuilder.setHasMask(false);
1142 matchEntriesBuilder.setOxmMatchField(field);
1143 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
1144 portBuilder.setPort(portNumber);
1145 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build());
1146 return matchEntriesBuilder.build();
1149 private static MatchEntries toOfIcmpv4Type(final Short icmpv4Type) {
1150 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1151 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1152 matchEntriesBuilder.setHasMask(false);
1153 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
1154 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
1155 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Type);
1156 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
1157 return matchEntriesBuilder.build();
1160 private static MatchEntries toOfIcmpv4Code(final Short icmpv4Code) {
1161 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1162 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1163 matchEntriesBuilder.setHasMask(false);
1164 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
1165 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
1166 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Code);
1167 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
1168 return matchEntriesBuilder.build();
1171 private static MatchEntries toOfIcmpv6Type(final Short icmpv6Type) {
1172 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1173 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1174 matchEntriesBuilder.setHasMask(false);
1175 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
1176 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
1177 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Type);
1178 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
1179 return matchEntriesBuilder.build();
1182 private static MatchEntries toOfIcmpv6Code(final Short icmpv6Code) {
1183 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1184 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1185 matchEntriesBuilder.setHasMask(false);
1186 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
1187 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
1188 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Code);
1189 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
1190 return matchEntriesBuilder.build();
1193 public static MatchEntries toOfIpv4Prefix(final Class<? extends MatchField> field, final Ipv4Prefix ipv4Prefix) {
1194 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1195 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1196 matchEntriesBuilder.setOxmMatchField(field);
1197 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Prefix);
1198 matchEntriesBuilder.setHasMask(hasMask);
1199 return matchEntriesBuilder.build();
1202 private static MatchEntries toOfIpv6Prefix(final Class<? extends MatchField> field, final Ipv6Prefix ipv6Prefix) {
1203 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1204 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1205 matchEntriesBuilder.setOxmMatchField(field);
1206 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Prefix);
1207 matchEntriesBuilder.setHasMask(hasmask);
1208 return matchEntriesBuilder.build();
1211 public static MatchEntries toOfIpDscp(final Dscp ipDscp) {
1212 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1213 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1214 matchEntriesBuilder.setHasMask(false);
1215 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
1216 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
1217 dscpBuilder.setDscp(ipDscp);
1218 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
1219 return matchEntriesBuilder.build();
1222 public static MatchEntries toOfVlanPcp(
1223 final org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp vlanPcp) {
1224 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1225 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1226 matchEntriesBuilder.setHasMask(false);
1227 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
1228 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
1229 vlanPcpBuilder.setVlanPcp(vlanPcp.getValue());
1230 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
1231 return matchEntriesBuilder.build();
1234 private static MatchEntries toOfVlanVid(final VlanId vlanId) {
1236 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1237 boolean hasmask = false;
1238 boolean setCfiBit = false;
1239 Integer vidEntryValue = 0;
1240 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1241 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
1242 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
1243 if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
1245 if (vlanId.getVlanId() != null) {
1246 vidEntryValue = vlanId.getVlanId().getValue();
1248 hasmask = (vidEntryValue == 0);
1250 vlanVidBuilder.setCfiBit(setCfiBit);
1251 vlanVidBuilder.setVlanVid(vidEntryValue);
1252 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
1254 addMaskAugmentation(matchEntriesBuilder, VLAN_VID_MASK);
1256 matchEntriesBuilder.setHasMask(hasmask);
1257 return matchEntriesBuilder.build();
1260 private static MatchEntries toOfIpProto(final Short ipProtocol) {
1261 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1262 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1263 matchEntriesBuilder.setHasMask(false);
1264 matchEntriesBuilder.setOxmMatchField(IpProto.class);
1265 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
1266 protoNumberBuilder.setProtocolNumber(ipProtocol);
1267 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
1268 return matchEntriesBuilder.build();
1271 private static MatchEntries toOfIpEcn(final Short ipEcn) {
1272 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1273 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1274 matchEntriesBuilder.setHasMask(false);
1275 matchEntriesBuilder.setOxmMatchField(IpEcn.class);
1276 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
1277 ecnBuilder.setEcn(ipEcn);
1278 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
1279 return matchEntriesBuilder.build();
1282 private static MatchEntries toOfArpOpCode(final Integer arpOp) {
1283 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1284 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1285 matchEntriesBuilder.setHasMask(false);
1286 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
1287 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
1288 opcodeBuilder.setOpCode(arpOp);
1289 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
1290 return matchEntriesBuilder.build();
1293 private static MatchEntries toOfIpv6Address(final Ipv6Address address) {
1294 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
1295 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
1296 matchEntriesBuilder.setHasMask(false);
1297 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
1298 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1299 ipv6AddressBuilder.setIpv6Address(address);
1300 matchEntriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1301 return matchEntriesBuilder.build();
1304 private static void addMaskAugmentation(final MatchEntriesBuilder builder, final byte[] mask) {
1305 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
1306 maskBuilder.setMask(mask);
1307 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
1310 private static boolean addIpv6PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv6Prefix address) {
1311 boolean hasMask = false;
1312 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1313 Ipv6Address ipv6Address = new Ipv6Address(addressParts.next());
1315 Integer prefix = null;
1316 if (addressParts.hasNext()) {
1317 prefix = Integer.parseInt(addressParts.next());
1320 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
1321 ipv6AddressBuilder.setIpv6Address(ipv6Address);
1322 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
1323 if (prefix != null) {
1325 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
1330 private static byte[] convertIpv6PrefixToByteArray(final int prefix) {
1331 // TODO: Temporary fix. Has performance impacts.
1332 byte[] mask = new byte[16];
1333 int oneCount = prefix;
1334 for (int count = 0; count < 16; count++) {
1336 if (oneCount >= 8) {
1338 oneCount = oneCount - 8;
1340 byteBits = oneCount;
1344 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
1349 private static void addMetadataAugmentation(final MatchEntriesBuilder builder, final BigInteger metadata) {
1350 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
1351 metadataMatchEntry.setMetadata(ByteUtil.convertBigIntegerToNBytes(metadata, OFConstants.SIZE_OF_LONG_IN_BYTES));
1352 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
1356 * @return true if Ipv4Prefix contains prefix (and it is used in mask),
1359 private static boolean addIpv4PrefixAugmentation(final MatchEntriesBuilder builder, final Ipv4Prefix address) {
1360 boolean hasMask = false;
1361 Iterator<String> addressParts = PREFIX_SPLITTER.split(address.getValue()).iterator();
1362 Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
1365 if (addressParts.hasNext()) {
1366 prefix = Integer.parseInt(addressParts.next());
1371 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
1372 ipv4AddressBuilder.setIpv4Address(ipv4Address);
1373 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
1375 int mask = 0xffffffff << (32 - prefix);
1376 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
1378 addMaskAugmentation(builder, maskBytes);
1384 private static void addMacAddressAugmentation(final MatchEntriesBuilder builder, final MacAddress address) {
1385 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
1386 macAddress.setMacAddress(address);
1387 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
1391 * Method converts OF SetField action to SAL SetFiled action.
1394 * @param ofVersion current ofp version
1397 public static SetField fromOFSetFieldToSALSetFieldAction(
1398 final Action action, OpenflowVersion ofVersion) {
1399 logger.debug("Converting OF SetField action to SAL SetField action");
1400 SetFieldBuilder setField = new SetFieldBuilder();
1401 OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
1402 MatchBuilder match = OfMatchToSALMatchConvertor(oxmFields.getMatchEntries(), null, ofVersion);
1403 setField.fieldsFrom(match.build());
1404 return setField.build();