public static InstructionsBuilder createControllerInstructions() {
    // ActionList
    List<Action> actionList = Lists.newArrayList();
    // Action 1
    ActionBuilder ab = new ActionBuilder();
    OutputActionBuilder oab = new OutputActionBuilder();
    oab.setMaxLength(65535);
    Uri value = new Uri("CONTROLLER");
    oab.setOutputNodeConnector(value);
    ab.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));

    actionList.add(ab.build());
    // Action End

    // Create an Apply Action
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);

    // Wrap our Apply Action in an Instruction
    InstructionBuilder ib = new InstructionBuilder();
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));

    // Put our Instruction in a list of Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(ib.build());
    isb.setInstruction(instructions);
    return isb;
  }
  public static InstructionsBuilder createDropInstructions() {
    // Add our drop action to a list
    List<Action> actionList = Lists.newArrayList();

    // Drop Action
    DropActionBuilder dab = new DropActionBuilder();
    DropAction dropAction = dab.build();
    ActionBuilder ab = new ActionBuilder();
    ab.setAction(new DropActionCaseBuilder().setDropAction(dropAction).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));

    actionList.add(ab.build());

    // Create an Apply Action
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);

    // Wrap our Apply Action in an Instruction
    InstructionBuilder ib = new InstructionBuilder();
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));

    // Put our Instruction in a list of Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(ib.build());
    isb.setInstruction(instructions);
    return isb;
  }
  // createDlSrcInstructions(InstructionBuilder ib, MacAddress macAddress) {
  //	public static InstructionsBuilder create_DlSrc_NwSrc_Instructions(MacAddress macAddress,
  // Ipv4Prefix prefixSrc) {
  public static InstructionsBuilder create_DlSrc_NwSrc_outputPort_Instructions(
      MacAddress macAddress, Ipv4Prefix prefixSrc, String outputPort) {
    // ActionList
    List<Action> actionList = Lists.newArrayList();
    // Action 1
    ActionBuilder ab = new ActionBuilder();
    SetDlSrcActionBuilder dlSrcActionBuilder = new SetDlSrcActionBuilder();
    dlSrcActionBuilder.setAddress(macAddress);
    ab.setAction(
        new SetDlSrcActionCaseBuilder().setSetDlSrcAction(dlSrcActionBuilder.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));

    // Action 2
    ActionBuilder ab2 = new ActionBuilder();
    SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
    Ipv4Builder ipsrc = new Ipv4Builder();
    ipsrc.setIpv4Address(prefixSrc);
    setNwsrcActionBuilder.setAddress(ipsrc.build());
    ab2.setAction(
        new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
    ab2.setOrder(1);
    ab2.setKey(new ActionKey(1));

    // - have to make nodeconnectionid store table
    // Action 3
    ActionBuilder ab3 = new ActionBuilder();
    OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
    if (outputPort.equals("4294967291")) {
      outputActionBuilder.setOutputNodeConnector(new Uri("FLOOD"));
    } else {
      outputActionBuilder.setOutputNodeConnector(new Uri("output:" + outputPort));
    }
    ab3.setAction(
        new OutputActionCaseBuilder().setOutputAction(outputActionBuilder.build()).build());
    ab3.setOrder(2);
    ab3.setKey(new ActionKey(2));

    actionList.add(ab.build());
    actionList.add(ab2.build());
    actionList.add(ab3.build());
    // Action End

    // Create an Apply Action
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);

    // Wrap our Apply Action in an Instruction
    InstructionBuilder ib = new InstructionBuilder();
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));

    // Put our Instruction in a list of Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(ib.build());
    isb.setInstruction(instructions);
    return isb;
  }
