/** * Tests the point to point intent JSON codec. * * @throws IOException if JSON processing fails */ @Test public void decodePointToPointIntent() throws IOException { JsonCodec<Intent> intentCodec = context.codec(Intent.class); assertThat(intentCodec, notNullValue()); Intent intent = getIntent("PointToPointIntent.json", intentCodec); assertThat(intent, notNullValue()); assertThat(intent, instanceOf(PointToPointIntent.class)); PointToPointIntent pointIntent = (PointToPointIntent) intent; assertThat(pointIntent.priority(), is(55)); assertThat(pointIntent.ingressPoint().deviceId(), is(did("0000000000000001"))); assertThat(pointIntent.ingressPoint().port(), is(PortNumber.portNumber(1))); assertThat(pointIntent.egressPoint().deviceId(), is(did("0000000000000007"))); assertThat(pointIntent.egressPoint().port(), is(PortNumber.portNumber(2))); assertThat(pointIntent.constraints(), hasSize(1)); assertThat(pointIntent.selector(), notNullValue()); assertThat(pointIntent.selector().criteria(), hasSize(1)); Criterion criterion1 = pointIntent.selector().criteria().iterator().next(); assertThat(criterion1, instanceOf(EthCriterion.class)); EthCriterion ethCriterion = (EthCriterion) criterion1; assertThat(ethCriterion.mac().toString(), is("11:22:33:44:55:66")); assertThat(ethCriterion.type().name(), is("ETH_DST")); assertThat(pointIntent.treatment(), notNullValue()); assertThat(pointIntent.treatment().allInstructions(), hasSize(1)); Instruction instruction1 = pointIntent.treatment().allInstructions().iterator().next(); assertThat(instruction1, instanceOf(ModEtherInstruction.class)); ModEtherInstruction ethInstruction = (ModEtherInstruction) instruction1; assertThat(ethInstruction.mac().toString(), is("22:33:44:55:66:77")); assertThat(ethInstruction.type().toString(), is("L2MODIFICATION")); assertThat(ethInstruction.subtype().toString(), is("ETH_SRC")); }
/** * Constructs a BGP intent and put it into the intentList. * * <p>The purpose of this method is too simplify the setUpBgpIntents() method, and to make the * setUpBgpIntents() easy to read. * * @param srcVlanId ingress VlanId * @param dstVlanId egress VlanId * @param srcPrefix source IP prefix to match * @param dstPrefix destination IP prefix to match * @param srcTcpPort source TCP port to match * @param dstTcpPort destination TCP port to match * @param srcConnectPoint source connect point for PointToPointIntent * @param dstConnectPoint destination connect point for PointToPointIntent */ private void bgpPathintentConstructor( VlanId srcVlanId, VlanId dstVlanId, String srcPrefix, String dstPrefix, Short srcTcpPort, Short dstTcpPort, ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { TrafficSelector.Builder builder = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPProtocol(IPv4.PROTOCOL_TCP) .matchIPSrc(IpPrefix.valueOf(srcPrefix)) .matchIPDst(IpPrefix.valueOf(dstPrefix)); if (!srcVlanId.equals(VlanId.NONE)) { builder.matchVlanId(srcVlanId); } TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); if (!dstVlanId.equals(VlanId.NONE)) { treatment.setVlanId(dstVlanId); } if (srcTcpPort != null) { builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); } if (dstTcpPort != null) { builder.matchTcpDst(TpPort.tpPort(dstTcpPort)); } Key key = Key.of( srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] + "-" + ((srcTcpPort == null) ? "dst" : "src"), APPID); PointToPointIntent intent = PointToPointIntent.builder() .appId(APPID) .key(key) .selector(builder.build()) .treatment(treatment.build()) .ingressPoint(srcConnectPoint) .egressPoint(dstConnectPoint) .build(); intentList.add(intent); }
/** 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)); }
/** 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)); }