Example #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;
    }
  }