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;
11 import java.math.BigInteger;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetField;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActions;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActions;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.Meter;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActions;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadata;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ipv6.match.fields.Ipv6LabelBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
183 import org.slf4j.Logger;
184 import org.slf4j.LoggerFactory;
187 * Utility class for converting a MD-SAL Flow into the OF flow mod
189 public class FlowConvertor {
190 private static final Logger logger = LoggerFactory.getLogger(FlowConvertor.class);
191 private static final String PREFIX_SEPARATOR = "/";
193 public static FlowModInput toFlowModInput(Flow flow, short version) {
194 FlowModInputBuilder flowMod = new FlowModInputBuilder();
196 flowMod.setCookie(flow.getCookie());
198 if (flow.getCookieMask() != null) {
199 flowMod.setCookieMask(new BigInteger(flow.getCookieMask().toString()));
202 if (flow.getTableId() != null) {
203 flowMod.setTableId(new TableId(flow.getTableId().longValue()));
206 if (flow instanceof AddFlowInput) {
207 flowMod.setCommand(FlowModCommand.OFPFCADD);
208 } else if (flow instanceof RemoveFlowInput) {
209 if (flow.isStrict()) {
210 flowMod.setCommand(FlowModCommand.OFPFCDELETESTRICT);
212 flowMod.setCommand(FlowModCommand.OFPFCDELETE);
214 } else if (flow instanceof UpdateFlowInput) {
215 if (flow.isStrict()) {
216 flowMod.setCommand(FlowModCommand.OFPFCMODIFYSTRICT);
218 flowMod.setCommand(FlowModCommand.OFPFCMODIFY);
222 flowMod.setIdleTimeout(flow.getIdleTimeout());
223 flowMod.setHardTimeout(flow.getHardTimeout());
224 flowMod.setPriority(flow.getPriority());
225 flowMod.setBufferId(flow.getBufferId());
227 if (flow.getOutPort() != null) {
228 flowMod.setOutPort(new PortNumber(flow.getOutPort().longValue()));
231 flowMod.setOutGroup(flow.getOutGroup());
233 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags flowModFlags = flow.getFlags();
234 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags ofFlowModFlags = null;
235 if (flowModFlags != null) {
236 ofFlowModFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags(
237 flowModFlags.isCHECKOVERLAP(), flowModFlags.isNOBYTCOUNTS(), flowModFlags.isNOPKTCOUNTS(),
238 flowModFlags.isRESETCOUNTS(), flowModFlags.isSENDFLOWREM());
240 flowMod.setFlags(ofFlowModFlags);
242 if (flow.getMatch() != null) {
243 MatchBuilder matchBuilder = new MatchBuilder();
244 matchBuilder.setMatchEntries(toMatch(flow.getMatch()));
245 flowMod.setMatch(matchBuilder.build());
248 if (flow.getInstructions() != null) {
249 flowMod.setInstructions(toInstructions(flow.getInstructions(), version));
251 flowMod.setVersion(version);
252 return flowMod.build();
255 public static List<MatchEntries> toMatch(
256 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
258 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
259 List<MatchEntries> matchEntriesList = new ArrayList<>();
261 if (match.getInPort() != null) {
262 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
263 matchEntriesBuilder.setHasMask(false);
264 matchEntriesBuilder.setOxmMatchField(InPort.class);
265 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
266 port.setPortNumber(new PortNumber(match.getInPort()));
267 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
268 matchEntriesList.add(matchEntriesBuilder.build());
271 if (match.getInPhyPort() != null) {
272 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
273 matchEntriesBuilder.setHasMask(false);
274 matchEntriesBuilder.setOxmMatchField(InPhyPort.class);
275 PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();
276 phyPort.setPortNumber(new PortNumber(match.getInPhyPort()));
277 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());
278 matchEntriesList.add(matchEntriesBuilder.build());
281 if (match.getMetadata() != null) {
282 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
283 matchEntriesBuilder.setHasMask(false);
284 matchEntriesBuilder.setOxmMatchField(Metadata.class);
285 addMetadataAugmentation(matchEntriesBuilder, match.getMetadata().getMetadata());
286 if (match.getMetadata().getMetadataMask() != null) {
287 addMaskAugmentation(matchEntriesBuilder, match.getMetadata().getMetadataMask());
289 matchEntriesList.add(matchEntriesBuilder.build());
292 if (match.getEthernetMatch() != null) {
293 EthernetMatch ethernetMatch = match.getEthernetMatch();
294 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
295 if (ethernetDestination != null) {
296 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
297 matchEntriesBuilder.setHasMask(false);
298 matchEntriesBuilder.setOxmMatchField(EthDst.class);
299 addMacAddressAugmentation(matchEntriesBuilder, ethernetDestination.getAddress());
300 if (ethernetDestination.getMask() != null) {
301 addMaskAugmentation(matchEntriesBuilder, ethernetDestination.getMask());
303 matchEntriesList.add(matchEntriesBuilder.build());
306 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
307 if (ethernetSource != null) {
308 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
309 matchEntriesBuilder.setHasMask(false);
310 matchEntriesBuilder.setOxmMatchField(EthSrc.class);
311 addMacAddressAugmentation(matchEntriesBuilder, ethernetSource.getAddress());
312 if (ethernetSource.getMask() != null) {
313 addMaskAugmentation(matchEntriesBuilder, ethernetSource.getMask());
315 matchEntriesList.add(matchEntriesBuilder.build());
318 if (ethernetMatch.getEthernetType() != null) {
319 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
320 matchEntriesBuilder.setHasMask(false);
321 matchEntriesBuilder.setOxmMatchField(EthType.class);
322 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
323 ethertypeBuilder.setEthType(new EtherType(ethernetMatch.getEthernetType().getType().getValue()
325 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
326 matchEntriesList.add(matchEntriesBuilder.build());
330 VlanMatch vlanMatch = match.getVlanMatch();
331 if (vlanMatch != null) {
332 if (vlanMatch.getVlanId() != null) {
334 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
335 matchEntriesBuilder.setHasMask(true);
336 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
337 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
338 Integer vidEntryValue = vlanMatch.getVlanId().getVlanId().getValue();
339 vlanVidBuilder.setCfiBit(vidEntryValue != 0);
340 vlanVidBuilder.setVlanVid(vidEntryValue);
341 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
342 if (vlanMatch.getVlanId().getMask() != null) {
343 addMaskAugmentation(matchEntriesBuilder, vlanMatch.getVlanId().getMask());
345 matchEntriesList.add(matchEntriesBuilder.build());
348 if (vlanMatch.getVlanPcp() != null) {
349 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
350 matchEntriesBuilder.setHasMask(false);
351 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
352 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
353 vlanPcpBuilder.setVlanPcp(vlanMatch.getVlanPcp().getValue());
354 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
355 matchEntriesList.add(matchEntriesBuilder.build());
359 IpMatch ipMatch = match.getIpMatch();
360 if (ipMatch != null) {
361 if (ipMatch.getIpDscp() != null) {
362 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
363 matchEntriesBuilder.setHasMask(false);
364 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
365 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
366 dscpBuilder.setDscp(ipMatch.getIpDscp());
367 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
368 matchEntriesList.add(matchEntriesBuilder.build());
371 if (ipMatch.getIpEcn() != null) {
372 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
373 matchEntriesBuilder.setHasMask(false);
374 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
375 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
376 ecnBuilder.setEcn(ipMatch.getIpEcn());
377 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
378 matchEntriesList.add(matchEntriesBuilder.build());
381 if (ipMatch.getIpProto() != null) {
382 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
383 matchEntriesBuilder.setHasMask(false);
384 matchEntriesBuilder.setOxmMatchField(IpProto.class);
385 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
386 protoNumberBuilder.setProtocolNumber((short) ipMatch.getIpProto().getIntValue());
387 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
388 matchEntriesList.add(matchEntriesBuilder.build());
393 Layer4Match layer4Match = match.getLayer4Match();
394 if (layer4Match != null) {
395 if (layer4Match instanceof TcpMatch) {
396 TcpMatch tcpMatch = (TcpMatch) layer4Match;
397 if (tcpMatch.getTcpSourcePort() != null) {
398 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
399 matchEntriesBuilder.setHasMask(false);
400 matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
401 addPortAugmentation(matchEntriesBuilder, tcpMatch.getTcpSourcePort());
402 matchEntriesList.add(matchEntriesBuilder.build());
405 if (tcpMatch.getTcpDestinationPort() != null) {
406 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
407 matchEntriesBuilder.setHasMask(false);
408 matchEntriesBuilder.setOxmMatchField(TcpDst.class);
409 addPortAugmentation(matchEntriesBuilder, tcpMatch.getTcpDestinationPort());
410 matchEntriesList.add(matchEntriesBuilder.build());
414 else if (layer4Match instanceof UdpMatch) {
415 UdpMatch udpMatch = (UdpMatch) layer4Match;
416 if (udpMatch.getUdpSourcePort() != null) {
417 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
418 matchEntriesBuilder.setHasMask(false);
419 matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
420 addPortAugmentation(matchEntriesBuilder, udpMatch.getUdpSourcePort());
421 matchEntriesList.add(matchEntriesBuilder.build());
424 if (udpMatch.getUdpDestinationPort() != null) {
425 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
426 matchEntriesBuilder.setHasMask(false);
427 matchEntriesBuilder.setOxmMatchField(UdpDst.class);
428 addPortAugmentation(matchEntriesBuilder, udpMatch.getUdpDestinationPort());
429 matchEntriesList.add(matchEntriesBuilder.build());
433 else if (layer4Match instanceof SctpMatch) {
434 SctpMatch sctpMatch = (SctpMatch) layer4Match;
435 if (sctpMatch.getSctpSourcePort() != null) {
436 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
437 matchEntriesBuilder.setHasMask(false);
438 matchEntriesBuilder.setOxmMatchField(SctpSrc.class);
439 addPortAugmentation(matchEntriesBuilder, sctpMatch.getSctpSourcePort());
440 matchEntriesList.add(matchEntriesBuilder.build());
443 if (sctpMatch.getSctpDestinationPort() != null) {
444 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
445 matchEntriesBuilder.setHasMask(false);
446 matchEntriesBuilder.setOxmMatchField(SctpDst.class);
447 addPortAugmentation(matchEntriesBuilder, sctpMatch.getSctpDestinationPort());
448 matchEntriesList.add(matchEntriesBuilder.build());
453 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
454 if (icmpv4Match != null) {
455 if (icmpv4Match.getIcmpv4Type() != null) {
456 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
457 matchEntriesBuilder.setHasMask(false);
458 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
459 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
460 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Match.getIcmpv4Type());
461 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
462 matchEntriesList.add(matchEntriesBuilder.build());
465 if (icmpv4Match.getIcmpv4Code() != null) {
466 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
467 matchEntriesBuilder.setHasMask(false);
468 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
469 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
470 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Match.getIcmpv4Code());
471 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
472 matchEntriesList.add(matchEntriesBuilder.build());
476 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
477 if (icmpv6Match != null) {
478 if (icmpv6Match.getIcmpv6Type() != null) {
479 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
480 matchEntriesBuilder.setHasMask(false);
481 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
482 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
483 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Match.getIcmpv6Type());
484 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
485 matchEntriesList.add(matchEntriesBuilder.build());
488 if (icmpv6Match.getIcmpv6Code() != null) {
489 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
490 matchEntriesBuilder.setHasMask(false);
491 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
492 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
493 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Match.getIcmpv6Code());
494 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
495 matchEntriesList.add(matchEntriesBuilder.build());
499 Layer3Match layer3Match = match.getLayer3Match();
500 if (layer3Match != null) {
501 if (layer3Match instanceof Ipv4Match) {
502 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
503 if (ipv4Match.getIpv4Source() != null) {
504 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
505 matchEntriesBuilder.setHasMask(false);
506 matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);
507 addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Match.getIpv4Source());
508 matchEntriesList.add(matchEntriesBuilder.build());
510 if (ipv4Match.getIpv4Destination() != null) {
511 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
512 matchEntriesBuilder.setHasMask(false);
513 matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);
514 addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Match.getIpv4Destination());
515 matchEntriesList.add(matchEntriesBuilder.build());
519 else if (layer3Match instanceof ArpMatch) {
520 ArpMatch arpMatch = (ArpMatch) layer3Match;
521 if (arpMatch.getArpOp() != null) {
522 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
523 matchEntriesBuilder.setHasMask(false);
524 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
525 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
526 opcodeBuilder.setOpCode(arpMatch.getArpOp());
527 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
528 matchEntriesList.add(matchEntriesBuilder.build());
531 if (arpMatch.getArpSourceTransportAddress() != null) {
532 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
533 matchEntriesBuilder.setHasMask(false);
534 matchEntriesBuilder.setOxmMatchField(ArpSpa.class);
535 addIpv4PrefixAugmentation(matchEntriesBuilder, arpMatch.getArpSourceTransportAddress());
536 matchEntriesList.add(matchEntriesBuilder.build());
539 if (arpMatch.getArpTargetTransportAddress() != null) {
540 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
541 matchEntriesBuilder.setHasMask(false);
542 matchEntriesBuilder.setOxmMatchField(ArpTpa.class);
543 addIpv4PrefixAugmentation(matchEntriesBuilder, arpMatch.getArpTargetTransportAddress());
544 matchEntriesList.add(matchEntriesBuilder.build());
547 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
548 if (arpSourceHardwareAddress != null) {
549 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
550 matchEntriesBuilder.setHasMask(false);
551 matchEntriesBuilder.setOxmMatchField(ArpSha.class);
552 addMacAddressAugmentation(matchEntriesBuilder, arpSourceHardwareAddress.getAddress());
553 if (arpSourceHardwareAddress.getMask() != null) {
554 addMaskAugmentation(matchEntriesBuilder, arpSourceHardwareAddress.getMask());
556 matchEntriesList.add(matchEntriesBuilder.build());
559 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
560 if (arpTargetHardwareAddress != null) {
561 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
562 matchEntriesBuilder.setHasMask(false);
563 matchEntriesBuilder.setOxmMatchField(ArpTha.class);
564 addMacAddressAugmentation(matchEntriesBuilder, arpTargetHardwareAddress.getAddress());
565 if (arpTargetHardwareAddress.getMask() != null) {
566 addMaskAugmentation(matchEntriesBuilder, arpTargetHardwareAddress.getMask());
568 matchEntriesList.add(matchEntriesBuilder.build());
572 else if (layer3Match instanceof Ipv6Match) {
573 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
574 if (ipv6Match.getIpv6Source() != null) {
575 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
576 matchEntriesBuilder.setHasMask(false);
577 matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);
578 addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Source());
579 matchEntriesList.add(matchEntriesBuilder.build());
582 if (ipv6Match.getIpv6Destination() != null) {
583 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
584 matchEntriesBuilder.setHasMask(false);
585 matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);
586 addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Destination());
587 matchEntriesList.add(matchEntriesBuilder.build());
590 if (ipv6Match.getIpv6Label() != null) {
591 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
592 matchEntriesBuilder.setHasMask(false);
593 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
594 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
595 ipv6FlabelBuilder.setIpv6Flabel(ipv6Match.getIpv6Label().getIpv6Flabel());
596 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
597 if (ipv6Match.getIpv6Label().getFlabelMask() != null) {
598 addMaskAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Label().getFlabelMask());
600 matchEntriesList.add(matchEntriesBuilder.build());
603 if (ipv6Match.getIpv6NdTarget() != null) {
604 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
605 matchEntriesBuilder.setHasMask(false);
606 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
607 addIpv6AddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdTarget());
608 matchEntriesList.add(matchEntriesBuilder.build());
611 if (ipv6Match.getIpv6NdSll() != null) {
612 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
613 matchEntriesBuilder.setHasMask(false);
614 matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class);
615 addMacAddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdSll());
616 matchEntriesList.add(matchEntriesBuilder.build());
619 if (ipv6Match.getIpv6NdTll() != null) {
620 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
621 matchEntriesBuilder.setHasMask(false);
622 matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class);
623 addMacAddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdTll());
624 matchEntriesList.add(matchEntriesBuilder.build());
627 if (ipv6Match.getIpv6Exthdr() != null) {
629 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
630 matchEntriesBuilder.setHasMask(false);
631 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
632 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
633 Integer bitmap = ipv6Match.getIpv6Exthdr();
634 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
635 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
636 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
637 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
638 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
639 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
640 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
641 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
642 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
643 pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP,
645 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
646 addMaskAugmentation(matchEntriesBuilder, ByteBuffer.allocate(2).putInt(bitmap).array());
647 matchEntriesList.add(matchEntriesBuilder.build());
652 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
653 if (protocolMatchFields != null) {
654 if (protocolMatchFields.getMplsLabel() != null) {
655 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
656 matchEntriesBuilder.setHasMask(false);
657 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
658 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
659 mplsLabelBuilder.setMplsLabel(protocolMatchFields.getMplsLabel());
660 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
661 matchEntriesList.add(matchEntriesBuilder.build());
664 if (protocolMatchFields.getMplsBos() != null) {
665 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
666 matchEntriesBuilder.setHasMask(false);
667 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
668 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
669 if (protocolMatchFields.getMplsBos() != 0) {
670 bosBuilder.setBos(true);
672 bosBuilder.setBos(false);
674 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
675 matchEntriesList.add(matchEntriesBuilder.build());
678 if (protocolMatchFields.getMplsTc() != null) {
679 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
680 matchEntriesBuilder.setHasMask(false);
681 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
682 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
683 tcBuilder.setTc(protocolMatchFields.getMplsTc());
684 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
685 matchEntriesList.add(matchEntriesBuilder.build());
688 if (protocolMatchFields.getPbb() != null) {
689 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
690 matchEntriesBuilder.setHasMask(false);
691 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
692 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
693 isidBuilder.setIsid(protocolMatchFields.getPbb().getPbbIsid());
694 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
695 if (protocolMatchFields.getPbb().getPbbMask() != null) {
696 addMaskAugmentation(matchEntriesBuilder, protocolMatchFields.getPbb().getPbbMask());
698 matchEntriesList.add(matchEntriesBuilder.build());
702 if (match.getTunnel() != null) {
703 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
704 matchEntriesBuilder.setHasMask(false);
705 matchEntriesBuilder.setOxmMatchField(TunnelId.class);
706 addMetadataAugmentation(matchEntriesBuilder, match.getTunnel().getTunnelId());
707 if (match.getTunnel().getTunnelMask() != null) {
708 addMaskAugmentation(matchEntriesBuilder, match.getTunnel().getTunnelMask());
712 return matchEntriesList;
715 private static List<Instructions> toInstructions(
716 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
718 List<Instructions> instructionsList = new ArrayList<>();
719 InstructionsBuilder instructionBuilder = new InstructionsBuilder();
721 for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
723 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction
725 if (curInstruction instanceof GoToTable) {
726 GoToTable goToTable = (GoToTable) curInstruction;
728 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable.class);
729 TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder();
730 tableBuilder.setTableId(goToTable.getTableId());
731 instructionBuilder.addAugmentation(TableIdInstruction.class, tableBuilder.build());
734 else if (curInstruction instanceof WriteMetadata) {
735 WriteMetadata writeMetadata = (WriteMetadata) curInstruction;
737 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class);
738 MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();
739 metadataBuilder.setMetadata(writeMetadata.getMetadata().toByteArray());
740 metadataBuilder.setMetadataMask(writeMetadata.getMetadataMask().toByteArray());
741 instructionBuilder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());
744 else if (curInstruction instanceof WriteActions) {
745 WriteActions writeActions = (WriteActions) curInstruction;
747 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
748 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
749 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(writeActions.getAction(),
751 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
754 else if (curInstruction instanceof ApplyActions) {
755 ApplyActions applyActions = (ApplyActions) curInstruction;
757 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
758 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
759 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(applyActions.getAction(),
761 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
764 else if (curInstruction instanceof ClearActions) {
765 ClearActions clearActions = (ClearActions) curInstruction;
767 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class);
768 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
769 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(clearActions.getAction(),
771 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
774 else if (curInstruction instanceof Meter) {
775 Meter meter = (Meter) curInstruction;
777 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter.class);
778 MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
779 Long meterId = Long.parseLong(meter.getMeter());
780 meterBuilder.setMeterId(meterId);
781 instructionBuilder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
784 instructionsList.add(instructionBuilder.build());
786 return instructionsList;
789 private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
790 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
791 maskBuilder.setMask(mask);
792 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
793 builder.setHasMask(true);
796 private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, Ipv6Address address) {
797 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
798 ipv6AddressBuilder.setIpv6Address(address);
799 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
802 private static void addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
803 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
804 Integer prefix = null;
805 if (addressParts.length == 2) {
806 prefix = Integer.parseInt(addressParts[1]);
809 Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
810 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
811 ipv6AddressBuilder.setIpv6Address(ipv6Address);
812 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
813 if (prefix != null) {
814 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
818 private static byte[] convertIpv6PrefixToByteArray(int prefix) {
819 // TODO: Temporary fix. Has performance impacts.
820 byte[] mask = new byte[16];
821 int oneCount = prefix;
822 for (int count = 0; count < 16; count++) {
826 oneCount = oneCount - 8;
832 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
837 private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
838 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
839 metadataMatchEntry.setMetadata(metadata.toByteArray());
840 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
843 private static void addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
844 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
845 Integer prefix = null;
846 if (addressParts.length < 2) {
849 prefix = Integer.parseInt(addressParts[1]);
852 Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
853 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
854 ipv4AddressBuilder.setIpv4Address(ipv4Address);
855 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
857 int mask = 0xffffffff << (32 - prefix);
858 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
860 addMaskAugmentation(builder, maskBytes);
864 private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
865 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
866 macAddress.setMacAddress(address);
867 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
870 private static void addPortAugmentation(MatchEntriesBuilder builder,
871 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber port) {
872 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
873 portBuilder.setPort(port);
874 builder.addAugmentation(PortMatchEntry.class, portBuilder.build());
878 * Method converts OF SetField Match to SAL SetFiled matches
882 public static SetField ofToSALSetField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
883 logger.info("OF SetField match to SAL SetField match converstion begins");
884 SetFieldBuilder setField = new SetFieldBuilder();
885 /* OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
887 List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
888 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field.MatchBuilder match =new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field.MatchBuilder();
890 EthernetMatchBuilder ethernetMatchBuilder = null;
891 VlanMatchBuilder vlanMatchBuilder = null;
892 IpMatchBuilder ipMatchBuilder = null;
893 TcpMatchBuilder tcpMatchBuilder = null;
894 UdpMatchBuilder udpMatchBuilder = null;
895 SctpMatchBuilder sctpMatchBuilder = null;
896 Icmpv4MatchBuilder icmpv4MatchBuilder = null;
897 Icmpv6MatchBuilder icmpv6MatchBuilder = null;
898 Ipv4MatchBuilder ipv4MatchBuilder = null;
899 ArpMatchBuilder arpMatchBuilder = null;
900 Ipv6MatchBuilder ipv6MatchBuilder = null;
901 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = null;
903 for(MatchEntries matchEntry : matchEntries){
904 if(matchEntry instanceof InPort){
905 PortNumberMatchEntry inPort = matchEntry.getAugmentation(PortNumberMatchEntry.class);
906 match.setInPort(inPort.getPortNumber().getValue());
907 }else if (matchEntry instanceof InPhyPort){
908 PortNumberMatchEntry phyPort = matchEntry.getAugmentation(PortNumberMatchEntry.class);
909 match.setInPhyPort(phyPort.getPortNumber().getValue());
910 }else if (matchEntry instanceof Metadata){
911 MetadataMatchEntry metadataMatch = matchEntry.getAugmentation(MetadataMatchEntry.class);
912 MetadataBuilder metadataBuilder = new MetadataBuilder();
913 metadataBuilder.setMetadata(new BigInteger(metadataMatch.getMetadata()));
914 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
915 if (maskMatch != null){
916 metadataBuilder.setMetadataMask(maskMatch.getMask());
918 match.setMetadata(metadataBuilder.build());
919 }else if (matchEntry instanceof EthDst){
921 if(ethernetMatchBuilder == null)
922 ethernetMatchBuilder = new EthernetMatchBuilder();
924 MacAddressMatchEntry macAddressMatch = matchEntry.getAugmentation(MacAddressMatchEntry.class);
925 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
926 EthernetDestinationBuilder ethernetDestination = new EthernetDestinationBuilder();
927 ethernetDestination.setAddress(macAddressMatch.getMacAddress());
928 if(maskMatch != null){
929 ethernetDestination.setMask(maskMatch.getMask());
931 ethernetMatchBuilder.setEthernetDestination(ethernetDestination.build());
932 }else if (matchEntry instanceof EthSrc){
933 if(ethernetMatchBuilder == null)
934 ethernetMatchBuilder = new EthernetMatchBuilder();
936 MacAddressMatchEntry macAddressMatch = matchEntry.getAugmentation(MacAddressMatchEntry.class);
937 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
938 EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
939 ethernetSource.setAddress(macAddressMatch.getMacAddress());
940 if(maskMatch != null){
941 ethernetSource.setMask(maskMatch.getMask());
943 ethernetMatchBuilder.setEthernetSource(ethernetSource.build());
944 }else if (matchEntry instanceof EthType){
945 if(ethernetMatchBuilder == null)
946 ethernetMatchBuilder = new EthernetMatchBuilder();
948 EthTypeMatchEntry etherTypeMatch = matchEntry.getAugmentation(EthTypeMatchEntry.class);
949 EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
950 org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType etherType = new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long)etherTypeMatch.getEthType().getValue());
951 ethernetType.setType(etherType);
952 ethernetMatchBuilder.setEthernetType(ethernetType.build());
953 }else if (matchEntry instanceof VlanVid){
954 if(vlanMatchBuilder == null)
955 vlanMatchBuilder = new VlanMatchBuilder();
957 VlanVidMatchEntry vlanVidMatch = matchEntry.getAugmentation(VlanVidMatchEntry.class);
958 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
960 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
961 vlanIdBuilder.setVlanId(
962 new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid()));
963 if(maskMatch != null){
964 vlanIdBuilder.setMask(maskMatch.getMask());
966 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
968 }else if (matchEntry instanceof VlanPcp){
969 if(vlanMatchBuilder == null)
970 vlanMatchBuilder = new VlanMatchBuilder();
972 VlanPcpMatchEntry vlanPcpMatch = matchEntry.getAugmentation(VlanPcpMatchEntry.class);
973 vlanMatchBuilder.setVlanPcp(
974 new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp()));
975 }else if (matchEntry instanceof IpDscp){
976 if(ipMatchBuilder == null)
977 ipMatchBuilder = new IpMatchBuilder();
979 DscpMatchEntry dscpMatchEntry = matchEntry.getAugmentation(DscpMatchEntry.class);
980 ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
982 }else if (matchEntry instanceof IpEcn){
983 if(ipMatchBuilder == null)
984 ipMatchBuilder = new IpMatchBuilder();
986 EcnMatchEntry ecnMatchEntry = matchEntry.getAugmentation(EcnMatchEntry.class);
987 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
989 }else if (matchEntry instanceof IpProto){
990 if(ipMatchBuilder == null)
991 ipMatchBuilder = new IpMatchBuilder();
993 ProtocolNumberMatchEntry protocolNumberMatch = matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
994 ipMatchBuilder.setIpProtocol(protocolNumberMatch.getProtocolNumber());
995 }else if (matchEntry instanceof TcpSrc){
996 if(tcpMatchBuilder == null)
997 tcpMatchBuilder = new TcpMatchBuilder();
999 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1000 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
1002 }else if (matchEntry instanceof TcpDst){
1003 if(tcpMatchBuilder == null)
1004 tcpMatchBuilder = new TcpMatchBuilder();
1006 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1007 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
1009 }else if (matchEntry instanceof UdpSrc){
1010 if(udpMatchBuilder == null)
1011 udpMatchBuilder = new UdpMatchBuilder();
1013 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1014 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
1017 }else if (matchEntry instanceof UdpDst){
1018 if(udpMatchBuilder == null)
1019 udpMatchBuilder = new UdpMatchBuilder();
1021 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1022 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
1023 }else if (matchEntry instanceof SctpSrc){
1024 if(sctpMatchBuilder == null)
1025 sctpMatchBuilder = new SctpMatchBuilder();
1027 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1028 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
1030 }else if (matchEntry instanceof SctpDst){
1031 if(sctpMatchBuilder == null)
1032 sctpMatchBuilder = new SctpMatchBuilder();
1034 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1035 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
1036 }else if (matchEntry instanceof Icmpv4Type){
1037 if(icmpv4MatchBuilder == null)
1038 icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1040 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
1041 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
1043 }else if (matchEntry instanceof Icmpv4Code){
1044 if(icmpv4MatchBuilder == null)
1045 icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1047 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
1048 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
1050 }else if (matchEntry instanceof Icmpv6Type){
1051 if(icmpv6MatchBuilder == null)
1052 icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1054 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
1055 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
1056 }else if (matchEntry instanceof Icmpv6Code){
1057 if(icmpv6MatchBuilder == null)
1058 icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1060 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
1061 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
1062 }else if (matchEntry instanceof Ipv4Src){
1063 if(ipv4MatchBuilder == null)
1064 ipv4MatchBuilder = new Ipv4MatchBuilder();
1066 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1067 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1068 ipv4MatchBuilder.setIpv4Source(
1069 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1070 +"/"+new String(maskMatchEntry.getMask())));
1072 }else if (matchEntry instanceof Ipv4Dst){
1073 if(ipv4MatchBuilder == null)
1074 ipv4MatchBuilder = new Ipv4MatchBuilder();
1076 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1077 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1078 ipv4MatchBuilder.setIpv4Destination(
1079 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1080 +"/"+new String(maskMatchEntry.getMask())));
1081 }else if (matchEntry instanceof ArpOp){
1082 if(arpMatchBuilder == null)
1083 arpMatchBuilder = new ArpMatchBuilder();
1085 OpCodeMatchEntry opCodeMatchEntry = matchEntry.getAugmentation(OpCodeMatchEntry.class);
1086 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
1088 }else if (matchEntry instanceof ArpSpa){
1089 if(arpMatchBuilder == null)
1090 arpMatchBuilder = new ArpMatchBuilder();
1092 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1093 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1094 arpMatchBuilder.setArpSourceTransportAddress(
1095 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1096 +"/"+new String(maskMatchEntry.getMask())));
1098 }else if (matchEntry instanceof ArpTpa){
1099 if(arpMatchBuilder == null)
1100 arpMatchBuilder = new ArpMatchBuilder();
1102 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1103 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1104 arpMatchBuilder.setArpTargetTransportAddress(
1105 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1106 +"/"+new String(maskMatchEntry.getMask())));
1108 }else if (matchEntry instanceof ArpSha){
1109 if(arpMatchBuilder == null)
1110 arpMatchBuilder = new ArpMatchBuilder();
1112 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1113 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1114 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
1115 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
1116 arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1117 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
1119 }else if (matchEntry instanceof ArpTha){
1120 if(arpMatchBuilder == null)
1121 arpMatchBuilder = new ArpMatchBuilder();
1123 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1124 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1125 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
1126 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
1127 arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1128 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
1129 }else if (matchEntry instanceof Ipv6Src){
1130 if(ipv6MatchBuilder == null)
1131 ipv6MatchBuilder = new Ipv6MatchBuilder();
1133 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1134 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1135 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix (ipv6AddressMatchEntry.getIpv6Address().getValue()+
1136 "/"+new String(maskMatchEntry.getMask())));
1138 }else if (matchEntry instanceof Ipv6Dst){
1139 if(ipv6MatchBuilder == null)
1140 ipv6MatchBuilder = new Ipv6MatchBuilder();
1142 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1143 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1144 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix (ipv6AddressMatchEntry.getIpv6Address().getValue()+
1145 "/"+new String(maskMatchEntry.getMask())));
1147 }else if (matchEntry instanceof Ipv6Flabel){
1148 if(ipv6MatchBuilder == null)
1149 ipv6MatchBuilder = new Ipv6MatchBuilder();
1151 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
1152 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1153 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
1154 ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
1155 ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
1156 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1158 }else if (matchEntry instanceof Ipv6NdTarget){
1159 if(ipv6MatchBuilder == null)
1160 ipv6MatchBuilder = new Ipv6MatchBuilder();
1161 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1162 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
1164 }else if (matchEntry instanceof Ipv6NdSll){
1165 if(ipv6MatchBuilder == null)
1166 ipv6MatchBuilder = new Ipv6MatchBuilder();
1168 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1169 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
1170 }else if (matchEntry instanceof Ipv6NdTll){
1171 if(ipv6MatchBuilder == null)
1172 ipv6MatchBuilder = new Ipv6MatchBuilder();
1174 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1175 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
1177 }else if (matchEntry instanceof Ipv6Exthdr){
1178 if(ipv6MatchBuilder == null)
1179 ipv6MatchBuilder = new Ipv6MatchBuilder();
1181 PseudoFieldMatchEntry pseudoFieldMatchEntry = matchEntry.getAugmentation(PseudoFieldMatchEntry.class);
1182 PseudoField pseudoField = pseudoFieldMatchEntry.getPseudoField();
1183 int pseudoFieldInt = 0;
1184 pseudoFieldInt |= pseudoField.isNonext()?(1 << 0):~(1 << 0);
1185 pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 << 1);
1186 pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
1187 pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
1188 pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
1189 pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
1190 pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
1191 pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
1192 pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
1194 ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt);
1195 }else if (matchEntry instanceof MplsLabel){
1196 if(protocolMatchFieldsBuilder == null)
1197 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1199 MplsLabelMatchEntry MplsLabelMatchEntry = matchEntry.getAugmentation(MplsLabelMatchEntry.class);
1200 protocolMatchFieldsBuilder.setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
1202 }else if (matchEntry instanceof MplsBos){
1203 if(protocolMatchFieldsBuilder == null)
1204 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1206 BosMatchEntry bosMatchEntry = matchEntry.getAugmentation(BosMatchEntry.class);
1207 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
1209 }else if (matchEntry instanceof MplsTc) {
1210 if(protocolMatchFieldsBuilder == null)
1211 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1213 TcMatchEntry tcMatchEntry = matchEntry.getAugmentation(TcMatchEntry.class);
1214 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
1216 }else if (matchEntry instanceof PbbIsid){
1217 if(protocolMatchFieldsBuilder == null)
1218 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1220 IsidMatchEntry isidMatchEntry = matchEntry.getAugmentation(IsidMatchEntry.class);
1221 PbbBuilder pbbBuilder = new PbbBuilder();
1222 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
1223 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1224 if(maskMatchEntry != null)
1225 pbbBuilder.setPbbMask(maskMatchEntry.getMask());
1227 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
1228 }else if (matchEntry instanceof TunnelId){
1229 MetadataMatchEntry metadataMatchEntry = matchEntry.getAugmentation(MetadataMatchEntry.class);
1230 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1231 TunnelBuilder tunnelBuilder = new TunnelBuilder();
1232 tunnelBuilder.setTunnelId(new BigInteger(metadataMatchEntry.getMetadata()));
1233 tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
1234 match.setTunnel(tunnelBuilder.build());
1237 if(ethernetMatchBuilder != null){
1238 match.setEthernetMatch(ethernetMatchBuilder.build());
1240 if (vlanMatchBuilder != null){
1241 match.setVlanMatch(vlanMatchBuilder.build());
1243 if(ipMatchBuilder != null){
1244 match.setIpMatch(ipMatchBuilder.build());
1246 if(tcpMatchBuilder != null){
1247 match.setLayer4Match(tcpMatchBuilder.build());
1249 if(udpMatchBuilder != null){
1250 match.setLayer4Match(udpMatchBuilder.build());
1252 if(sctpMatchBuilder != null){
1253 match.setLayer4Match(sctpMatchBuilder.build());
1255 if(icmpv4MatchBuilder != null){
1256 match.setIcmpv4Match(icmpv4MatchBuilder.build());
1258 if(icmpv6MatchBuilder != null){
1259 match.setIcmpv6Match(icmpv6MatchBuilder.build());
1261 if(ipv4MatchBuilder != null){
1262 match.setLayer3Match(ipv4MatchBuilder.build());
1264 if(arpMatchBuilder != null){
1265 match.setLayer3Match(arpMatchBuilder.build());
1267 if(ipv6MatchBuilder != null){
1268 match.setLayer3Match(ipv6MatchBuilder.build());
1270 if(protocolMatchFieldsBuilder != null){
1271 match.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1273 setField.setMatch(match.build());
1275 */ return setField.build();