예제 #1
0
  public void afterFromProto(Message proto) {
    // Validate the rule message.
    Topology.Rule rule = (Topology.Rule) proto;
    UUID id = UUIDUtil.fromProto(rule.getId());

    if (!rule.hasAction()) {
      throw new ZoomConvert.ConvertException("Rule " + id + " has no action set (" + rule + ")");
    }

    switch (rule.getType()) {
      case JUMP_RULE:
        if (!rule.hasJumpRuleData()) {
          throw new ZoomConvert.ConvertException(
              "Rule "
                  + id
                  + " is a JUMP rule but does not have its "
                  + "JUMP data set ("
                  + rule
                  + ")");
        }
        if (rule.getAction() != Topology.Rule.Action.JUMP)
          throw new ZoomConvert.ConvertException(
              "Rule "
                  + id
                  + " is a JUMP rule but does not have its "
                  + "action set to JUMP ("
                  + rule
                  + ")");
        break;

      case NAT_RULE:
        if (!rule.hasNatRuleData()) {
          throw new ZoomConvert.ConvertException(
              "Rule "
                  + id
                  + " is a NAT rule but does not have its "
                  + "NAT data set ("
                  + rule
                  + ")");
        }
        if (!rule.getNatRuleData().getReverse()
            && rule.getNatRuleData().getNatTargetsCount() == 0) {
          throw new ZoomConvert.ConvertException(
              "Rule " + id + " is a forward NAT rule but has no " + "targets set (" + rule + ")");
        }
        break;

      case TRACE_RULE:
        if (rule.getAction() != Topology.Rule.Action.CONTINUE)
          throw new ZoomConvert.ConvertException(
              "Rule "
                  + id
                  + " is a TRACE rule but its action is not "
                  + " set to CONTINUE ("
                  + rule
                  + ")");
        break;
    }
  }
예제 #2
0
 public Class<? extends Rule> getType(Topology.Rule proto) {
   switch (proto.getType()) {
     case JUMP_RULE:
       return JumpRule.class;
     case LITERAL_RULE:
       return LiteralRule.class;
     case TRACE_RULE:
       return TraceRule.class;
     case NAT_RULE:
       return NatRule.class;
     default:
       throw new ZoomConvert.ConvertException("Unknown rule " + "type: " + proto.getType());
   }
 }
예제 #3
0
 @Override
 public UUID createRule(UUID chainId, short ethertype) {
   try {
     UUID randId = UUID.randomUUID();
     Topology.Rule r =
         Topology.Rule.getDefaultInstance()
             .toBuilder()
             .setId(UUIDUtil.toProto(randId))
             .setType(Topology.Rule.Type.LITERAL_RULE)
             .setAction(Topology.Rule.Action.ACCEPT)
             .setChainId(UUIDUtil.toProto(chainId))
             .setCondition(Condition.newBuilder().setDlType(ethertype))
             .build();
     backend.store().create(r);
     return randId;
   } catch (Exception e) {
     throw new RuntimeException("Failed to create chain");
   }
 }