Beispiel #1
0
  public boolean pushRoute(
      Route route,
      OFMatch match,
      Integer wildcard_hints,
      OFPacketIn pi,
      long pinSwitch,
      long cookie,
      FloodlightContext cntx,
      boolean requestFlowRemovedNotifn,
      boolean doFlush,
      short flowModCommand) {

    boolean srcSwitchIncluded = false;
    OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    OFActionOutput action = new OFActionOutput();
    action.setMaxLength((short) 0xffff);
    List<OFAction> actions = new ArrayList<OFAction>();
    actions.add(action);

    fm.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
        .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
        .setBufferId(OFPacketOut.BUFFER_ID_NONE)
        .setCookie(cookie)
        .setCommand(flowModCommand)
        .setMatch(match)
        .setActions(actions)
        .setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);

    List<NodePortTuple> switchPortList = route.getPath();

    for (int indx = switchPortList.size() - 1; indx > 0; indx -= 2) {
      // indx and indx-1 will always have the same switch DPID.
      long switchDPID = switchPortList.get(indx).getNodeId();
      IOFSwitch sw = floodlightProvider.getSwitches().get(switchDPID);
      if (sw == null) {
        if (log.isWarnEnabled()) {
          log.warn("Unable to push route, switch at DPID {} " + "not available", switchDPID);
        }
        return srcSwitchIncluded;
      }

      // set the match.
      fm.setMatch(wildcard(match, sw, wildcard_hints));

      // set buffer id if it is the source switch
      if (1 == indx) {
        // Set the flag to request flow-mod removal notifications only
        // for the
        // source switch. The removal message is used to maintain the
        // flow
        // cache. Don't set the flag for ARP messages
        if ((requestFlowRemovedNotifn) && (match.getDataLayerType() != Ethernet.TYPE_ARP)) {
          fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
          match.setWildcards(fm.getMatch().getWildcards());
        }
      }

      short outPort = switchPortList.get(indx).getPortId();
      short inPort = switchPortList.get(indx - 1).getPortId();
      // set input and output ports on the switch
      fm.getMatch().setInputPort(inPort);
      ((OFActionOutput) fm.getActions().get(0)).setPort(outPort);

      try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, fm);
        if (log.isTraceEnabled()) {
          log.trace(
              "Pushing Route flowmod routeIndx={} " + "sw={} inPort={} outPort={}",
              new Object[] {indx, sw, fm.getMatch().getInputPort(), outPort});
        }
        messageDamper.write(sw, fm, cntx);
        if (doFlush) {
          sw.flush();
          counterStore.updateFlush();
        }

        // Push the packet out the source switch
        if (sw.getId() == pinSwitch) {
          pushPacket(sw, match, pi, outPort, cntx);
          srcSwitchIncluded = true;
        }
      } catch (IOException e) {
        log.error("Failure writing flow mod", e);
      }

      try {
        fm = fm.clone();
      } catch (CloneNotSupportedException e) {
        log.error("Failure cloning flow mod", e);
      }
    }

    return srcSwitchIncluded;
  }
  @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();
    }
  }