Ejemplo n.º 1
0
 public boolean setConsumeRule(FTFiveTuple org, FTFiveTuple nextTuple, int tag, int newTag) {
   this.setConsumeFiveTupleRule(org, nextTuple, true, tag, newTag);
   FTFiveTuple reverseOrg =
       new FTFiveTuple(
           org.getNwDst(),
           org.getNwSrc(),
           org.getTpDstPort(),
           org.getTpSrcPort(),
           org.getNwProto());
   FTFiveTuple reverseNextTuple =
       new FTFiveTuple(
           nextTuple.getNwDst(),
           nextTuple.getNwSrc(),
           nextTuple.getTpDstPort(),
           nextTuple.getTpSrcPort(),
           nextTuple.getNwProto());
   this.setConsumeFiveTupleRule(reverseNextTuple, reverseOrg, false, tag, newTag);
   this.setConsumeFiveTupleRule(nextTuple, org, false, tag, newTag);
   return true;
 }
Ejemplo n.º 2
0
  public boolean setNatGenerateRule(FTFiveTuple org, int orgTag, int newTag) {
    Flow flow = new Flow();
    Match match = new Match();
    List<Action> actions = new ArrayList<Action>();
    try {
      match.setField(MatchType.DL_TYPE, (short) 0x0800);
      match.setField(
          MatchType.NW_SRC,
          InetAddress.getByAddress(BigInteger.valueOf(org.getNwSrc()).toByteArray()),
          InetAddress.getByName("255.255.255.255"));
      match.setField(
          MatchType.NW_DST,
          InetAddress.getByAddress(BigInteger.valueOf(org.getNwDst()).toByteArray()),
          InetAddress.getByName("255.255.255.255"));
      logger.info("NAT NW_PROTO:" + org.getNwProto());
      if (org.getNwProto() != 0x01) {
        // TCP or UDP
        logger.info("NW_PROTO:" + org.getNwProto());
        match.setField(MatchType.TP_SRC, new Short((short) org.getTpSrcPort()));
        match.setField(MatchType.TP_DST, new Short((short) org.getTpDstPort()));
      }
      match.setField(MatchType.NW_TOS, new Byte((byte) orgTag));
      match.setField(MatchType.NW_PROTO, new Byte((byte) org.getNwProto()));
      match.setField(MatchType.IN_PORT, this.netPort);
    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    if (newTag != 0 && newTag != -1) {
      actions.add(new SetNwTos(new Byte((byte) (newTag))));
    }
    // Dirty Hack for First NAT
    if (orgTag == 1 && newTag == -1) {
      actions.add(new SetNwTos(new Byte((byte) newTag)));
    }
    actions.add(new SetDlDst(this.getMacAddressFromDPID()));
    actions.add(new Output(this.hostPort));
    flow.setMatch(match);
    flow.setActions(actions);
    System.out.println("NAT GENERAGE");
    if (this.addFlowRule(flow)) {
      this.tagRoute.add(flow);
    }
    return true;
  }
Ejemplo n.º 3
0
  private boolean setConsumeFiveTupleRule(
      FTFiveTuple org, FTFiveTuple modified, boolean toMB, int tag, int newTag) {
    Flow flow = new Flow();
    Match match = new Match();
    List<Action> actions = new ArrayList<Action>();
    match.setField(MatchType.DL_TYPE, (short) 0x0800);
    logger.info("Org: " + org.toString());
    logger.info("Mod: " + modified.toString());
    try {
      match.setField(
          MatchType.NW_SRC,
          InetAddress.getByAddress(BigInteger.valueOf(org.getNwSrc()).toByteArray()),
          InetAddress.getByName("255.255.255.255"));
      match.setField(
          MatchType.NW_DST,
          InetAddress.getByAddress(BigInteger.valueOf(org.getNwDst()).toByteArray()),
          InetAddress.getByName("255.255.255.255"));
      logger.info("CONSUME NW_PROTO:" + org.getNwProto());
      if (org.getNwProto() != 0x01) {
        // TCP or UDP
        match.setField(MatchType.TP_SRC, (short) org.getTpSrcPort());
        match.setField(MatchType.TP_DST, (short) org.getTpDstPort());
      }
      match.setField(MatchType.NW_PROTO, (byte) org.getNwProto());
      System.out.println("HEREERRE:" + toMB);
      if (toMB) {
        logger.info("CONSUME NW TOS:" + tag);
        match.setField(MatchType.NW_TOS, (byte) (tag / 4));
      }
    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    if (modified.getNwSrc() != 0) {
      try {
        actions.add(
            new SetNwSrc(
                InetAddress.getByAddress(BigInteger.valueOf(modified.getNwSrc()).toByteArray())));
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (modified.getNwDst() != 0) {
      try {
        actions.add(
            new SetNwDst(
                InetAddress.getByAddress(BigInteger.valueOf(modified.getNwDst()).toByteArray())));
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (modified.getTpSrcPort() != 0) {
      short modifiedSrcPort = (short) modified.getTpSrcPort();
      actions.add(new SetTpSrc(modifiedSrcPort & 0xffff));
    }

    if (modified.getTpDstPort() != 0) {
      short modifiedDstPort = (short) modified.getTpDstPort();
      actions.add(new SetTpDst(modifiedDstPort & 0xffff));
    }

    if (toMB) {

      actions.add(new SetDlDst(this.getMacAddressFromDPID()));
      // actions.add(new SetNwTos((byte) (newTag/4)));
      byte bNewTag = (byte) (newTag);
      System.out.println("CONSUME");
      actions.add(new SetNwTos((bNewTag & 0xff)));
      actions.add(new Output(this.hostPort));
    } else {
      actions.add(new Output(this.netPort));
    }

    flow.setMatch(match);
    flow.setActions(actions);
    flow.setPriority((short) 10);
    if (this.addFlowRule(flow)) {
      this.tagRoute.add(flow);
    }
    return true;
  }