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.ArpTargetHardwareAddress;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6Match;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFields;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstructionBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntry;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntry;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EcnMatchEntryBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntryBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntry;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6FlabelMatchEntryBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntry;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstruction;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataInstructionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntry;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstruction;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntry;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortNumberMatchEntryBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MatchTypeBase;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSha;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpSpa;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTha;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpTpa;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Dst;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv4Src;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Dst;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Flabel;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTarget;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdTll;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Src;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpDst;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.SctpSrc;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TunnelId;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
161 import org.slf4j.Logger;
162 import org.slf4j.LoggerFactory;
165 * Utility class for converting a MD-SAL Flow into the OF flow mod
167 public class FlowConvertor {
168 private static final Logger logger = LoggerFactory.getLogger(FlowConvertor.class);
169 private static final String PREFIX_SEPARATOR = "/";
171 // Default values for when things are null
172 private static final BigInteger DEFAULT_COOKIE = BigInteger.ZERO; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
173 private static final BigInteger DEFAULT_COOKIE_MASK = BigInteger.ZERO; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
174 private static final TableId DEFAULT_TABLE_ID = new TableId(new Long(0)); // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
175 private static final Integer DEFAULT_IDLE_TIMEOUT = new Integer(5*60); // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
176 private static final Integer DEFAULT_HARD_TIMEOUT = new Integer(10*60); // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
177 private static final Integer DEFAULT_PRIORITY = new Integer(100); // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
178 private static final Long DEFAULT_BUFFER_ID = Long.parseLong("ffffffff", 16); // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
179 private static final Long OFPP_ANY = Long.parseLong("ffffffff", 16);
180 private static final Long DEFAULT_OUT_PORT = OFPP_ANY; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
181 private static final Long OFPG_ANY = Long.parseLong("ffffffff", 16);
182 private static final Long DEFAULT_OUT_GROUP = OFPG_ANY; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
183 private static final boolean DEFAULT_OFPFF_FLOW_REM = true; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
184 private static final boolean DEFAULT_OFPFF_CHECK_OVERLAP = false; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
185 private static final boolean DEFAULT_OFPFF_RESET_COUNTS = false; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
186 private static final boolean DEFAULT_OFPFF_NO_PKT_COUNTS = false; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
187 private static final boolean DEFAULT_OFPFF_NO_BYT_COUNTS = false; // TODO: Someone check me, I have no idea if this is a good default - eaw@cisco.com
188 private static final Class<? extends MatchTypeBase> DEFAULT_MATCH_TYPE = OxmMatchType.class;
190 public static FlowModInput toFlowModInput(Flow flow, short version) {
191 FlowModInputBuilder flowMod = new FlowModInputBuilder();
192 if(flow.getCookie() != null){
193 flowMod.setCookie(flow.getCookie());
195 flowMod.setCookie(DEFAULT_COOKIE);
198 if (flow.getCookieMask() != null) {
199 flowMod.setCookieMask(new BigInteger(flow.getCookieMask().toString()));
201 flowMod.setCookieMask(DEFAULT_COOKIE_MASK);
204 if (flow.getTableId() != null) {
205 flowMod.setTableId(new TableId(flow.getTableId().longValue()));
207 flowMod.setTableId(DEFAULT_TABLE_ID);
210 if (flow instanceof AddFlowInput) {
211 flowMod.setCommand(FlowModCommand.OFPFCADD);
212 } else if (flow instanceof RemoveFlowInput) {
213 if (flow.isStrict()) {
214 flowMod.setCommand(FlowModCommand.OFPFCDELETESTRICT);
216 flowMod.setCommand(FlowModCommand.OFPFCDELETE);
218 } else if (flow instanceof UpdateFlowInput) {
219 if (flow.isStrict()) {
220 flowMod.setCommand(FlowModCommand.OFPFCMODIFYSTRICT);
222 flowMod.setCommand(FlowModCommand.OFPFCMODIFY);
225 if(flow.getIdleTimeout() != null) {
226 flowMod.setIdleTimeout(flow.getIdleTimeout());
228 flowMod.setIdleTimeout(DEFAULT_IDLE_TIMEOUT);
230 if(flow.getHardTimeout() != null) {
231 flowMod.setHardTimeout(flow.getHardTimeout());
233 flowMod.setHardTimeout(DEFAULT_HARD_TIMEOUT);
235 if(flow.getPriority() != null) {
236 flowMod.setPriority(flow.getPriority());
238 flowMod.setPriority(DEFAULT_PRIORITY);
240 if(flow.getBufferId() != null ) {
241 flowMod.setBufferId(flow.getBufferId());
243 flowMod.setBufferId(DEFAULT_BUFFER_ID);
246 if (flow.getOutPort() != null) {
247 flowMod.setOutPort(new PortNumber(flow.getOutPort().longValue()));
249 flowMod.setOutPort(new PortNumber(DEFAULT_OUT_PORT));
251 if(flow.getOutGroup() != null) {
252 flowMod.setOutGroup(flow.getOutGroup());
254 flowMod.setOutGroup(DEFAULT_OUT_GROUP);
257 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags flowModFlags = flow.getFlags();
258 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags ofFlowModFlags = null;
259 if (flowModFlags != null) {
260 ofFlowModFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags(
261 flowModFlags.isCHECKOVERLAP(), flowModFlags.isNOBYTCOUNTS(), flowModFlags.isNOPKTCOUNTS(),
262 flowModFlags.isRESETCOUNTS(), flowModFlags.isSENDFLOWREM());
264 ofFlowModFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags(
265 DEFAULT_OFPFF_CHECK_OVERLAP,DEFAULT_OFPFF_NO_BYT_COUNTS,DEFAULT_OFPFF_NO_PKT_COUNTS,
266 DEFAULT_OFPFF_RESET_COUNTS,DEFAULT_OFPFF_FLOW_REM);
268 flowMod.setFlags(ofFlowModFlags);
270 if (flow.getMatch() != null) {
271 MatchBuilder matchBuilder = new MatchBuilder();
272 matchBuilder.setMatchEntries(toMatch(flow.getMatch()));
273 matchBuilder.setType(DEFAULT_MATCH_TYPE);
274 flowMod.setMatch(matchBuilder.build());
277 if (flow.getInstructions() != null) {
278 flowMod.setInstructions(toInstructions(flow.getInstructions(), version));
280 flowMod.setVersion(version);
281 return flowMod.build();
284 public static List<MatchEntries> toMatch(
285 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) {
287 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
288 List<MatchEntries> matchEntriesList = new ArrayList<>();
290 if (match.getInPort() != null) {
291 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
292 matchEntriesBuilder.setHasMask(false);
293 matchEntriesBuilder.setOxmMatchField(InPort.class);
294 PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
295 port.setPortNumber(new PortNumber(match.getInPort()));
296 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
297 matchEntriesList.add(matchEntriesBuilder.build());
300 if (match.getInPhyPort() != null) {
301 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
302 matchEntriesBuilder.setHasMask(false);
303 matchEntriesBuilder.setOxmMatchField(InPhyPort.class);
304 PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();
305 phyPort.setPortNumber(new PortNumber(match.getInPhyPort()));
306 matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());
307 matchEntriesList.add(matchEntriesBuilder.build());
310 if (match.getMetadata() != null) {
311 boolean hasmask = false;
312 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
313 matchEntriesBuilder.setOxmMatchField(Metadata.class);
314 addMetadataAugmentation(matchEntriesBuilder, match.getMetadata().getMetadata());
315 if (match.getMetadata().getMetadataMask() != null) {
317 addMaskAugmentation(matchEntriesBuilder, match.getMetadata().getMetadataMask());
319 matchEntriesBuilder.setHasMask(hasmask);
320 matchEntriesList.add(matchEntriesBuilder.build());
323 if (match.getEthernetMatch() != null) {
324 EthernetMatch ethernetMatch = match.getEthernetMatch();
325 EthernetDestination ethernetDestination = ethernetMatch.getEthernetDestination();
326 if (ethernetDestination != null) {
327 boolean hasmask = false;
328 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
329 matchEntriesBuilder.setOxmMatchField(EthDst.class);
330 addMacAddressAugmentation(matchEntriesBuilder, ethernetDestination.getAddress());
331 if (ethernetDestination.getMask() != null) {
333 addMaskAugmentation(matchEntriesBuilder, ethernetDestination.getMask());
335 matchEntriesBuilder.setHasMask(hasmask);
336 matchEntriesList.add(matchEntriesBuilder.build());
339 EthernetSource ethernetSource = ethernetMatch.getEthernetSource();
340 if (ethernetSource != null) {
341 boolean hasmask = false;
342 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
343 matchEntriesBuilder.setOxmMatchField(EthSrc.class);
344 addMacAddressAugmentation(matchEntriesBuilder, ethernetSource.getAddress());
345 if (ethernetSource.getMask() != null) {
347 addMaskAugmentation(matchEntriesBuilder, ethernetSource.getMask());
349 matchEntriesBuilder.setHasMask(hasmask);
350 matchEntriesList.add(matchEntriesBuilder.build());
353 if (ethernetMatch.getEthernetType() != null) {
354 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
355 matchEntriesBuilder.setHasMask(false);
356 matchEntriesBuilder.setOxmMatchField(EthType.class);
357 EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
358 ethertypeBuilder.setEthType(new EtherType(ethernetMatch.getEthernetType().getType().getValue()
360 matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
361 matchEntriesList.add(matchEntriesBuilder.build());
365 VlanMatch vlanMatch = match.getVlanMatch();
366 if (vlanMatch != null) {
367 if (vlanMatch.getVlanId() != null) {
369 boolean hasmask = false;
370 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
371 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
372 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
373 Integer vidEntryValue = vlanMatch.getVlanId().getVlanId().getValue();
374 vlanVidBuilder.setCfiBit(vidEntryValue != 0);
375 vlanVidBuilder.setVlanVid(vidEntryValue);
376 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
377 if (vlanMatch.getVlanId().getMask() != null) {
379 addMaskAugmentation(matchEntriesBuilder, vlanMatch.getVlanId().getMask());
381 matchEntriesBuilder.setHasMask(hasmask);
382 matchEntriesList.add(matchEntriesBuilder.build());
385 if (vlanMatch.getVlanPcp() != null) {
386 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
387 matchEntriesBuilder.setHasMask(false);
388 matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
389 VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
390 vlanPcpBuilder.setVlanPcp(vlanMatch.getVlanPcp().getValue());
391 matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
392 matchEntriesList.add(matchEntriesBuilder.build());
396 IpMatch ipMatch = match.getIpMatch();
397 if (ipMatch != null) {
398 if (ipMatch.getIpDscp() != null) {
399 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
400 matchEntriesBuilder.setHasMask(false);
401 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
402 DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
403 dscpBuilder.setDscp(ipMatch.getIpDscp());
404 matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
405 matchEntriesList.add(matchEntriesBuilder.build());
408 if (ipMatch.getIpEcn() != null) {
409 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
410 matchEntriesBuilder.setHasMask(false);
411 matchEntriesBuilder.setOxmMatchField(IpDscp.class);
412 EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
413 ecnBuilder.setEcn(ipMatch.getIpEcn());
414 matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
415 matchEntriesList.add(matchEntriesBuilder.build());
418 if (ipMatch.getIpProto() != null) {
419 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
420 matchEntriesBuilder.setHasMask(false);
421 matchEntriesBuilder.setOxmMatchField(IpProto.class);
422 ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
423 protoNumberBuilder.setProtocolNumber((short) ipMatch.getIpProto().getIntValue());
424 matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
425 matchEntriesList.add(matchEntriesBuilder.build());
430 Layer4Match layer4Match = match.getLayer4Match();
431 if (layer4Match != null) {
432 if (layer4Match instanceof TcpMatch) {
433 TcpMatch tcpMatch = (TcpMatch) layer4Match;
434 if (tcpMatch.getTcpSourcePort() != null) {
435 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
436 matchEntriesBuilder.setHasMask(false);
437 matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
438 addPortAugmentation(matchEntriesBuilder, tcpMatch.getTcpSourcePort());
439 matchEntriesList.add(matchEntriesBuilder.build());
442 if (tcpMatch.getTcpDestinationPort() != null) {
443 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
444 matchEntriesBuilder.setHasMask(false);
445 matchEntriesBuilder.setOxmMatchField(TcpDst.class);
446 addPortAugmentation(matchEntriesBuilder, tcpMatch.getTcpDestinationPort());
447 matchEntriesList.add(matchEntriesBuilder.build());
451 else if (layer4Match instanceof UdpMatch) {
452 UdpMatch udpMatch = (UdpMatch) layer4Match;
453 if (udpMatch.getUdpSourcePort() != null) {
454 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
455 matchEntriesBuilder.setHasMask(false);
456 matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
457 addPortAugmentation(matchEntriesBuilder, udpMatch.getUdpSourcePort());
458 matchEntriesList.add(matchEntriesBuilder.build());
461 if (udpMatch.getUdpDestinationPort() != null) {
462 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
463 matchEntriesBuilder.setHasMask(false);
464 matchEntriesBuilder.setOxmMatchField(UdpDst.class);
465 addPortAugmentation(matchEntriesBuilder, udpMatch.getUdpDestinationPort());
466 matchEntriesList.add(matchEntriesBuilder.build());
470 else if (layer4Match instanceof SctpMatch) {
471 SctpMatch sctpMatch = (SctpMatch) layer4Match;
472 if (sctpMatch.getSctpSourcePort() != null) {
473 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
474 matchEntriesBuilder.setHasMask(false);
475 matchEntriesBuilder.setOxmMatchField(SctpSrc.class);
476 addPortAugmentation(matchEntriesBuilder, sctpMatch.getSctpSourcePort());
477 matchEntriesList.add(matchEntriesBuilder.build());
480 if (sctpMatch.getSctpDestinationPort() != null) {
481 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
482 matchEntriesBuilder.setHasMask(false);
483 matchEntriesBuilder.setOxmMatchField(SctpDst.class);
484 addPortAugmentation(matchEntriesBuilder, sctpMatch.getSctpDestinationPort());
485 matchEntriesList.add(matchEntriesBuilder.build());
490 Icmpv4Match icmpv4Match = match.getIcmpv4Match();
491 if (icmpv4Match != null) {
492 if (icmpv4Match.getIcmpv4Type() != null) {
493 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
494 matchEntriesBuilder.setHasMask(false);
495 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
496 Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
497 icmpv4TypeBuilder.setIcmpv4Type(icmpv4Match.getIcmpv4Type());
498 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
499 matchEntriesList.add(matchEntriesBuilder.build());
502 if (icmpv4Match.getIcmpv4Code() != null) {
503 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
504 matchEntriesBuilder.setHasMask(false);
505 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
506 Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
507 icmpv4CodeBuilder.setIcmpv4Code(icmpv4Match.getIcmpv4Code());
508 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
509 matchEntriesList.add(matchEntriesBuilder.build());
513 Icmpv6Match icmpv6Match = match.getIcmpv6Match();
514 if (icmpv6Match != null) {
515 if (icmpv6Match.getIcmpv6Type() != null) {
516 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
517 matchEntriesBuilder.setHasMask(false);
518 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
519 Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
520 icmpv6TypeBuilder.setIcmpv6Type(icmpv6Match.getIcmpv6Type());
521 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
522 matchEntriesList.add(matchEntriesBuilder.build());
525 if (icmpv6Match.getIcmpv6Code() != null) {
526 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
527 matchEntriesBuilder.setHasMask(false);
528 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
529 Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
530 icmpv6CodeBuilder.setIcmpv6Code(icmpv6Match.getIcmpv6Code());
531 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
532 matchEntriesList.add(matchEntriesBuilder.build());
536 Layer3Match layer3Match = match.getLayer3Match();
537 if (layer3Match != null) {
538 if (layer3Match instanceof Ipv4Match) {
539 Ipv4Match ipv4Match = (Ipv4Match) layer3Match;
540 if (ipv4Match.getIpv4Source() != null) {
541 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
542 matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);
543 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Match.getIpv4Source());
544 matchEntriesBuilder.setHasMask(hasMask);
545 matchEntriesList.add(matchEntriesBuilder.build());
547 if (ipv4Match.getIpv4Destination() != null) {
548 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
549 matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);
550 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, ipv4Match.getIpv4Destination());
551 matchEntriesBuilder.setHasMask(hasMask);
552 matchEntriesList.add(matchEntriesBuilder.build());
556 else if (layer3Match instanceof ArpMatch) {
557 ArpMatch arpMatch = (ArpMatch) layer3Match;
558 if (arpMatch.getArpOp() != null) {
559 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
560 matchEntriesBuilder.setHasMask(false);
561 matchEntriesBuilder.setOxmMatchField(ArpOp.class);
562 OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
563 opcodeBuilder.setOpCode(arpMatch.getArpOp());
564 matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
565 matchEntriesList.add(matchEntriesBuilder.build());
568 if (arpMatch.getArpSourceTransportAddress() != null) {
569 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
570 matchEntriesBuilder.setOxmMatchField(ArpSpa.class);
571 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, arpMatch.getArpSourceTransportAddress());
572 matchEntriesBuilder.setHasMask(hasMask);
573 matchEntriesList.add(matchEntriesBuilder.build());
576 if (arpMatch.getArpTargetTransportAddress() != null) {
577 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
578 matchEntriesBuilder.setOxmMatchField(ArpTpa.class);
579 boolean hasMask = addIpv4PrefixAugmentation(matchEntriesBuilder, arpMatch.getArpTargetTransportAddress());
580 matchEntriesBuilder.setHasMask(hasMask);
581 matchEntriesList.add(matchEntriesBuilder.build());
584 ArpSourceHardwareAddress arpSourceHardwareAddress = arpMatch.getArpSourceHardwareAddress();
585 if (arpSourceHardwareAddress != null) {
586 boolean hasmask = false;
587 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
588 matchEntriesBuilder.setOxmMatchField(ArpSha.class);
589 addMacAddressAugmentation(matchEntriesBuilder, arpSourceHardwareAddress.getAddress());
590 if (arpSourceHardwareAddress.getMask() != null) {
592 addMaskAugmentation(matchEntriesBuilder, arpSourceHardwareAddress.getMask());
594 matchEntriesBuilder.setHasMask(hasmask);
595 matchEntriesList.add(matchEntriesBuilder.build());
598 ArpTargetHardwareAddress arpTargetHardwareAddress = arpMatch.getArpTargetHardwareAddress();
599 if (arpTargetHardwareAddress != null) {
600 boolean hasmask = false;
601 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
602 matchEntriesBuilder.setOxmMatchField(ArpTha.class);
603 addMacAddressAugmentation(matchEntriesBuilder, arpTargetHardwareAddress.getAddress());
604 if (arpTargetHardwareAddress.getMask() != null) {
606 addMaskAugmentation(matchEntriesBuilder, arpTargetHardwareAddress.getMask());
608 matchEntriesBuilder.setHasMask(hasmask);
609 matchEntriesList.add(matchEntriesBuilder.build());
613 else if (layer3Match instanceof Ipv6Match) {
614 Ipv6Match ipv6Match = (Ipv6Match) layer3Match;
615 if (ipv6Match.getIpv6Source() != null) {
616 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
617 matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);
618 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Source());
619 matchEntriesBuilder.setHasMask(hasmask);
620 matchEntriesList.add(matchEntriesBuilder.build());
623 if (ipv6Match.getIpv6Destination() != null) {
624 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
625 matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);
626 boolean hasmask = addIpv6PrefixAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Destination());
627 matchEntriesBuilder.setHasMask(hasmask);
628 matchEntriesList.add(matchEntriesBuilder.build());
631 if (ipv6Match.getIpv6Label() != null) {
632 boolean hasmask = false;
633 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
634 matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
635 Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
636 ipv6FlabelBuilder.setIpv6Flabel(ipv6Match.getIpv6Label().getIpv6Flabel());
637 matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
638 if (ipv6Match.getIpv6Label().getFlabelMask() != null) {
640 addMaskAugmentation(matchEntriesBuilder, ipv6Match.getIpv6Label().getFlabelMask());
642 matchEntriesBuilder.setHasMask(hasmask);
643 matchEntriesList.add(matchEntriesBuilder.build());
646 if (ipv6Match.getIpv6NdTarget() != null) {
647 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
648 matchEntriesBuilder.setHasMask(false);
649 matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
650 addIpv6AddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdTarget());
651 matchEntriesList.add(matchEntriesBuilder.build());
654 if (ipv6Match.getIpv6NdSll() != null) {
655 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
656 matchEntriesBuilder.setHasMask(false);
657 matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class);
658 addMacAddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdSll());
659 matchEntriesList.add(matchEntriesBuilder.build());
662 if (ipv6Match.getIpv6NdTll() != null) {
663 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
664 matchEntriesBuilder.setHasMask(false);
665 matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class);
666 addMacAddressAugmentation(matchEntriesBuilder, ipv6Match.getIpv6NdTll());
667 matchEntriesList.add(matchEntriesBuilder.build());
670 if (ipv6Match.getIpv6Exthdr() != null) {
672 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
673 matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
674 PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
675 Integer bitmap = ipv6Match.getIpv6Exthdr();
676 final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
677 final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
678 final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
679 final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
680 final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
681 final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
682 final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
683 final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
684 final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
685 pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP,
687 matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
688 addMaskAugmentation(matchEntriesBuilder, ByteBuffer.allocate(2).putInt(bitmap).array());
689 matchEntriesBuilder.setHasMask(false);
690 matchEntriesList.add(matchEntriesBuilder.build());
695 ProtocolMatchFields protocolMatchFields = match.getProtocolMatchFields();
696 if (protocolMatchFields != null) {
697 if (protocolMatchFields.getMplsLabel() != null) {
698 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
699 matchEntriesBuilder.setHasMask(false);
700 matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
701 MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
702 mplsLabelBuilder.setMplsLabel(protocolMatchFields.getMplsLabel());
703 matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
704 matchEntriesList.add(matchEntriesBuilder.build());
707 if (protocolMatchFields.getMplsBos() != null) {
708 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
709 matchEntriesBuilder.setHasMask(false);
710 matchEntriesBuilder.setOxmMatchField(MplsBos.class);
711 BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
712 if (protocolMatchFields.getMplsBos() != 0) {
713 bosBuilder.setBos(true);
715 bosBuilder.setBos(false);
717 matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
718 matchEntriesList.add(matchEntriesBuilder.build());
721 if (protocolMatchFields.getMplsTc() != null) {
722 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
723 matchEntriesBuilder.setHasMask(false);
724 matchEntriesBuilder.setOxmMatchField(MplsTc.class);
725 TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
726 tcBuilder.setTc(protocolMatchFields.getMplsTc());
727 matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
728 matchEntriesList.add(matchEntriesBuilder.build());
731 if (protocolMatchFields.getPbb() != null) {
732 boolean hasmask = false;
733 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
734 matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
735 IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
736 isidBuilder.setIsid(protocolMatchFields.getPbb().getPbbIsid());
737 matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
738 if (protocolMatchFields.getPbb().getPbbMask() != null) {
740 addMaskAugmentation(matchEntriesBuilder, protocolMatchFields.getPbb().getPbbMask());
742 matchEntriesBuilder.setHasMask(hasmask);
743 matchEntriesList.add(matchEntriesBuilder.build());
747 if (match.getTunnel() != null) {
748 boolean hasmask = false;
749 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
750 matchEntriesBuilder.setOxmMatchField(TunnelId.class);
751 addMetadataAugmentation(matchEntriesBuilder, match.getTunnel().getTunnelId());
752 if (match.getTunnel().getTunnelMask() != null) {
754 addMaskAugmentation(matchEntriesBuilder, match.getTunnel().getTunnelMask());
756 matchEntriesBuilder.setHasMask(false);
757 matchEntriesList.add(matchEntriesBuilder.build());
760 return matchEntriesList;
763 private static List<Instructions> toInstructions(
764 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
766 List<Instructions> instructionsList = new ArrayList<>();
768 for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
770 InstructionsBuilder instructionBuilder = new InstructionsBuilder();
771 org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction
773 if (curInstruction instanceof GoToTable) {
774 GoToTable goToTable = (GoToTable) curInstruction;
776 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable.class);
777 TableIdInstructionBuilder tableBuilder = new TableIdInstructionBuilder();
778 tableBuilder.setTableId(goToTable.getTableId());
779 instructionBuilder.addAugmentation(TableIdInstruction.class, tableBuilder.build());
780 instructionsList.add(instructionBuilder.build());
783 else if (curInstruction instanceof WriteMetadata) {
784 WriteMetadata writeMetadata = (WriteMetadata) curInstruction;
786 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata.class);
787 MetadataInstructionBuilder metadataBuilder = new MetadataInstructionBuilder();
788 metadataBuilder.setMetadata(writeMetadata.getMetadata().toByteArray());
789 metadataBuilder.setMetadataMask(writeMetadata.getMetadataMask().toByteArray());
790 instructionBuilder.addAugmentation(MetadataInstruction.class, metadataBuilder.build());
791 instructionsList.add(instructionBuilder.build());
794 else if (curInstruction instanceof WriteActions) {
795 WriteActions writeActions = (WriteActions) curInstruction;
797 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
798 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
799 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(writeActions.getAction(),
801 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
802 instructionsList.add(instructionBuilder.build());
805 else if (curInstruction instanceof ApplyActions) {
806 ApplyActions applyActions = (ApplyActions) curInstruction;
808 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
809 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
810 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(applyActions.getAction(),
812 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
813 instructionsList.add(instructionBuilder.build());
816 else if (curInstruction instanceof ClearActions) {
817 ClearActions clearActions = (ClearActions) curInstruction;
819 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class);
820 ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
821 actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(clearActions.getAction(),
823 instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
824 instructionsList.add(instructionBuilder.build());
827 else if (curInstruction instanceof Meter) {
828 Meter meter = (Meter) curInstruction;
830 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter.class);
831 MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
832 Long meterId = Long.parseLong(meter.getMeter());
833 meterBuilder.setMeterId(meterId);
834 instructionBuilder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
835 instructionsList.add(instructionBuilder.build());
838 return instructionsList;
841 private static void addMaskAugmentation(MatchEntriesBuilder builder, byte[] mask) {
842 MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
843 maskBuilder.setMask(mask);
844 builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
845 builder.setHasMask(true);
848 private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, Ipv6Address address) {
849 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
850 ipv6AddressBuilder.setIpv6Address(address);
851 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
854 private static boolean addIpv6PrefixAugmentation(MatchEntriesBuilder builder, Ipv6Prefix address) {
855 boolean hasMask = false;
856 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
857 Integer prefix = null;
858 if (addressParts.length == 2) {
859 prefix = Integer.parseInt(addressParts[1]);
862 Ipv6Address ipv6Address = new Ipv6Address(addressParts[0]);
863 Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
864 ipv6AddressBuilder.setIpv6Address(ipv6Address);
865 builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
866 if (prefix != null) {
868 addMaskAugmentation(builder, convertIpv6PrefixToByteArray(prefix));
873 private static byte[] convertIpv6PrefixToByteArray(int prefix) {
874 // TODO: Temporary fix. Has performance impacts.
875 byte[] mask = new byte[16];
876 int oneCount = prefix;
877 for (int count = 0; count < 16; count++) {
881 oneCount = oneCount - 8;
887 mask[count] = (byte) (256 - Math.pow(2, 8 - byteBits));
892 private static void addMetadataAugmentation(MatchEntriesBuilder builder, BigInteger metadata) {
893 MetadataMatchEntryBuilder metadataMatchEntry = new MetadataMatchEntryBuilder();
894 metadataMatchEntry.setMetadata(metadata.toByteArray());
895 builder.addAugmentation(MetadataMatchEntry.class, metadataMatchEntry.build());
899 * @return true if Ipv4Prefix contains prefix (and it is used in mask), false otherwise
901 private static boolean addIpv4PrefixAugmentation(MatchEntriesBuilder builder, Ipv4Prefix address) {
902 boolean hasMask = false;
903 String[] addressParts = address.getValue().split(PREFIX_SEPARATOR);
904 Integer prefix = null;
905 if (addressParts.length < 2) {
908 prefix = Integer.parseInt(addressParts[1]);
911 Ipv4Address ipv4Address = new Ipv4Address(addressParts[0]);
912 Ipv4AddressMatchEntryBuilder ipv4AddressBuilder = new Ipv4AddressMatchEntryBuilder();
913 ipv4AddressBuilder.setIpv4Address(ipv4Address);
914 builder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4AddressBuilder.build());
916 int mask = 0xffffffff << (32 - prefix);
917 byte[] maskBytes = new byte[] { (byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8),
919 addMaskAugmentation(builder, maskBytes);
925 private static void addMacAddressAugmentation(MatchEntriesBuilder builder, MacAddress address) {
926 MacAddressMatchEntryBuilder macAddress = new MacAddressMatchEntryBuilder();
927 macAddress.setMacAddress(address);
928 builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
931 private static void addPortAugmentation(MatchEntriesBuilder builder,
932 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber port) {
933 PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
934 portBuilder.setPort(port);
935 builder.addAugmentation(PortMatchEntry.class, portBuilder.build());
939 * Method converts OF SetField Match to SAL SetFiled matches
943 public static SetField ofToSALSetField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action action) {
944 logger.info("OF SetField match to SAL SetField match converstion begins");
945 SetFieldBuilder setField = new SetFieldBuilder();
946 /* OxmFieldsAction oxmFields = action.getAugmentation(OxmFieldsAction.class);
948 List<MatchEntries> matchEntries = oxmFields.getMatchEntries();
949 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();
951 EthernetMatchBuilder ethernetMatchBuilder = null;
952 VlanMatchBuilder vlanMatchBuilder = null;
953 IpMatchBuilder ipMatchBuilder = null;
954 TcpMatchBuilder tcpMatchBuilder = null;
955 UdpMatchBuilder udpMatchBuilder = null;
956 SctpMatchBuilder sctpMatchBuilder = null;
957 Icmpv4MatchBuilder icmpv4MatchBuilder = null;
958 Icmpv6MatchBuilder icmpv6MatchBuilder = null;
959 Ipv4MatchBuilder ipv4MatchBuilder = null;
960 ArpMatchBuilder arpMatchBuilder = null;
961 Ipv6MatchBuilder ipv6MatchBuilder = null;
962 ProtocolMatchFieldsBuilder protocolMatchFieldsBuilder = null;
964 for(MatchEntries matchEntry : matchEntries){
965 if(matchEntry instanceof InPort){
966 PortNumberMatchEntry inPort = matchEntry.getAugmentation(PortNumberMatchEntry.class);
967 match.setInPort(inPort.getPortNumber().getValue());
968 }else if (matchEntry instanceof InPhyPort){
969 PortNumberMatchEntry phyPort = matchEntry.getAugmentation(PortNumberMatchEntry.class);
970 match.setInPhyPort(phyPort.getPortNumber().getValue());
971 }else if (matchEntry instanceof Metadata){
972 MetadataMatchEntry metadataMatch = matchEntry.getAugmentation(MetadataMatchEntry.class);
973 MetadataBuilder metadataBuilder = new MetadataBuilder();
974 metadataBuilder.setMetadata(new BigInteger(metadataMatch.getMetadata()));
975 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
976 if (maskMatch != null){
977 metadataBuilder.setMetadataMask(maskMatch.getMask());
979 match.setMetadata(metadataBuilder.build());
980 }else if (matchEntry instanceof EthDst){
982 if(ethernetMatchBuilder == null)
983 ethernetMatchBuilder = new EthernetMatchBuilder();
985 MacAddressMatchEntry macAddressMatch = matchEntry.getAugmentation(MacAddressMatchEntry.class);
986 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
987 EthernetDestinationBuilder ethernetDestination = new EthernetDestinationBuilder();
988 ethernetDestination.setAddress(macAddressMatch.getMacAddress());
989 if(maskMatch != null){
990 ethernetDestination.setMask(maskMatch.getMask());
992 ethernetMatchBuilder.setEthernetDestination(ethernetDestination.build());
993 }else if (matchEntry instanceof EthSrc){
994 if(ethernetMatchBuilder == null)
995 ethernetMatchBuilder = new EthernetMatchBuilder();
997 MacAddressMatchEntry macAddressMatch = matchEntry.getAugmentation(MacAddressMatchEntry.class);
998 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
999 EthernetSourceBuilder ethernetSource = new EthernetSourceBuilder();
1000 ethernetSource.setAddress(macAddressMatch.getMacAddress());
1001 if(maskMatch != null){
1002 ethernetSource.setMask(maskMatch.getMask());
1004 ethernetMatchBuilder.setEthernetSource(ethernetSource.build());
1005 }else if (matchEntry instanceof EthType){
1006 if(ethernetMatchBuilder == null)
1007 ethernetMatchBuilder = new EthernetMatchBuilder();
1009 EthTypeMatchEntry etherTypeMatch = matchEntry.getAugmentation(EthTypeMatchEntry.class);
1010 EthernetTypeBuilder ethernetType= new EthernetTypeBuilder();
1011 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());
1012 ethernetType.setType(etherType);
1013 ethernetMatchBuilder.setEthernetType(ethernetType.build());
1014 }else if (matchEntry instanceof VlanVid){
1015 if(vlanMatchBuilder == null)
1016 vlanMatchBuilder = new VlanMatchBuilder();
1018 VlanVidMatchEntry vlanVidMatch = matchEntry.getAugmentation(VlanVidMatchEntry.class);
1019 MaskMatchEntry maskMatch = matchEntry.getAugmentation(MaskMatchEntry.class);
1021 VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
1022 vlanIdBuilder.setVlanId(
1023 new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanVidMatch.getVlanVid()));
1024 if(maskMatch != null){
1025 vlanIdBuilder.setMask(maskMatch.getMask());
1027 vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
1029 }else if (matchEntry instanceof VlanPcp){
1030 if(vlanMatchBuilder == null)
1031 vlanMatchBuilder = new VlanMatchBuilder();
1033 VlanPcpMatchEntry vlanPcpMatch = matchEntry.getAugmentation(VlanPcpMatchEntry.class);
1034 vlanMatchBuilder.setVlanPcp(
1035 new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(vlanPcpMatch.getVlanPcp()));
1036 }else if (matchEntry instanceof IpDscp){
1037 if(ipMatchBuilder == null)
1038 ipMatchBuilder = new IpMatchBuilder();
1040 DscpMatchEntry dscpMatchEntry = matchEntry.getAugmentation(DscpMatchEntry.class);
1041 ipMatchBuilder.setIpDscp(dscpMatchEntry.getDscp());
1043 }else if (matchEntry instanceof IpEcn){
1044 if(ipMatchBuilder == null)
1045 ipMatchBuilder = new IpMatchBuilder();
1047 EcnMatchEntry ecnMatchEntry = matchEntry.getAugmentation(EcnMatchEntry.class);
1048 ipMatchBuilder.setIpEcn(ecnMatchEntry.getEcn());
1050 }else if (matchEntry instanceof IpProto){
1051 if(ipMatchBuilder == null)
1052 ipMatchBuilder = new IpMatchBuilder();
1054 ProtocolNumberMatchEntry protocolNumberMatch = matchEntry.getAugmentation(ProtocolNumberMatchEntry.class);
1055 ipMatchBuilder.setIpProtocol(protocolNumberMatch.getProtocolNumber());
1056 }else if (matchEntry instanceof TcpSrc){
1057 if(tcpMatchBuilder == null)
1058 tcpMatchBuilder = new TcpMatchBuilder();
1060 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1061 tcpMatchBuilder.setTcpSourcePort(portMatchEntry.getPort());
1063 }else if (matchEntry instanceof TcpDst){
1064 if(tcpMatchBuilder == null)
1065 tcpMatchBuilder = new TcpMatchBuilder();
1067 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1068 tcpMatchBuilder.setTcpDestinationPort(portMatchEntry.getPort());
1070 }else if (matchEntry instanceof UdpSrc){
1071 if(udpMatchBuilder == null)
1072 udpMatchBuilder = new UdpMatchBuilder();
1074 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1075 udpMatchBuilder.setUdpSourcePort(portMatchEntry.getPort());
1078 }else if (matchEntry instanceof UdpDst){
1079 if(udpMatchBuilder == null)
1080 udpMatchBuilder = new UdpMatchBuilder();
1082 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1083 udpMatchBuilder.setUdpDestinationPort(portMatchEntry.getPort());
1084 }else if (matchEntry instanceof SctpSrc){
1085 if(sctpMatchBuilder == null)
1086 sctpMatchBuilder = new SctpMatchBuilder();
1088 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1089 sctpMatchBuilder.setSctpSourcePort(portMatchEntry.getPort());
1091 }else if (matchEntry instanceof SctpDst){
1092 if(sctpMatchBuilder == null)
1093 sctpMatchBuilder = new SctpMatchBuilder();
1095 PortMatchEntry portMatchEntry = matchEntry.getAugmentation(PortMatchEntry.class);
1096 sctpMatchBuilder.setSctpDestinationPort(portMatchEntry.getPort());
1097 }else if (matchEntry instanceof Icmpv4Type){
1098 if(icmpv4MatchBuilder == null)
1099 icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1101 Icmpv4TypeMatchEntry icmpv4TypeMatchEntry = matchEntry.getAugmentation(Icmpv4TypeMatchEntry.class);
1102 icmpv4MatchBuilder.setIcmpv4Type(icmpv4TypeMatchEntry.getIcmpv4Type());
1104 }else if (matchEntry instanceof Icmpv4Code){
1105 if(icmpv4MatchBuilder == null)
1106 icmpv4MatchBuilder = new Icmpv4MatchBuilder();
1108 Icmpv4CodeMatchEntry icmpv4CodeMatchEntry = matchEntry.getAugmentation(Icmpv4CodeMatchEntry.class);
1109 icmpv4MatchBuilder.setIcmpv4Code(icmpv4CodeMatchEntry.getIcmpv4Code());
1111 }else if (matchEntry instanceof Icmpv6Type){
1112 if(icmpv6MatchBuilder == null)
1113 icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1115 Icmpv6TypeMatchEntry icmpv6TypeMatchEntry = matchEntry.getAugmentation(Icmpv6TypeMatchEntry.class);
1116 icmpv6MatchBuilder.setIcmpv6Type(icmpv6TypeMatchEntry.getIcmpv6Type());
1117 }else if (matchEntry instanceof Icmpv6Code){
1118 if(icmpv6MatchBuilder == null)
1119 icmpv6MatchBuilder = new Icmpv6MatchBuilder();
1121 Icmpv6CodeMatchEntry icmpv6CodeMatchEntry = matchEntry.getAugmentation(Icmpv6CodeMatchEntry.class);
1122 icmpv6MatchBuilder.setIcmpv6Code(icmpv6CodeMatchEntry.getIcmpv6Code());
1123 }else if (matchEntry instanceof Ipv4Src){
1124 if(ipv4MatchBuilder == null)
1125 ipv4MatchBuilder = new Ipv4MatchBuilder();
1127 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1128 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1129 ipv4MatchBuilder.setIpv4Source(
1130 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1131 +"/"+new String(maskMatchEntry.getMask())));
1133 }else if (matchEntry instanceof Ipv4Dst){
1134 if(ipv4MatchBuilder == null)
1135 ipv4MatchBuilder = new Ipv4MatchBuilder();
1137 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1138 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1139 ipv4MatchBuilder.setIpv4Destination(
1140 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1141 +"/"+new String(maskMatchEntry.getMask())));
1142 }else if (matchEntry instanceof ArpOp){
1143 if(arpMatchBuilder == null)
1144 arpMatchBuilder = new ArpMatchBuilder();
1146 OpCodeMatchEntry opCodeMatchEntry = matchEntry.getAugmentation(OpCodeMatchEntry.class);
1147 arpMatchBuilder.setArpOp(opCodeMatchEntry.getOpCode());
1149 }else if (matchEntry instanceof ArpSpa){
1150 if(arpMatchBuilder == null)
1151 arpMatchBuilder = new ArpMatchBuilder();
1153 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1154 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1155 arpMatchBuilder.setArpSourceTransportAddress(
1156 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1157 +"/"+new String(maskMatchEntry.getMask())));
1159 }else if (matchEntry instanceof ArpTpa){
1160 if(arpMatchBuilder == null)
1161 arpMatchBuilder = new ArpMatchBuilder();
1163 Ipv4AddressMatchEntry ipv4AddressMatchEntry = matchEntry.getAugmentation(Ipv4AddressMatchEntry.class);
1164 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1165 arpMatchBuilder.setArpTargetTransportAddress(
1166 new Ipv4Prefix(ipv4AddressMatchEntry.getIpv4Address().getValue()
1167 +"/"+new String(maskMatchEntry.getMask())));
1169 }else if (matchEntry instanceof ArpSha){
1170 if(arpMatchBuilder == null)
1171 arpMatchBuilder = new ArpMatchBuilder();
1173 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1174 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1175 ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
1176 arpSourceHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
1177 arpSourceHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1178 arpMatchBuilder.setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder.build());
1180 }else if (matchEntry instanceof ArpTha){
1181 if(arpMatchBuilder == null)
1182 arpMatchBuilder = new ArpMatchBuilder();
1184 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1185 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1186 ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
1187 arpTargetHardwareAddressBuilder.setAddress(macAddressMatchEntry.getMacAddress());
1188 arpTargetHardwareAddressBuilder.setMask(maskMatchEntry.getMask());
1189 arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build());
1190 }else if (matchEntry instanceof Ipv6Src){
1191 if(ipv6MatchBuilder == null)
1192 ipv6MatchBuilder = new Ipv6MatchBuilder();
1194 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1195 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1196 ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix (ipv6AddressMatchEntry.getIpv6Address().getValue()+
1197 "/"+new String(maskMatchEntry.getMask())));
1199 }else if (matchEntry instanceof Ipv6Dst){
1200 if(ipv6MatchBuilder == null)
1201 ipv6MatchBuilder = new Ipv6MatchBuilder();
1203 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1204 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1205 ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix (ipv6AddressMatchEntry.getIpv6Address().getValue()+
1206 "/"+new String(maskMatchEntry.getMask())));
1208 }else if (matchEntry instanceof Ipv6Flabel){
1209 if(ipv6MatchBuilder == null)
1210 ipv6MatchBuilder = new Ipv6MatchBuilder();
1212 Ipv6FlabelMatchEntry ipv6FlabelMatchEntry = matchEntry.getAugmentation(Ipv6FlabelMatchEntry.class);
1213 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1214 Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
1215 ipv6LabelBuilder.setIpv6Flabel(ipv6FlabelMatchEntry.getIpv6Flabel());
1216 ipv6LabelBuilder.setFlabelMask(maskMatchEntry.getMask());
1217 ipv6MatchBuilder.setIpv6Label(ipv6LabelBuilder.build());
1219 }else if (matchEntry instanceof Ipv6NdTarget){
1220 if(ipv6MatchBuilder == null)
1221 ipv6MatchBuilder = new Ipv6MatchBuilder();
1222 Ipv6AddressMatchEntry ipv6AddressMatchEntry = matchEntry.getAugmentation(Ipv6AddressMatchEntry.class);
1223 ipv6MatchBuilder.setIpv6NdTarget(ipv6AddressMatchEntry.getIpv6Address());
1225 }else if (matchEntry instanceof Ipv6NdSll){
1226 if(ipv6MatchBuilder == null)
1227 ipv6MatchBuilder = new Ipv6MatchBuilder();
1229 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1230 ipv6MatchBuilder.setIpv6NdSll(macAddressMatchEntry.getMacAddress());
1231 }else if (matchEntry instanceof Ipv6NdTll){
1232 if(ipv6MatchBuilder == null)
1233 ipv6MatchBuilder = new Ipv6MatchBuilder();
1235 MacAddressMatchEntry macAddressMatchEntry = matchEntry.getAugmentation(MacAddressMatchEntry.class);
1236 ipv6MatchBuilder.setIpv6NdTll(macAddressMatchEntry.getMacAddress());
1238 }else if (matchEntry instanceof Ipv6Exthdr){
1239 if(ipv6MatchBuilder == null)
1240 ipv6MatchBuilder = new Ipv6MatchBuilder();
1242 PseudoFieldMatchEntry pseudoFieldMatchEntry = matchEntry.getAugmentation(PseudoFieldMatchEntry.class);
1243 PseudoField pseudoField = pseudoFieldMatchEntry.getPseudoField();
1244 int pseudoFieldInt = 0;
1245 pseudoFieldInt |= pseudoField.isNonext()?(1 << 0):~(1 << 0);
1246 pseudoFieldInt |= pseudoField.isEsp()?(1 << 1):~(1 << 1);
1247 pseudoFieldInt |= pseudoField.isAuth()?(1 << 2):~(1 << 2);
1248 pseudoFieldInt |= pseudoField.isDest()?(1 << 3):~(1 << 3);
1249 pseudoFieldInt |= pseudoField.isFrag()?(1 << 4):~(1 << 4);
1250 pseudoFieldInt |= pseudoField.isRouter()?(1 << 5):~(1 << 5);
1251 pseudoFieldInt |= pseudoField.isHop()?(1 << 6):~(1 << 6);
1252 pseudoFieldInt |= pseudoField.isUnrep()?(1 << 7):~(1 << 7);
1253 pseudoFieldInt |= pseudoField.isUnseq()?(1 << 8):~(1 << 8);
1255 ipv6MatchBuilder.setIpv6Exthdr(pseudoFieldInt);
1256 }else if (matchEntry instanceof MplsLabel){
1257 if(protocolMatchFieldsBuilder == null)
1258 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1260 MplsLabelMatchEntry MplsLabelMatchEntry = matchEntry.getAugmentation(MplsLabelMatchEntry.class);
1261 protocolMatchFieldsBuilder.setMplsLabel(MplsLabelMatchEntry.getMplsLabel());
1263 }else if (matchEntry instanceof MplsBos){
1264 if(protocolMatchFieldsBuilder == null)
1265 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1267 BosMatchEntry bosMatchEntry = matchEntry.getAugmentation(BosMatchEntry.class);
1268 protocolMatchFieldsBuilder.setMplsBos(bosMatchEntry.isBos()?(short)1:(short)0);
1270 }else if (matchEntry instanceof MplsTc) {
1271 if(protocolMatchFieldsBuilder == null)
1272 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1274 TcMatchEntry tcMatchEntry = matchEntry.getAugmentation(TcMatchEntry.class);
1275 protocolMatchFieldsBuilder.setMplsTc(tcMatchEntry.getTc());
1277 }else if (matchEntry instanceof PbbIsid){
1278 if(protocolMatchFieldsBuilder == null)
1279 protocolMatchFieldsBuilder = new ProtocolMatchFieldsBuilder();
1281 IsidMatchEntry isidMatchEntry = matchEntry.getAugmentation(IsidMatchEntry.class);
1282 PbbBuilder pbbBuilder = new PbbBuilder();
1283 pbbBuilder.setPbbIsid(isidMatchEntry.getIsid());
1284 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1285 if(maskMatchEntry != null)
1286 pbbBuilder.setPbbMask(maskMatchEntry.getMask());
1288 protocolMatchFieldsBuilder.setPbb(pbbBuilder.build());
1289 }else if (matchEntry instanceof TunnelId){
1290 MetadataMatchEntry metadataMatchEntry = matchEntry.getAugmentation(MetadataMatchEntry.class);
1291 MaskMatchEntry maskMatchEntry = matchEntry.getAugmentation(MaskMatchEntry.class);
1292 TunnelBuilder tunnelBuilder = new TunnelBuilder();
1293 tunnelBuilder.setTunnelId(new BigInteger(metadataMatchEntry.getMetadata()));
1294 tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
1295 match.setTunnel(tunnelBuilder.build());
1298 if(ethernetMatchBuilder != null){
1299 match.setEthernetMatch(ethernetMatchBuilder.build());
1301 if (vlanMatchBuilder != null){
1302 match.setVlanMatch(vlanMatchBuilder.build());
1304 if(ipMatchBuilder != null){
1305 match.setIpMatch(ipMatchBuilder.build());
1307 if(tcpMatchBuilder != null){
1308 match.setLayer4Match(tcpMatchBuilder.build());
1310 if(udpMatchBuilder != null){
1311 match.setLayer4Match(udpMatchBuilder.build());
1313 if(sctpMatchBuilder != null){
1314 match.setLayer4Match(sctpMatchBuilder.build());
1316 if(icmpv4MatchBuilder != null){
1317 match.setIcmpv4Match(icmpv4MatchBuilder.build());
1319 if(icmpv6MatchBuilder != null){
1320 match.setIcmpv6Match(icmpv6MatchBuilder.build());
1322 if(ipv4MatchBuilder != null){
1323 match.setLayer3Match(ipv4MatchBuilder.build());
1325 if(arpMatchBuilder != null){
1326 match.setLayer3Match(arpMatchBuilder.build());
1328 if(ipv6MatchBuilder != null){
1329 match.setLayer3Match(ipv6MatchBuilder.build());
1331 if(protocolMatchFieldsBuilder != null){
1332 match.setProtocolMatchFields(protocolMatchFieldsBuilder.build());
1334 setField.setMatch(match.build());
1336 */ return setField.build();