Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.segmentrouting; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 7 | import net.floodlightcontroller.core.IOFSwitch; |
| 8 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 9 | import net.onrc.onos.api.packet.IPacketListener; |
| 10 | import net.onrc.onos.api.packet.IPacketService; |
| 11 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
| 12 | import net.onrc.onos.core.packet.Ethernet; |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 13 | import net.onrc.onos.core.packet.ICMP; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 14 | import net.onrc.onos.core.packet.IPv4; |
Srikanth Vavilapalli | 5ddf8f0 | 2014-09-24 11:02:28 -0700 | [diff] [blame^] | 15 | import net.onrc.onos.core.topology.Host; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 16 | import net.onrc.onos.core.topology.ITopologyService; |
| 17 | import net.onrc.onos.core.topology.MutableTopology; |
| 18 | import net.onrc.onos.core.topology.Port; |
| 19 | import net.onrc.onos.core.topology.Switch; |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 20 | import net.onrc.onos.core.util.SwitchPort; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 21 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 22 | import org.json.JSONArray; |
| 23 | import org.json.JSONException; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 24 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 25 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
| 26 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 27 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 28 | import org.projectfloodlight.openflow.protocol.OFPacketOut; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 30 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort; |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 32 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmMplsLabel; |
| 33 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.types.EthType; |
| 35 | import org.projectfloodlight.openflow.types.IPv4Address; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.types.OFBufferId; |
| 37 | import org.projectfloodlight.openflow.types.OFPort; |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 38 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 39 | import org.projectfloodlight.openflow.types.TableId; |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.types.U32; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 41 | import org.slf4j.Logger; |
| 42 | import org.slf4j.LoggerFactory; |
| 43 | |
| 44 | public class IcmpHandler implements IPacketListener { |
| 45 | |
| 46 | private SegmentRoutingManager srManager; |
| 47 | private IFloodlightProviderService floodlightProvider; |
| 48 | private MutableTopology mutableTopology; |
| 49 | private IPacketService packetService; |
| 50 | private ITopologyService topologyService; |
| 51 | private static final Logger log = LoggerFactory |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 52 | .getLogger(IcmpHandler.class); |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 53 | |
| 54 | private IFlowPusherService flowPusher; |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 55 | private boolean controllerPortAllowed = false; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 56 | |
| 57 | private static final int TABLE_VLAN = 0; |
| 58 | private static final int TABLE_TMAC = 1; |
| 59 | private static final int TABLE_IPv4_UNICAST = 2; |
| 60 | private static final int TABLE_MPLS = 3; |
| 61 | private static final int TABLE_META = 4; |
| 62 | private static final int TABLE_ACL = 5; |
| 63 | |
| 64 | private static final short MAX_PRIORITY = (short) 0xffff; |
| 65 | private static final short SLASH_24_PRIORITY = (short) 0xfff0; |
| 66 | private static final short SLASH_16_PRIORITY = (short) 0xff00; |
| 67 | private static final short SLASH_8_PRIORITY = (short) 0xf000; |
| 68 | private static final short MIN_PRIORITY = 0x0; |
| 69 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 70 | private static final int ICMP_TYPE_ECHO = 0x08; |
| 71 | private static final int ICMP_TYPE_REPLY = 0x00; |
| 72 | |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 73 | |
| 74 | public IcmpHandler(FloodlightModuleContext context, SegmentRoutingManager manager) { |
| 75 | |
| 76 | this.floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 77 | this.flowPusher = context.getServiceImpl(IFlowPusherService.class); |
| 78 | this.packetService = context.getServiceImpl(IPacketService.class); |
| 79 | this.topologyService = context.getServiceImpl(ITopologyService.class); |
| 80 | this.mutableTopology = topologyService.getTopology(); |
| 81 | |
| 82 | this.srManager = manager; |
| 83 | |
| 84 | packetService.registerPacketListener(this); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void receive(Switch sw, Port inPort, Ethernet payload) { |
| 90 | |
| 91 | if (payload.getEtherType() == Ethernet.TYPE_IPV4) { |
| 92 | |
| 93 | IPv4 ipv4 = (IPv4)payload.getPayload(); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 94 | |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 95 | if (ipv4.getProtocol() == IPv4.PROTOCOL_ICMP) { |
Srikanth Vavilapalli | 5ddf8f0 | 2014-09-24 11:02:28 -0700 | [diff] [blame^] | 96 | |
| 97 | log.debug("ICMPHandler: Received a ICMP packet {} from sw {} ", |
| 98 | payload.toString(), sw.getDpid()); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 99 | int destinationAddress = ipv4.getDestinationAddress(); |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 100 | String destAddressStr = IPv4Address.of(destinationAddress).toString(); |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 101 | |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 102 | // Check if it is ICMP request to the switch |
| 103 | String switchIpAddressSlash = sw.getStringAttribute("routerIp"); |
| 104 | if (switchIpAddressSlash != null) { |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 105 | String switchIpAddressStr |
| 106 | = switchIpAddressSlash.substring(0, switchIpAddressSlash.indexOf('/')); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 107 | IPv4Address switchIpAddress = IPv4Address.of(switchIpAddressStr); |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 108 | List<String> gatewayIps = getSubnetGatewayIps(sw); |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 109 | if (((ICMP)ipv4.getPayload()).getIcmpType() == ICMP_TYPE_ECHO && |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 110 | (destinationAddress == switchIpAddress.getInt() || |
| 111 | gatewayIps.contains(destAddressStr))) { |
Srikanth Vavilapalli | 5ddf8f0 | 2014-09-24 11:02:28 -0700 | [diff] [blame^] | 112 | log.debug("ICMPHandler: ICMP packet for sw {} and " |
| 113 | + "sending ICMP response ", sw.getDpid()); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 114 | sendICMPResponse(sw, inPort, payload); |
| 115 | return; |
| 116 | } |
| 117 | } |
Srikanth Vavilapalli | 5ddf8f0 | 2014-09-24 11:02:28 -0700 | [diff] [blame^] | 118 | |
| 119 | /* Check if ICMP is for any switch known host */ |
| 120 | for (Host host: sw.getHosts()) { |
| 121 | IPv4Address hostIpAddress = |
| 122 | IPv4Address.of(host.getIpAddress()); |
| 123 | if (hostIpAddress != null && |
| 124 | hostIpAddress.equals(destinationAddress)) { |
| 125 | /* TODO: We should not have come here as ARP itself |
| 126 | * would have installed a Route to the host. See if |
| 127 | * we can remove this code |
| 128 | */ |
| 129 | log.debug("ICMPHandler: ICMP request for known host {}", |
| 130 | hostIpAddress); |
| 131 | byte[] destinationMacAddress = host.getMacAddress().toBytes(); |
| 132 | srManager.addRouteToHost(sw, |
| 133 | destinationAddress, destinationMacAddress); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | /* ICMP for an unknown host */ |
| 138 | log.debug("ICMPHandler: ICMP request for unknown host {}" |
| 139 | + " and sending ARP request", destinationAddress); |
| 140 | srManager.sendArpRequest(sw, destinationAddress, inPort); |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | } |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 144 | } |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 145 | |
Sangho Shin | eb08303 | 2014-09-22 16:11:34 -0700 | [diff] [blame] | 146 | /** |
| 147 | * Retrieve Gateway IP address of all subnets defined in net config file |
| 148 | * |
| 149 | * @param sw Switch to retrieve subnet GW IPs for |
| 150 | * @return list of GW IP addresses for all subnets |
| 151 | */ |
| 152 | private List<String> getSubnetGatewayIps(Switch sw) { |
| 153 | |
| 154 | List<String> gatewayIps = new ArrayList<String>(); |
| 155 | |
| 156 | String subnets = sw.getStringAttribute("subnets"); |
| 157 | try { |
| 158 | JSONArray arry = new JSONArray(subnets); |
| 159 | for (int i = 0; i < arry.length(); i++) { |
| 160 | String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp"); |
| 161 | if (subnetIpSlash != null) { |
| 162 | String subnetIp = subnetIpSlash.substring(0, subnetIpSlash.indexOf('/')); |
| 163 | gatewayIps.add(subnetIp); |
| 164 | } |
| 165 | } |
| 166 | } catch (JSONException e) { |
| 167 | // TODO Auto-generated catch block |
| 168 | e.printStackTrace(); |
| 169 | } |
| 170 | |
| 171 | return gatewayIps; |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 174 | |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * Send ICMP reply back |
| 178 | * |
| 179 | * @param sw Switch |
| 180 | * @param inPort Port the ICMP packet is forwarded from |
| 181 | * @param icmpRequest the ICMP request to handle |
| 182 | * @param destinationAddress destination address to send ICMP response to |
| 183 | */ |
| 184 | private void sendICMPResponse(Switch sw, Port inPort, Ethernet icmpRequest) { |
| 185 | |
| 186 | Ethernet icmpReplyEth = new Ethernet(); |
| 187 | |
| 188 | IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload(); |
| 189 | IPv4 icmpReplyIpv4 = new IPv4(); |
| 190 | int destAddress = icmpRequestIpv4.getDestinationAddress(); |
| 191 | icmpReplyIpv4.setDestinationAddress(icmpRequestIpv4.getSourceAddress()); |
| 192 | icmpReplyIpv4.setSourceAddress(destAddress); |
| 193 | icmpReplyIpv4.setTtl((byte)64); |
| 194 | icmpReplyIpv4.setChecksum((short)0); |
| 195 | |
| 196 | |
| 197 | ICMP icmpReply = (ICMP)icmpRequestIpv4.getPayload().clone(); |
| 198 | icmpReply.setIcmpCode((byte)0x00); |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 199 | icmpReply.setIcmpType((byte) ICMP_TYPE_REPLY); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 200 | icmpReply.setChecksum((short)0); |
| 201 | |
| 202 | icmpReplyIpv4.setPayload(icmpReply); |
| 203 | |
| 204 | icmpReplyEth.setPayload(icmpReplyIpv4); |
| 205 | icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4); |
| 206 | icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress()); |
| 207 | icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress()); |
| 208 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 209 | sendPacketOut(sw, icmpReplyEth, new SwitchPort(sw.getDpid(), inPort.getPortNumber()), false); |
Sangho Shin | 79c8d45 | 2014-09-18 09:50:21 -0700 | [diff] [blame] | 210 | |
| 211 | log.debug("Send an ICMP response {}", icmpReplyIpv4.toString()); |
| 212 | |
| 213 | } |
| 214 | |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 215 | /** |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 216 | * Send PACKET_OUT message with actions |
| 217 | * If switches support OFPP_TABLE action, it sends out packet to TABLE port |
| 218 | * Otherwise, it sends the packet to the port the packet came from |
| 219 | * (in this case, MPLS label is added if the packet needs go through transit switches) |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 220 | * |
| 221 | * @param sw Switch the packet came from |
| 222 | * @param packet Ethernet packet to send |
| 223 | * @param switchPort port to send the packet |
| 224 | */ |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 225 | private void sendPacketOut(Switch sw, Ethernet packet, SwitchPort switchPort, boolean supportOfppTable) { |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 226 | |
| 227 | boolean sameSubnet = false; |
| 228 | IOFSwitch ofSwitch = floodlightProvider.getMasterSwitch(sw.getDpid().value()); |
| 229 | OFFactory factory = ofSwitch.getFactory(); |
| 230 | |
| 231 | List<OFAction> actions = new ArrayList<>(); |
| 232 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 233 | // If OFPP_TABLE action is not supported in the switch, MPLS label needs to be set |
| 234 | // if the packet needs to be delivered crossing switches |
| 235 | if (!supportOfppTable) { |
| 236 | // Check if the destination is the host attached to the switch |
| 237 | int destinationAddress = ((IPv4)packet.getPayload()).getDestinationAddress(); |
| 238 | for (net.onrc.onos.core.topology.Host host: mutableTopology.getHosts(switchPort)) { |
| 239 | IPv4Address hostIpAddress = IPv4Address.of(host.getIpAddress()); |
| 240 | if (hostIpAddress != null && hostIpAddress.getInt() == destinationAddress) { |
| 241 | sameSubnet = true; |
| 242 | break; |
| 243 | } |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 244 | } |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 245 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 246 | // If the destination host is not attached in the switch, add MPLS label |
| 247 | if (!sameSubnet) { |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 248 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 249 | IPv4Address targetAddress = IPv4Address.of(((IPv4)packet.getPayload()).getDestinationAddress()); |
| 250 | int mplsLabel = getMplsLabelFromConfig(targetAddress); |
| 251 | if (mplsLabel > 0) { |
| 252 | OFAction pushlabel = factory.actions().pushMpls(EthType.MPLS_UNICAST); |
| 253 | OFOxmMplsLabel l = factory.oxms() |
| 254 | .mplsLabel(U32.of(mplsLabel)); |
| 255 | OFAction setlabelid = factory.actions().buildSetField() |
| 256 | .setField(l).build(); |
| 257 | OFAction copyTtlOut = factory.actions().copyTtlOut(); |
| 258 | actions.add(pushlabel); |
| 259 | actions.add(setlabelid); |
| 260 | actions.add(copyTtlOut); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | OFAction outport = factory.actions().output(OFPort.of(switchPort.getPortNumber().shortValue()), Short.MAX_VALUE); |
| 265 | actions.add(outport); |
| 266 | } |
| 267 | // If OFPP_TABLE action is supported, first set a rule to allow packet from CONTROLLER port. |
| 268 | // Then, send the packet to the table port |
| 269 | else { |
| 270 | if (!controllerPortAllowed) { |
| 271 | addControlPortInVlanTable(sw); |
| 272 | controllerPortAllowed = true; |
| 273 | } |
| 274 | OFAction outport = factory.actions().output(OFPort.TABLE, Short.MAX_VALUE); |
| 275 | actions.add(outport); |
| 276 | } |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 277 | |
| 278 | OFPacketOut po = factory.buildPacketOut() |
| 279 | .setData(packet.serialize()) |
| 280 | .setActions(actions) |
| 281 | .build(); |
| 282 | |
| 283 | flowPusher.add(sw.getDpid(), po); |
| 284 | } |
| 285 | |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 286 | /** |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 287 | * Get MPLS label for the target address from the network config file |
| 288 | * |
| 289 | * @param targetAddress - IP address of the target host |
| 290 | * @return MPLS label of the switch to send packets to the target address |
| 291 | */ |
| 292 | private int getMplsLabelFromConfig(IPv4Address targetAddress) { |
| 293 | |
| 294 | int mplsLabel = -1; |
| 295 | |
| 296 | for (Switch sw: mutableTopology.getSwitches()) { |
| 297 | |
| 298 | String subnets = sw.getStringAttribute("subnets"); |
| 299 | try { |
| 300 | JSONArray arry = new JSONArray(subnets); |
| 301 | for (int i = 0; i < arry.length(); i++) { |
| 302 | String subnetIp = (String) arry.getJSONObject(i).get("subnetIp"); |
| 303 | if (srManager.netMatch(subnetIp, targetAddress.toString())) { |
| 304 | String mplsLabelStr = sw.getStringAttribute("nodeSid"); |
| 305 | if (mplsLabelStr != null) |
| 306 | mplsLabel = Integer.parseInt(mplsLabelStr); |
| 307 | } |
| 308 | } |
| 309 | } catch (JSONException e) { |
| 310 | // TODO Auto-generated catch block |
| 311 | e.printStackTrace(); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | return mplsLabel; |
| 316 | } |
| 317 | |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 318 | |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * Add a new rule to VLAN table to forward packets from any port to the next table |
| 322 | * It is required to forward packets from controller to pipeline |
| 323 | * |
| 324 | * @param sw Switch the packet came from |
| 325 | */ |
| 326 | private void addControlPortInVlanTable(Switch sw) { |
| 327 | |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 328 | IOFSwitch ofSwitch = floodlightProvider.getMasterSwitch(sw.getDpid().value()); |
| 329 | OFFactory factory = ofSwitch.getFactory(); |
| 330 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 331 | OFOxmInPort oxp = factory.oxms().inPort(OFPort.CONTROLLER); |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 332 | OFOxmVlanVid oxv = factory.oxms() |
| 333 | .vlanVid(OFVlanVidMatch.UNTAGGED); |
| 334 | OFOxmList oxmList = OFOxmList.of(oxv); |
| 335 | |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 336 | /* Cqpd switch does not seems to support CONTROLLER port as in_port match rule */ |
| 337 | //OFOxmList oxmList = OFOxmList.of(oxp, oxv); |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 338 | |
| 339 | OFMatchV3 match = factory.buildMatchV3() |
| 340 | .setOxmList(oxmList) |
| 341 | .build(); |
| 342 | |
| 343 | OFInstruction gotoTbl = factory.instructions().buildGotoTable() |
| 344 | .setTableId(TableId.of(TABLE_TMAC)).build(); |
| 345 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
Sangho Shin | f41ac0a | 2014-09-19 09:50:30 -0700 | [diff] [blame] | 346 | instructions.add(gotoTbl); |
| 347 | OFMessage flowEntry = factory.buildFlowAdd() |
| 348 | .setTableId(TableId.of(TABLE_VLAN)) |
| 349 | .setMatch(match) |
| 350 | .setInstructions(instructions) |
| 351 | .setPriority(1000) // does not matter - all rules |
| 352 | // exclusive |
| 353 | .setBufferId(OFBufferId.NO_BUFFER) |
| 354 | .setIdleTimeout(0) |
| 355 | .setHardTimeout(0) |
| 356 | //.setXid(getNextTransactionId()) |
| 357 | .build(); |
| 358 | |
| 359 | flowPusher.add(sw.getDpid(), flowEntry);; |
Sangho Shin | 1aa9354 | 2014-09-22 09:49:44 -0700 | [diff] [blame] | 360 | log.debug("Adding a new vlan-rules in sw {}", sw.getDpid()); |
Sangho Shin | 2f26369 | 2014-09-15 14:09:41 -0700 | [diff] [blame] | 361 | |
| 362 | } |
| 363 | |
| 364 | } |