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