Пример #4
0
  @Override
  public Status programIpRewriteExclusion(
      Long dpid, String segmentationId, String excludedCidr, Action action) {
    String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;

    MatchBuilder matchBuilder = new MatchBuilder();
    NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);

    // Instructions List Stores Individual Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = Lists.newArrayList();
    InstructionBuilder ib;

    MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
    String ipAddress = excludedCidr.substring(0, excludedCidr.indexOf("/"));
    InetAddress inetAddress;
    try {
      inetAddress = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
      return new Status(StatusCode.BADREQUEST);
    }
    if (inetAddress instanceof Inet6Address) {
      // WORKAROUND: For now ipv6 is not supported
      // TODO: implement ipv6 cidr case
      LOG.debug("ipv6 cidr is not implemented yet. cidr {}", excludedCidr);
      return new Status(StatusCode.NOTIMPLEMENTED);
    }
    MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(excludedCidr));

    // Goto Next Table
    ib = getMutablePipelineInstructionBuilder();
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));
    instructions.add(ib.build());

    FlowBuilder flowBuilder = new FlowBuilder();
    flowBuilder.setMatch(matchBuilder.build());
    flowBuilder.setInstructions(isb.setInstruction(instructions).build());

    String flowId = "InboundNATExclusion_" + segmentationId + "_" + excludedCidr;
    flowBuilder.setId(new FlowId(flowId));
    FlowKey key = new FlowKey(new FlowId(flowId));
    flowBuilder.setBarrier(true);
    flowBuilder.setTableId(this.getTable());
    flowBuilder.setKey(key);
    flowBuilder.setPriority(1024);
    flowBuilder.setFlowName(flowId);
    flowBuilder.setHardTimeout(0);
    flowBuilder.setIdleTimeout(0);

    if (action.equals(Action.ADD)) {
      writeFlow(flowBuilder, nodeBuilder);
    } else {
      removeFlow(flowBuilder, nodeBuilder);
    }

    // ToDo: WriteFlow/RemoveFlow should return something we can use to check success
    return new Status(StatusCode.SUCCESS);
  }
  public static InstructionsBuilder create_DlSrc_NwSrc_Controller_Instructions(
      MacAddress macAddress, Ipv4Prefix prefixSrc) {
    // ActionList
    List<Action> actionList = Lists.newArrayList();
    // Action 1
    ActionBuilder ab = new ActionBuilder();
    SetDlSrcActionBuilder dlSrcActionBuilder = new SetDlSrcActionBuilder();
    dlSrcActionBuilder.setAddress(macAddress);
    ab.setAction(
        new SetDlSrcActionCaseBuilder().setSetDlSrcAction(dlSrcActionBuilder.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));

    // Action 2
    ActionBuilder ab2 = new ActionBuilder();
    SetNwSrcActionBuilder setNwsrcActionBuilder = new SetNwSrcActionBuilder();
    Ipv4Builder ipsrc = new Ipv4Builder();
    ipsrc.setIpv4Address(prefixSrc);
    setNwsrcActionBuilder.setAddress(ipsrc.build());
    ab2.setAction(
        new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwsrcActionBuilder.build()).build());
    ab2.setOrder(1);
    ab2.setKey(new ActionKey(1));

    // Action 3
    ActionBuilder ab3 = new ActionBuilder();
    OutputActionBuilder oab = new OutputActionBuilder();
    oab.setMaxLength(65535);
    Uri value = new Uri("CONTROLLER");
    oab.setOutputNodeConnector(value);
    ab3.setAction(new OutputActionCaseBuilder().setOutputAction(oab.build()).build());
    ab3.setOrder(2);
    ab3.setKey(new ActionKey(2));

    actionList.add(ab.build());
    actionList.add(ab2.build());
    actionList.add(ab3.build());
    // Action End

    // Create an Apply Action
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);

    // Wrap our Apply Action in an Instruction
    InstructionBuilder ib = new InstructionBuilder();
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));

    // Put our Instruction in a list of Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(ib.build());
    isb.setInstruction(instructions);
    return isb;
  }
