예제 #1
0
  @Test
  public void alarmCodecTestWithOptionalField() {
    final JsonCodec<Alarm> codec = context.codec(Alarm.class);
    assertThat(codec, is(notNullValue()));

    final ObjectNode alarmJson = codec.encode(alarmWithSource, context);
    assertThat(alarmJson, notNullValue());
    assertThat(alarmJson, matchesAlarm(alarmWithSource));
  }
예제 #2
0
  @Test
  public void alarmCodecTestWithOptionalFieldMissing() {
    // context.registerService(AlarmService.class, new AlarmServiceAdapter());
    final JsonCodec<Alarm> codec = context.codec(Alarm.class);
    assertThat(codec, is(notNullValue()));

    final ObjectNode alarmJson = codec.encode(alarmMinimumFields, context);
    assertThat(alarmJson, notNullValue());
    assertThat(alarmJson, matchesAlarm(alarmMinimumFields));
  }
예제 #3
0
  /** Tests the encoding of a host to host intent. */
  @Test
  public void hostToHostIntent() {
    final HostToHostIntent intent =
        HostToHostIntent.builder().appId(appId).one(id1).two(id2).build();

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

    final ObjectNode intentJson = intentCodec.encode(intent, context);
    assertThat(intentJson, matchesIntent(intent));
  }
  @Override
  public ObjectNode encode(NextObjective nextObjective, CodecContext context) {

    checkNotNull(nextObjective, NOT_NULL_MESSAGE);

    final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
    final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);

    // encode common properties
    ObjectiveCodecHelper och = new ObjectiveCodecHelper();
    ObjectNode result = och.encode(nextObjective, context);

    // encode id
    result.put(ID, nextObjective.id());

    // encode type
    result.put(TYPE, nextObjective.type().toString());

    // encode operation
    result.put(OPERATION, nextObjective.op().toString());

    // encode treatments
    ArrayNode treatments = context.mapper().createArrayNode();
    nextObjective
        .next()
        .forEach(
            t -> {
              ObjectNode treatmentJson = trafficTreatmentCodec.encode(t, context);
              treatments.add(treatmentJson);
            });
    result.set(TREATMENTS, treatments);

    // encode meta
    if (nextObjective.meta() != null) {
      ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(nextObjective.meta(), context);
      result.set(META, trafficSelectorNode);
    }

    return result;
  }
예제 #5
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));
  }
예제 #6
0
  @Override
  public ObjectNode encode(TrafficSelector selector, CodecContext context) {
    checkNotNull(selector, "Traffic selector cannot be null");

    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonCriteria = result.putArray(CRITERIA);

    if (selector.criteria() != null) {
      final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
      for (final Criterion criterion : selector.criteria()) {
        jsonCriteria.add(criterionCodec.encode(criterion, context));
      }
    }

    return result;
  }
예제 #7
0
  /** Tests the encoding of a point to point intent. */
  @Test
  public void pointToPointIntent() {
    ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
    ConnectPoint egress = NetTestTools.connectPoint("egress", 2);

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

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

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