private void verifyFlowMod(OFFlowMod testFlowMod, OFFlowMod goodFlowMod) { verifyMatch(testFlowMod, goodFlowMod); verifyActions(testFlowMod, goodFlowMod); // dont' bother testing the cookie; just copy it over goodFlowMod.setCookie(testFlowMod.getCookie()); // .. so we can continue to use .equals() assertEquals(goodFlowMod, testFlowMod); }
@LogMessageDocs({ @LogMessageDoc( level = "ERROR", message = "Failure writing deny flow mod", explanation = "An I/O error occurred while writing a " + "deny flow mod to a switch", recommendation = LogMessageDoc.CHECK_SWITCH) }) public static boolean blockHost( IFloodlightProviderService floodlightProvider, SwitchPort sw_tup, long host_mac, short hardTimeout, long cookie) { if (sw_tup == null) { return false; } IOFSwitch sw = floodlightProvider.getSwitches().get(sw_tup.getSwitchDPID()); if (sw == null) return false; int inputPort = sw_tup.getPort(); log.debug( "blockHost sw={} port={} mac={}", new Object[] {sw, sw_tup.getPort(), new Long(host_mac)}); // Create flow-mod based on packet-in and src-switch OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD); OFMatch match = new OFMatch(); List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to // drop match .setDataLayerSource(Ethernet.toByteArray(host_mac)) .setInputPort((short) inputPort) .setWildcards(OFMatch.OFPFW_ALL & ~OFMatch.OFPFW_DL_SRC & ~OFMatch.OFPFW_IN_PORT); fm.setCookie(cookie) .setHardTimeout(hardTimeout) .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT) .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT) .setBufferId(OFPacketOut.BUFFER_ID_NONE) .setMatch(match) .setActions(actions) .setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH); try { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] {sw, match, fm}); // TODO: can't use the message damper sine this method is static sw.write(fm, null); } catch (IOException e) { log.error("Failure writing deny flow mod", e); return false; } return true; }
@LogMessageDoc( level = "ERROR", message = "Failure writing drop flow mod", explanation = "An I/O error occured while trying to write a " + "drop flow mod to a switch", recommendation = LogMessageDoc.CHECK_SWITCH) protected void doDropFlow( IOFSwitch sw, OFPacketIn pi, IRoutingDecision decision, FloodlightContext cntx) { // initialize match structure and populate it using the packet OFMatch match = new OFMatch(); match.loadFromPacket(pi.getPacketData(), pi.getInPort()); if (decision.getWildcards() != null) { match.setWildcards(decision.getWildcards()); } // Create flow-mod based on packet-in and src-switch OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD); List<OFAction> actions = new ArrayList<OFAction>(); // Set no action to // drop long cookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); fm.setCookie(cookie) .setHardTimeout((short) 0) .setIdleTimeout((short) 5) .setBufferId(OFPacketOut.BUFFER_ID_NONE) .setMatch(match) .setActions(actions) .setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH); try { if (log.isDebugEnabled()) { log.debug("write drop flow-mod sw={} match={} flow-mod={}", new Object[] {sw, match, fm}); } messageDamper.write(sw, fm, cntx); } catch (IOException e) { log.error("Failure writing drop flow mod", e); } }
@Override public void addedSwitch(IOFSwitch sw) { /** * Insert static flows on all ports of the switch to redirect DHCP client --> DHCP DHCPServer * traffic to the controller. DHCP client's operate on UDP port 67 */ OFFlowMod flow = new OFFlowMod(); OFMatch match = new OFMatch(); ArrayList<OFAction> actionList = new ArrayList<OFAction>(); OFActionOutput action = new OFActionOutput(); String flowName; if (sw.getStringId().equals(ROOT_NODE_WIFI_OVS_DPID)) { // root node, WiFi bridge, patch to tunnel port flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_WIFI_OVS_PATCH); action.setType(OFActionType.OUTPUT); action.setPort(ROOT_NODE_WIFI_OVS_TUNNEL); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(ROOT_NODE_WIFI_OVS_TUNNEL); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-wifi-br-patch-tun"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, WiFi bridge, physical to patch flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_WIFI_OVS_TUNNEL); action.setType(OFActionType.OUTPUT); action.setPort(ROOT_NODE_WIFI_OVS_PATCH); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(ROOT_NODE_WIFI_OVS_PATCH); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-wifi-br-tun-patch"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); } else if (sw.getStringId().equals(ROOT_NODE_WIMAX_OVS_DPID)) { // root node, WiMAX bridge, patch to physical flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_WIMAX_OVS_PATCH); action.setType(OFActionType.OUTPUT); action.setPort(ROOT_NODE_WIMAX_OVS_VLAN); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(ROOT_NODE_WIMAX_OVS_VLAN); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-wimax-br-patch-phys"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, WiMAX bridge, interface to patch flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_WIMAX_OVS_VLAN); action.setType(OFActionType.OUTPUT); action.setPort(ROOT_NODE_WIMAX_OVS_PATCH); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(ROOT_NODE_WIMAX_OVS_PATCH); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-wimax-br-phys-patch"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, WiMAX bridge, DHCP on physical match.setInputPort(ROOT_NODE_WIMAX_OVS_VLAN); match.setDataLayerType(Ethernet.TYPE_IPv4); match.setNetworkProtocol(IPv4.PROTOCOL_UDP); match.setTransportSource(UDP.DHCP_CLIENT_PORT); action.setType(OFActionType.OUTPUT); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); action.setPort(OFPort.OFPP_CONTROLLER.getValue()); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(OFPort.OFPP_CONTROLLER.getValue()); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_MAX); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-wimax-br-DHCP-phys"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); } else if (sw.getStringId().equals(ROOT_NODE_ROOT_OVS_DPID)) { // root node, root bridge, patch AP3 (WiFi) to Linux flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_ROOT_OVS_WIFI_PATCH); action.setType(OFActionType.OUTPUT); action.setPort(OFPort.OFPP_LOCAL.getValue()); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(OFPort.OFPP_LOCAL.getValue()); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-root-br-patchWiFi-linux"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, root bridge, patch WiMAX to Linux flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(ROOT_NODE_ROOT_OVS_WIMAX_PATCH); action.setType(OFActionType.OUTPUT); action.setPort(OFPort.OFPP_LOCAL.getValue()); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(OFPort.OFPP_LOCAL.getValue()); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "root-node-root-br-patchWiMAX-linux"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, root bridge, physical to Linux // flow = new OFFlowMod(); // match = new OFMatch(); // match.setInputPort((short) 1); // action.setType(OFActionType.OUTPUT); // action.setPort(OFPort.OFPP_LOCAL.getValue()); // action.setLength((short) OFActionOutput.MINIMUM_LENGTH); // actionList.add(action); // flow.setCookie(0); // flow.setBufferId(-1); // flow.setOutPort(OFPort.OFPP_LOCAL.getValue()); // flow.setActions(actionList); // flow.setMatch(match); // flow.setPriority(PRIORITY_HIGH); // flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); // flowName = "root-ovs-root-br-phys-linux"; // sfp.addFlow(flowName, flow, sw.getStringId()); // log.info("added flow on SW " + sw.getStringId() + flowName); // actionList.clear(); // root node, root bridge, Linux to physical (match extra: src-ip of root node...i.e. it's // outbound) // flow = new OFFlowMod(); // match = new OFMatch(); // match.setInputPort(OFPort.OFPP_LOCAL.getValue()); // match.setDataLayerType(Ethernet.TYPE_IPv4); // ... IP packets ... required for a match on // an IP address // match.setNetworkSource(ROOT_NODE_ROOT_OVS_IP); // action.setType(OFActionType.OUTPUT); // action.setPort((short) 1); // action.setLength((short) OFActionOutput.MINIMUM_LENGTH); // actionList.add(action); // flow.setCookie(0); // flow.setBufferId(-1); // flow.setOutPort((short) 1); // flow.setActions(actionList); // flow.setMatch(match); // flow.setPriority(PRIORITY_HIGH); // flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); // flowName = "root-ovs-root-br-linux-phys-egress"; // sfp.addFlow(flowName, flow, sw.getStringId()); // log.info("added flow on SW " + sw.getStringId() + flowName); // actionList.clear(); } else if (sw.getStringId().equals(WIFI_NODE_WIFI_OVS_DPID)) { // WiFi node, WiFi bridge, physical to patch flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort((short) 1); action.setType(OFActionType.OUTPUT); action.setPort(WIFI_NODE_WIFI_OVS_PATCH); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(WIFI_NODE_WIFI_OVS_PATCH); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "wifi-node-wifi-br-phys-patch"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // WiFi node, WiFi bridge, patch to physical flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(WIFI_NODE_WIFI_OVS_PATCH); action.setType(OFActionType.OUTPUT); action.setPort((short) 1); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort((short) 1); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "wifi-node-wifi-br-patch-phys"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // root node, WiMAX bridge, DHCP on physical match.setInputPort((short) 1); match.setDataLayerType(Ethernet.TYPE_IPv4); match.setNetworkProtocol(IPv4.PROTOCOL_UDP); match.setTransportSource(UDP.DHCP_CLIENT_PORT); action.setType(OFActionType.OUTPUT); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); action.setPort(OFPort.OFPP_CONTROLLER.getValue()); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(OFPort.OFPP_CONTROLLER.getValue()); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_MAX); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "wifi-node-wifi-br-DHCP-phys"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); } else if (sw.getStringId().equals(WIFI_NODE_TUNNEL_OVS_DPID)) { // WiFi node, tunnel bridge, tunnel to patch flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(WIFI_NODE_TUNNEL_OVS_TUNNEL); action.setType(OFActionType.OUTPUT); action.setPort(WIFI_NODE_TUNNEL_OVS_PATCH); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(WIFI_NODE_TUNNEL_OVS_PATCH); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "wifi-node-tunnel-br-tun-patch"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); // WiFi node, tunnel bridge, patch to tunnel flow = new OFFlowMod(); match = new OFMatch(); match.setInputPort(WIFI_NODE_TUNNEL_OVS_PATCH); action.setType(OFActionType.OUTPUT); action.setPort(WIFI_NODE_TUNNEL_OVS_TUNNEL); action.setLength((short) OFActionOutput.MINIMUM_LENGTH); actionList.add(action); flow.setCookie(0); flow.setBufferId(-1); flow.setOutPort(WIFI_NODE_TUNNEL_OVS_TUNNEL); flow.setActions(actionList); flow.setMatch(match); flow.setPriority(PRIORITY_HIGH); flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + action.getLengthU()); flowName = "wifi-node-tunnel-br-patch-tun"; sfp.addFlow(flowName, flow, sw.getStringId()); log.info("added flow on SW " + sw.getStringId() + flowName); actionList.clear(); } }