Пример #6
0
  @Override
  public Status programIpRewriteRule(
      Long dpid,
      Long inPort,
      String destSegId,
      InetAddress matchAddress,
      InetAddress rewriteAddress,
      Action action) {
    String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;

    MatchBuilder matchBuilder = new MatchBuilder();
    NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);

    // Instructions List Stores Individual Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = Lists.newArrayList();
    InstructionBuilder ib = new InstructionBuilder();

    MatchUtils.createInPortMatch(matchBuilder, dpid, inPort);
    MatchUtils.createDstL3IPv4Match(
        matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(matchAddress.getHostAddress()));

    // Set register to indicate that rewrite took place
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setAction(
        ActionUtils.nxLoadRegAction(
            new DstNxRegCaseBuilder().setNxReg(REG_FIELD).build(), new BigInteger(destSegId)));

    // Set Dest IP address and set REG_FIELD
    InstructionUtils.createNwDstInstructions(
        ib, MatchUtils.iPv4PrefixFromIPv4Address(rewriteAddress.getHostAddress()), actionBuilder);
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));
    instructions.add(ib.build());

    // Goto Next Table
    ib = getMutablePipelineInstructionBuilder();
    ib.setOrder(1);
    ib.setKey(new InstructionKey(1));
    instructions.add(ib.build());

    FlowBuilder flowBuilder = new FlowBuilder();
    flowBuilder.setMatch(matchBuilder.build());
    flowBuilder.setInstructions(isb.setInstruction(instructions).build());

    String flowId = "InboundNAT_" + inPort + "_" + destSegId + "_" + matchAddress.getHostAddress();
    flowBuilder.setId(new FlowId(flowId));
    FlowKey key = new FlowKey(new FlowId(flowId));
    flowBuilder.setBarrier(true);
    flowBuilder.setTableId(this.getTable());
    flowBuilder.setKey(key);
    flowBuilder.setPriority(1024);
    flowBuilder.setFlowName(flowId);
    flowBuilder.setHardTimeout(0);
    flowBuilder.setIdleTimeout(0);

    if (action.equals(Action.ADD)) {
      writeFlow(flowBuilder, nodeBuilder);
    } else {
      removeFlow(flowBuilder, nodeBuilder);
    }

    // ToDo: WriteFlow/RemoveFlow should return something we can use to check success
    return new Status(StatusCode.SUCCESS);
  }
  //	public static InstructionsBuilder create_DlDst_NwDst_Instructions(MacAddress macAddress,
  // Ipv4Prefix prefixDst) {
  public static InstructionsBuilder create_DlDst_NwDst_outputPort_Instructions(
      MacAddress macAddress, Ipv4Prefix prefixDst, String outputPort) {
    //	public static InstructionsBuilder
    // create_DlDst_NwDst_outputPort_controller_Instructions(MacAddress macAddress, Ipv4Prefix
    // prefixDst, String outputPort) {
    // ActionList
    List<Action> actionList = Lists.newArrayList();
    // Action 1
    ActionBuilder ab = new ActionBuilder();
    SetDlDstActionBuilder dlDstActionBuilder = new SetDlDstActionBuilder();
    dlDstActionBuilder.setAddress(macAddress);
    ab.setAction(
        new SetDlDstActionCaseBuilder().setSetDlDstAction(dlDstActionBuilder.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));

    // Action 2
    ActionBuilder ab2 = new ActionBuilder();
    SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
    Ipv4Builder ipDst = new Ipv4Builder();
    ipDst.setIpv4Address(prefixDst);
    setNwDstActionBuilder.setAddress(ipDst.build());
    ab2.setAction(
        new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build());
    ab2.setOrder(1);
    ab2.setKey(new ActionKey(1));

    // - have to make nodeconnectionid store table
    // Action 3
    ActionBuilder ab3 = new ActionBuilder();
    OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
    //		outputActionBuilder.setOutputNodeConnector(new Uri("output:1"));
    outputActionBuilder.setOutputNodeConnector(new Uri("output:" + outputPort));
    ab3.setAction(
        new OutputActionCaseBuilder().setOutputAction(outputActionBuilder.build()).build());
    ab3.setOrder(2);
    ab3.setKey(new ActionKey(2));

    //		// Action 4
    //		ActionBuilder ab4 = new ActionBuilder();
    //		OutputActionBuilder outputActionBuilder2 = new OutputActionBuilder();
    //		outputActionBuilder2.setMaxLength(65535);
    //		outputActionBuilder2.setOutputNodeConnector(new Uri("CONTROLLER"));
    //		ab4.setAction(new
    // OutputActionCaseBuilder().setOutputAction(outputActionBuilder2.build()).build());
    //		ab4.setOrder(3);
    //		ab4.setKey(new ActionKey(3));

    actionList.add(ab.build());
    actionList.add(ab2.build());
    actionList.add(ab3.build());
    //		actionList.add(ab4.build());
    // Action End

    // Create an Apply Action
    ApplyActionsBuilder aab = new ApplyActionsBuilder();
    aab.setAction(actionList);

    // Wrap our Apply Action in an Instruction
    InstructionBuilder ib = new InstructionBuilder();
    ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
    ib.setOrder(0);
    ib.setKey(new InstructionKey(0));

    // Put our Instruction in a list of Instructions
    InstructionsBuilder isb = new InstructionsBuilder();
    List<Instruction> instructions = new ArrayList<Instruction>();
    instructions.add(ib.build());

    isb.setInstruction(instructions);
    return isb;
  }