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