@Override
 public Criterion decodeCriterion(ObjectNode json) {
   JsonNode ochSignalId =
       nullIsIllegal(
           json.get(CriterionCodec.OCH_SIGNAL_ID),
           CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE);
   GridType gridType =
       GridType.valueOf(
           nullIsIllegal(
                   ochSignalId.get(CriterionCodec.GRID_TYPE),
                   CriterionCodec.GRID_TYPE + MISSING_MEMBER_MESSAGE)
               .asText());
   ChannelSpacing channelSpacing =
       ChannelSpacing.valueOf(
           nullIsIllegal(
                   ochSignalId.get(CriterionCodec.CHANNEL_SPACING),
                   CriterionCodec.CHANNEL_SPACING + MISSING_MEMBER_MESSAGE)
               .asText());
   int spacingMultiplier =
       nullIsIllegal(
               ochSignalId.get(CriterionCodec.SPACING_MULIPLIER),
               CriterionCodec.SPACING_MULIPLIER + MISSING_MEMBER_MESSAGE)
           .asInt();
   int slotGranularity =
       nullIsIllegal(
               ochSignalId.get(CriterionCodec.SLOT_GRANULARITY),
               CriterionCodec.SLOT_GRANULARITY + MISSING_MEMBER_MESSAGE)
           .asInt();
   return Criteria.matchLambda(
       Lambda.ochSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity));
 }
Example #2
0
  /** Tests the encoding of an intent with treatment, selector and constraints specified. */
  @Test
  public void intentWithTreatmentSelectorAndConstraints() {
    ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
    ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
    DeviceId did1 = did("device1");
    DeviceId did2 = did("device2");
    DeviceId did3 = did("device3");
    Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
    final TrafficSelector selector =
        DefaultTrafficSelector.builder()
            .matchIPProtocol((byte) 3)
            .matchMplsLabel(MplsLabel.mplsLabel(4))
            .add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID))
            .add(Criteria.matchLambda(ochSignal))
            .matchEthDst(MacAddress.BROADCAST)
            .matchIPDst(IpPrefix.valueOf("1.2.3.4/24"))
            .build();
    final TrafficTreatment treatment =
        DefaultTrafficTreatment.builder()
            .add(Instructions.modL0Lambda(new IndexedLambda(33)))
            .setMpls(MplsLabel.mplsLabel(44))
            .setOutput(PortNumber.CONTROLLER)
            .setEthDst(MacAddress.BROADCAST)
            .build();

    final List<Constraint> constraints =
        ImmutableList.of(
            new BandwidthConstraint(Bandwidth.bps(1.0)),
            new LambdaConstraint(new IndexedLambda(3)),
            new AnnotationConstraint("key", 33.0),
            new AsymmetricPathConstraint(),
            new LatencyConstraint(Duration.ofSeconds(2)),
            new ObstacleConstraint(did1, did2),
            new WaypointConstraint(did3));

    final PointToPointIntent intent =
        PointToPointIntent.builder()
            .appId(appId)
            .selector(selector)
            .treatment(treatment)
            .ingressPoint(ingress)
            .egressPoint(egress)
            .constraints(constraints)
            .build();

    final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
    assertThat(intentCodec, notNullValue());

    final ObjectNode intentJson = intentCodec.encode(intent, context);
    assertThat(intentJson, matchesIntent(intent));
  }