Examples of OFFlowMod


Examples of org.openflow.protocol.OFFlowMod

          ofMatchSource.setNetworkSource(ipAddress
              .getIpAddressValue());

          ofMatchSource.setWildcards(wildCardSource);
          ofMatch = ofMatchSource;
          OFFlowMod flowModRule = new OFFlowMod();
          flowModRule.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
          flowModRule.setPriority(changedFlow.getPriority());
          flowModRule.setHardTimeout((short) 0);
          flowModRule.setIdleTimeout((short) 0);
         
          flowModRule.setBufferId(-1);
          flowModRule.setMatch(ofMatch);
     

         
          OFActionOutput ofAction = new OFActionOutput();
          ofAction.setPort(increasedPort);
          ArrayList<OFAction> actions = new ArrayList<OFAction>();
          actions.add(ofAction);
          if (mirroredPorts.get(increasedPort) != null) {
            OFActionOutput ofActionMirror = new OFActionOutput();
            ofActionMirror
                .setPort(mirroredPorts.get(increasedPort));
            actions.add(ofActionMirror);
          }

          flowModRule.setActions(actions);

 

          flowMods.add(flowModRule);

          OFMatch ofMatchDest = new OFMatch();
          ofMatchDest.setDataLayerType((short) 0x0800);
          ofMatchDest.setNetworkDestination(ipAddress
              .getIpAddressValue());

          int wildCardDest = OFMatch.OFPFW_ALL
              ^ OFMatch.OFPFW_DL_TYPE
              ^ OFMatch.OFPFW_NW_DST_ALL
              ^ (((maskingBits) - 1) << OFMatch.OFPFW_NW_DST_SHIFT);

          ofMatchDest.setWildcards(wildCardDest);

          OFFlowMod flowModRule1 = new OFFlowMod();
          flowModRule1.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
          flowModRule1.setPriority(changedFlow.getPriority());
          flowModRule1.setHardTimeout((short) 0);
          flowModRule1.setIdleTimeout((short) 0);
          flowModRule1.setBufferId(-1);
          flowModRule1.setMatch(ofMatchDest);

          flowModRule1.setActions(actions);

       

          flowMods.add(flowModRule1);

        }

        pattern = Pattern
            .compile("nw_dst=([0-9]+.[0-9]+.[0-9]+.[0-9]+)/([0-9]*)");

        matcher = pattern.matcher(changedFlow.getFlowString());

        while (matcher.find()) {

          try {
            logger.debug("ip address is {} and subnet is {}",

            matcher.group(1), matcher.group(2));

          } catch (IndexOutOfBoundsException ioe) {
            break;
          }
          IPv4Address ipv4Address = new IPv4Address(matcher.group(1));
          ipv4Address.setSubnet(Integer.parseInt(matcher.group(2)));
          int ipAddressInt = ipv4Address.getIPv4AddressInt();

          IPAddress ipAddress = new IPAddress();
          ipAddress.setIpAddressValue(ipAddressInt);
          ipAddress.setSubnet(Integer.parseInt(matcher.group(2)));

          short maskingBits = (short) (ipAddress.getSubnet());
          int wildCardDestination = OFMatch.OFPFW_ALL
              ^ OFMatch.OFPFW_DL_TYPE
              ^ OFMatch.OFPFW_NW_DST_ALL
              ^ (((maskingBits) - 1) << OFMatch.OFPFW_NW_DST_SHIFT);

          OFMatch ofMatchDestination = new OFMatch();
          ofMatchDestination.setDataLayerType((short) 0x0800);

          ofMatchDestination.setNetworkDestination(ipAddress
              .getIpAddressValue());

          ofMatchDestination.setWildcards(wildCardDestination);
          ofMatch = ofMatchDestination;
          OFFlowMod flowModRule = new OFFlowMod();
          flowModRule.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
          flowModRule.setHardTimeout((short) 0);
          flowModRule.setIdleTimeout((short) 0);
          flowModRule.setBufferId(-1);
          flowModRule.setMatch(ofMatch);
          flowModRule.setPriority(changedFlow.getPriority());
         
          OFActionOutput ofAction = new OFActionOutput();
          ofAction.setPort(increasedPort);
          ArrayList<OFAction> actions = new ArrayList<OFAction>();
          actions.add(ofAction);
          if (mirroredPorts.get(increasedPort) != null) {
            OFActionOutput ofActionMirror = new OFActionOutput();
            ofActionMirror
                .setPort(mirroredPorts.get(increasedPort));
            actions.add(ofActionMirror);
          }
          flowModRule.setActions(actions);

       

          flowMods.add(flowModRule);

          OFMatch ofMatchSrc = new OFMatch();
          ofMatchSrc.setDataLayerType((short) 0x0800);
          ofMatchSrc.setNetworkSource(ipAddress.getIpAddressValue());

          int wildCardSrc = OFMatch.OFPFW_ALL
              ^ OFMatch.OFPFW_DL_TYPE
              ^ OFMatch.OFPFW_NW_SRC_ALL
              ^ (((maskingBits) - 1) << OFMatch.OFPFW_NW_SRC_SHIFT);

          ofMatchSrc.setWildcards(wildCardSrc);

          OFFlowMod flowModRule1 = new OFFlowMod();
          flowModRule1.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
          flowModRule1.setPriority(changedFlow.getPriority());
          flowModRule1.setHardTimeout((short) 0);
          flowModRule1.setIdleTimeout((short) 0);
          flowModRule1.setBufferId(-1);
          flowModRule1.setMatch(ofMatchSrc);

          flowModRule1.setActions(actions);

   

          flowMods.add(flowModRule1);

View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

    // handle output switch first

    IOFSwitch outputSwitch = flowscaleController.getIBeaconProvider()
        .getSwitches().get(outputSwitchDatapathId);

    OFFlowMod flowModRule = new OFFlowMod();
    flowModRule.setType(OFType.FLOW_MOD);
    flowModRule.setCommand(OFFlowMod.OFPFC_ADD);
    flowModRule.setHardTimeout((short) 0);
    flowModRule.setIdleTimeout((short) 0);
    flowModRule.setBufferId(-1);

    int count = 0;

    int actionOutputLength;

    if (this.dropPortGroup) {
      actionOutputLength = 0;
    } else {
      actionOutputLength = OFActionOutput.MINIMUM_LENGTH;
    }

    for (OFRule rule : this.groupRules) {
      count++;

      flowModRule.setMatch(rule.getMatch());
      if (!this.dropPortGroup) {
        // add mirroring capabitlites

        HashMap<Short, Short> switchMirrors = flowscaleController
            .getSwitchFlowMirrorPortsHashMap().get(
                outputSwitch.getId());

        if (switchMirrors != null) {
          FlowscaleController.logger.debug("Mirror hashmap {}",
              switchMirrors.toString());
          OFActionOutput actionPort = null;
          try {
            FlowscaleController.logger.debug("Mirror actions = {}",
                rule.getActions());
            if (rule.getActions() != null) {

              actionPort = ((OFActionOutput) rule.getActions()
                  .get(0));

              FlowscaleController.logger.debug(
                  "Action port for Mirror is {}",
                  actionPort.getPort());
            }
            Short mirrorPortValue = switchMirrors.get(actionPort
                .getPort());
            if (mirrorPortValue != null) {
              FlowscaleController.logger
                  .debug("mirror {} for switch {} set ",
                      actionPort.getPort()
                          + ","
                          + mirrorPortValue
                              .toString(),
                      HexString.toHexString(outputSwitch
                          .getId()));
              rule.setMirrorPort(mirrorPortValue);
            }

          } catch (NumberFormatException nfe) {
            FlowscaleController.logger.error(
                "OFAction {} is not directed to a switch port",
                flowModRule.getActions().get(0).toString());
          }

        }

        // after checking mirrors set actions
        flowModRule.setActions(rule.getActions());
      }
      flowModRule.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH
          + actionOutputLength));
      flowModRule.setPriority(rule.getPriority());

      try {
        FlowscaleController.logger.debug("{}", flowModRule);
        outputSwitch.getOutputStream().write(flowModRule);
        if (count >= flowscaleController.getMaximumFlowsToPush()) {
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

  private void deleteAllRules() {
    // algorithm to nuke all rules from all switches
    IOFSwitch sw = flowscaleController.ibeaconProvider.getSwitches().get(
        this.outputSwitchDatapathId);
    OFFlowMod flowToDelete = new OFFlowMod();
    flowToDelete.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
    flowToDelete.setOutPort(OFPort.OFPP_NONE);
    for (OFRule ofRule : this.groupRules) {

      flowToDelete.setMatch(ofRule.getMatch());
      flowToDelete.setPriority(ofRule.getPriority());
      flowToDelete.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH));

      try {

        FlowscaleController.logger.debug(
            " Attempting to delete flow  {}", flowToDelete);
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

   * @param reason
   *            the reason for the update
   */
  public void alert(IOFSwitch sw, short portNum, OFPhysicalPort physicalPort,
      OFPortReason reason) {
    OFFlowMod updateFlow = new OFFlowMod();
    OFFlowMod updateFlow2 = new OFFlowMod();
    updateFlow.setType(OFType.FLOW_MOD);
    updateFlow.setCommand(OFFlowMod.OFPFC_ADD);
    updateFlow.setHardTimeout((short) 0);
    updateFlow.setIdleTimeout((short) 0);
    int portStatus = 0;

    FlowscaleController.logger
        .trace("current rules for group with update port");

    for (OFRule rule : this.groupRules) {

      FlowscaleController.logger.trace("rule match is {} and port is {}",
          rule.getMatch().toString(), rule.getActions().get(0));

    }

    if (physicalPort == null) {

      if (reason == OFPortReason.OFPPR_ADD) {

        portStatus = 0;

      } else if (reason == OFPortReason.OFPPR_DELETE) {
        portStatus = 1;
      }

    } else if (reason == null) {

      // just check that the last bit is zero then set the status to 0 or
      // 1 meaning port is down
      portStatus = physicalPort.getState();
      if (portStatus % 2 == 0) {
        portStatus = 0;
      } else {
        portStatus = 1;
      }

    }

    FlowscaleController.logger.info(
        "updating flows since there is a port modification at port {}",
        physicalPort.getPortNumber());

    switch (portStatus) {

    case 0:
      FlowscaleController.logger
          .info("a port belonging to the group output ports is up");

      if (!(outputPortsUp
          .contains(new Short(physicalPort.getPortNumber())))) {
        outputPortsUp.add(physicalPort.getPortNumber());
      }
      int ruleDistribution = this.outputPortsUp.size();

      int i = 1;

      FlowscaleController.logger.info(
          "Modifying flows for switch {} to add port {}",
          HexString.toHexString(sw.getId()),
          physicalPort.getPortNumber());
      ArrayList<OFRule> checkedRules = new ArrayList<OFRule>();
      for (OFRule ofRule : this.groupRules) {

        if (checkedRules.contains(ofRule)) {
          continue;
        }

        if (i % ruleDistribution == 0) {

          OFActionOutput ofActionOutput = new OFActionOutput();
          ofActionOutput.setPort(portNum);

          String thisMatchString = ofRule.getMatch().toString();
          String otherMatchString = "";
          OFRule otherDirectionRule = null;
          if (thisMatchString.indexOf("nw_src") != -1) {
            otherMatchString = thisMatchString.replace("nw_src",
                "nw_dst");

          } else if (thisMatchString.indexOf("nw_dst") != -1) {
            otherMatchString = thisMatchString.replace("nw_dst",
                "nw_src");
          }

          if (this.type == IP_TYPE) {

            for (OFRule ofRule2 : this.groupRules) {

              if (ofRule2.getMatch().toString()
                  .equals(otherMatchString)) {
                otherDirectionRule = ofRule2;
                checkedRules.add(ofRule2);
                break;
              }

            }

          }

          ArrayList<OFAction> actionList = ofRule.getActions();
          actionList.clear();
          HashMap<Short, Short> switchMirrors = flowscaleController
              .getSwitchFlowMirrorPortsHashMap().get(sw.getId());
          actionList.add(ofActionOutput);
          if (switchMirrors != null) {
            Short mirrorPort = switchMirrors.get(portNum);
            if (mirrorPort != null) {
              OFActionOutput mirrorAction = new OFActionOutput();
              mirrorAction.setPort(mirrorPort);
              actionList.add(mirrorAction);

            }

          }

          updateFlow.setMatch(ofRule.getMatch());
          updateFlow.setBufferId(-1);
          updateFlow.setPriority(ofRule.getPriority());

          updateFlow.setActions(actionList);
          updateFlow.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH
              + OFActionOutput.MINIMUM_LENGTH));

          if (this.type == IP_TYPE) {

            updateFlow2 = new OFFlowMod();

            updateFlow2.setType(OFType.FLOW_MOD);
            updateFlow2.setCommand(OFFlowMod.OFPFC_ADD);
            updateFlow2.setHardTimeout((short) 0);
            updateFlow2.setIdleTimeout((short) 0);

            ArrayList<OFAction> actionList2 = otherDirectionRule
                .getActions();
            actionList2.clear();
            HashMap<Short, Short> switchMirrors2 = flowscaleController
                .getSwitchFlowMirrorPortsHashMap().get(
                    sw.getId());
            actionList2.add(ofActionOutput);
            if (switchMirrors2 != null) {
              Short mirrorPort = switchMirrors2.get(portNum);
              if (mirrorPort != null) {
                OFActionOutput mirrorAction = new OFActionOutput();
                mirrorAction.setPort(mirrorPort);
                actionList2.add(mirrorAction);

              }

            }

            updateFlow2.setMatch(otherDirectionRule.getMatch());
            updateFlow2.setBufferId(-1);
            updateFlow2.setPriority(otherDirectionRule
                .getPriority());

            updateFlow2.setActions(actionList2);
            updateFlow2.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH
                + OFActionOutput.MINIMUM_LENGTH));
          }

          try {
            FlowscaleController.logger.trace("modifying flow   {}",
                updateFlow);

            sw.getOutputStream().write(updateFlow);
            if (this.type == IP_TYPE) {
              sw.getOutputStream().write(updateFlow2);
            }

          } catch (IOException e) {
            // TODO Auto-generated catch block
            FlowscaleController.logger.error("{}", e);
          }

        }

        i++;
      }
      FlowscaleController.logger.info("Modification of flows completed");

      break;
    case 1:

      i = 0;
      FlowscaleController.logger.trace("outputPortUp before removal {}",
          outputPortsUp);

      outputPortsUp.remove(new Short(physicalPort.getPortNumber()));
      FlowscaleController.logger.trace("outputPortsUp after removal {}",
          outputPortsUp);

      FlowscaleController.logger
          .info("port {} for switch {} is down so flows for this will be updated",
              physicalPort.getPortNumber(),
              HexString.toHexString(sw.getId()));
      int count = 0;

      ArrayList<OFRule> checkedRulesonPortDown = new ArrayList<OFRule>();

      for (OFRule ofRule : this.groupRules) {

        if (checkedRulesonPortDown.contains(ofRule)) {
          continue;
        }

        OFActionOutput ofActionOutput = (OFActionOutput) ofRule
            .getActions().get(0);

        FlowscaleController.logger.trace(
            "match here is {} and port is {}", ofRule.getMatch(),
            ofActionOutput.getPort());

        if (ofActionOutput.getPort() == portNum) {
          short newPort = 0;
          try {
            newPort = this.outputPortsUp.get(i++
                % outputPortsUp.size());
            ofActionOutput.setPort(newPort);

          } catch (ArithmeticException aeException) {
            FlowscaleController.logger
                .info("No group ports are up , ...no flows redirected");
            continue;
          }
          ArrayList<OFAction> actionList = ofRule.getActions();
          actionList.clear();
          // add mirror ports if there are any

          HashMap<Short, Short> switchMirrors = flowscaleController
              .getSwitchFlowMirrorPortsHashMap().get(sw.getId());
          actionList.add(ofActionOutput);
          if (switchMirrors != null) {
            Short mirrorPort = switchMirrors.get(newPort);
            if (mirrorPort != null) {
              OFActionOutput mirrorAction = new OFActionOutput();
              mirrorAction.setPort(mirrorPort);
              actionList.add(mirrorAction);

            }

          }
          String thisMatchString = ofRule.getMatch().toString();
          String otherMatchString = "";
          OFRule otherDirectionRule = null;
          if (thisMatchString.indexOf("nw_src") != -1) {
            otherMatchString = thisMatchString.replace("nw_src",
                "nw_dst");

          } else if (thisMatchString.indexOf("nw_dst") != -1) {
            otherMatchString = thisMatchString.replace("nw_dst",
                "nw_src");
          }
          if (this.type == IP_TYPE) {

            for (OFRule ofRule2 : this.groupRules) {

              if (ofRule2.getMatch().toString()
                  .equals(otherMatchString)) {
                otherDirectionRule = ofRule2;
                checkedRulesonPortDown.add(ofRule2);
                break;

              }

            }

          }

          updateFlow.setMatch(ofRule.getMatch());
          updateFlow.setBufferId(-1);
       
          updateFlow.setPriority(ofRule.getPriority());

          updateFlow.setActions(actionList);

          if (this.type == IP_TYPE) {

            updateFlow2 = new OFFlowMod();
            updateFlow2.setType(OFType.FLOW_MOD);
            updateFlow2.setCommand(OFFlowMod.OFPFC_ADD);
            updateFlow2.setHardTimeout((short) 0);
            updateFlow2.setIdleTimeout((short) 0);

            ArrayList<OFAction> actionList2 = otherDirectionRule
                .getActions();
            actionList2.clear();
            HashMap<Short, Short> switchMirrors2 = flowscaleController
                .getSwitchFlowMirrorPortsHashMap().get(
                    sw.getId());
            actionList2.add(ofActionOutput);
            if (switchMirrors2 != null) {
              Short mirrorPort = switchMirrors2.get(portNum);
              if (mirrorPort != null) {
                OFActionOutput mirrorAction = new OFActionOutput();
                mirrorAction.setPort(mirrorPort);
                actionList2.add(mirrorAction);

              }

            }

            updateFlow2.setMatch(otherDirectionRule.getMatch());
            updateFlow2.setBufferId(-1);
            updateFlow2.setPriority(otherDirectionRule.getPriority());

            updateFlow2.setActions(actionList2);

          }

          try {
            FlowscaleController.logger.trace("updating flow {}",
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

    try {

      // 1) delete all flows

      OFFlowMod ofDeleteAll = new OFFlowMod();
      OFMatch ofMatchAll = new OFMatch();
      ofMatchAll.setWildcards(OFMatch.OFPFW_ALL);
      ofDeleteAll.setMatch(ofMatchAll);
      ofDeleteAll.setCommand(OFFlowMod.OFPFC_DELETE);

      // 2) inset default drop rule to avoid sending any packet to the
      // controller
      OFFlowMod ofDefaultDropRule = new OFFlowMod();

      ofDefaultDropRule.setPriority((short) defaultRulePriority);
      ofDefaultDropRule.setMatch(ofMatchAll);
      ofDefaultDropRule.setIdleTimeout((short) 0);
      ofDefaultDropRule.setHardTimeout((short) 0);
      ArrayList<OFAction> emptyActions = new ArrayList<OFAction>();

      ofDefaultDropRule.setActions(emptyActions);
      ArrayList<OFFlowMod> mirroringOFFlowMods = new ArrayList<OFFlowMod>();
      // 3) insert mirroring rules for UISO flowscale
      if (mirroringRules == null) {
        logger.info("no mirroring rules configured");
      } else {
        String[] mirrorValues = mirroringRules.split(";");

        // loop over comma separated value

        OFFlowMod mirrorFlowMod;
        OFMatch mirrorMatch;
        ArrayList<OFAction> mirrorOutput;
        OFActionOutput mirrorAction;
        for (String mirrorValue : mirrorValues) {

          String[] mirrorIndex = mirrorValue.split("-");

          short inputPort = Short.parseShort(mirrorIndex[0]);

          String[] mirrorPortValues = mirrorIndex[1].split(",");

          // add the flows

          mirrorFlowMod = new OFFlowMod();
          mirrorMatch = new OFMatch();
          mirrorMatch.setWildcards(OFMatch.OFPFW_ALL
              ^ OFMatch.OFPFW_IN_PORT);
          mirrorMatch.setInputPort(inputPort);
          mirrorFlowMod.setMatch(mirrorMatch);

          mirrorFlowMod.setIdleTimeout((short) 0);
          mirrorFlowMod.setHardTimeout((short) 0);
          mirrorFlowMod.setPriority(mirrorPriority);

          mirrorOutput = new ArrayList<OFAction>();

          for (String mirrorPortValue : mirrorPortValues) {

            mirrorAction = new OFActionOutput();
            mirrorAction.setPort(Short.parseShort(mirrorPortValue));

            mirrorOutput.add(mirrorAction);

          }

          mirrorFlowMod.setActions(mirrorOutput);
          mirrorFlowMod.setBufferId(-1);

          mirroringOFFlowMods.add(mirrorFlowMod);

        }
      }
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

                outPort = macTable.get(dlDstKey);
            }

            // push a flow mod if we know where the packet should be going
            if (outPort != null) {
                OFFlowMod fm = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD);
                fm.setBufferId(bufferId);
                fm.setCommand((short) 0);
                fm.setCookie(0);
                fm.setFlags((short) 0);
                fm.setHardTimeout((short) 0);
                fm.setIdleTimeout((short) 5);
                match.setInputPort(pi.getInPort());
                match.setWildcards(0);
                fm.setMatch(match);
                fm.setOutPort((short) OFPort.OFPP_NONE.getValue());
                fm.setPriority((short) 0);
                OFActionOutput action = new OFActionOutput();
                action.setMaxLength((short) 0);
                action.setPort(outPort);
                List<OFAction> actions = new ArrayList<OFAction>();
                actions.add(action);
                fm.setActions(actions);
                fm.setLength(U16.t(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH));
                try {
                    stream.write(fm);
                } catch (IOException e) {
                    e.printStackTrace();
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.