/** * Tests the host to host intent JSON codec. * * @throws IOException */ @Test public void decodeHostToHostIntent() throws IOException { JsonCodec<Intent> intentCodec = context.codec(Intent.class); assertThat(intentCodec, notNullValue()); Intent intent = getIntent("HostToHostIntent.json", intentCodec); assertThat(intent, notNullValue()); assertThat(intent, instanceOf(HostToHostIntent.class)); HostToHostIntent hostIntent = (HostToHostIntent) intent; assertThat(hostIntent.priority(), is(7)); assertThat(hostIntent.constraints(), hasSize(1)); }
/** 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)); }
public HostPair(Host src, Host dst) { this.src = src; this.dst = dst; this.intent = HostToHostIntent.builder() .appId(appId) .one(src.id()) .two(dst.id()) .selector(selector) .treatment(treatment) .constraints(constraint) .build(); }
@Override public void run() { TrafficSelector selector = DefaultTrafficSelector.emptySelector(); TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); List<Constraint> constraint = Lists.newArrayList(); List<Host> hosts = Lists.newArrayList(hostService.getHosts()); while (!hosts.isEmpty()) { Host src = hosts.remove(0); for (Host dst : hosts) { HostToHostIntent intent = HostToHostIntent.builder() .appId(appId) .one(src.id()) .two(dst.id()) .selector(selector) .treatment(treatment) .constraints(constraint) .build(); existingIntents.add(intent); intentService.submit(intent); } } }