use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class ReactiveRoutingFib method setUpConnectivityHostToInternet.
@Override
public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix, IpAddress nextHopIpAddress) {
// Find the attachment point (egress interface) of the next hop
Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}", nextHopIpAddress);
return;
}
Set<Host> hosts = hostService.getHostsByIp(nextHopIpAddress);
if (hosts.isEmpty()) {
log.warn("No host found for next hop IP address");
return;
}
MacAddress nextHopMacAddress = null;
for (Host host : hosts) {
nextHopMacAddress = host.mac();
break;
}
hosts = hostService.getHostsByIp(hostIp);
if (hosts.isEmpty()) {
log.warn("No host found for host IP address");
return;
}
Host host = hosts.stream().findFirst().get();
ConnectPoint ingressPoint = host.location();
// Generate the intent itself
ConnectPoint egressPort = egressInterface.connectPoint();
log.debug("Generating intent for prefix {}, next hop mac {}", prefix, nextHopMacAddress);
// Match the destination IP prefix at the first hop
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (prefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(prefix);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(prefix);
}
// Rewrite the destination MAC address
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(nextHopMacAddress);
if (!egressInterface.vlan().equals(VlanId.NONE)) {
treatment.setVlanId(egressInterface.vlan());
// If we set VLAN ID, we have to make sure a VLAN tag exists.
// TODO support no VLAN -> VLAN routing
selector.matchVlanId(VlanId.ANY);
}
int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Key key = Key.of(prefix.toString() + "-reactive", appId);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(Collections.singleton(new FilteredConnectPoint(ingressPoint))).filteredEgressPoint(new FilteredConnectPoint(egressPort)).priority(priority).constraints(CONSTRAINTS).build();
submitReactiveIntent(prefix, intent);
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class IntentCycleCommand method generateIntents.
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Intent> intents = Lists.newArrayList();
for (long i = 0; i < count; i++) {
TrafficSelector selector = selectorBldr.matchEthSrc(MacAddress.valueOf(i + keyOffset)).build();
intents.add(PointToPointIntent.builder().appId(appId()).key(Key.of(i + keyOffset, appId())).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build());
}
return intents;
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class SinglePointToMultiPointIntentCodec method decode.
@Override
public SinglePointToMultiPointIntent decode(ObjectNode json, CodecContext context) {
SinglePointToMultiPointIntent.Builder builder = SinglePointToMultiPointIntent.builder();
IntentCodec.intentAttributes(json, context, builder);
ConnectivityIntentCodec.intentAttributes(json, context, builder);
ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT), INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
ConnectPoint ingress = context.codec(ConnectPoint.class).decode(ingressJson, context);
builder.filteredIngressPoint(new FilteredConnectPoint(ingress));
ArrayNode egressJson = nullIsIllegal((ArrayNode) json.get(EGRESS_POINT), EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
final JsonCodec<ConnectPoint> connectPointCodec = context.codec(ConnectPoint.class);
Set<FilteredConnectPoint> egressCp = new HashSet<>();
for (int i = 0; i < egressJson.size(); i++) {
ConnectPoint cp = connectPointCodec.decode(get(egressJson, i), context);
egressCp.add(new FilteredConnectPoint(cp));
}
builder.filteredEgressPoints(egressCp);
return builder.build();
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsForApplicationWithDetail.
/**
* Tests the result of the rest api GET when intents are defined and the detail flag is true.
*/
@Test
public void testIntentsForApplicationWithDetail() {
final Intent intent1 = PointToPointIntent.builder().key(Key.of(0, APP_ID)).appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
final HostToHostIntent intent2 = HostToHostIntent.builder().key(Key.of(1, APP_ID_2)).appId(APP_ID_2).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
intents.add(intent1);
List<Intent> appIntents1 = new ArrayList<>();
appIntents1.add(intent1);
intents.add(intent2);
List<Intent> appIntents2 = new ArrayList<>();
appIntents2.add(intent2);
expect(mockIntentService.getIntentsByAppId(APP_ID)).andReturn(appIntents1).anyTimes();
expect(mockIntentService.getIntentsByAppId(APP_ID_2)).andReturn(appIntents2).anyTimes();
replay(mockIntentService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID_2.name())).andReturn(APP_ID_2).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Verify intents for app_id
final String response1 = wt.path("intents/application/" + APP_ID.name()).queryParam("detail", true).request().get(String.class);
assertThat(response1, containsString("{\"intents\":["));
final JsonObject result1 = Json.parse(response1).asObject();
assertThat(result1, notNullValue());
assertThat(result1.names(), hasSize(1));
assertThat(result1.names().get(0), is("intents"));
final JsonArray jsonIntents1 = result1.get("intents").asArray();
assertThat(jsonIntents1, notNullValue());
assertThat(jsonIntents1.size(), is(1));
assertThat(jsonIntents1, hasIntent(intent1, true));
assertThat(jsonIntents1, is(not(hasIntent(intent2, true))));
// Verify intents for app_id_2
final String response2 = wt.path("intents/application/" + APP_ID_2.name()).queryParam("detail", true).request().get(String.class);
assertThat(response2, containsString("{\"intents\":["));
final JsonObject result2 = Json.parse(response2).asObject();
assertThat(result2, notNullValue());
assertThat(result2.names(), hasSize(1));
assertThat(result2.names().get(0), is("intents"));
final JsonArray jsonIntents2 = result2.get("intents").asArray();
assertThat(jsonIntents2, notNullValue());
assertThat(jsonIntents2.size(), is(1));
assertThat(jsonIntents2, hasIntent(intent2, true));
assertThat(jsonIntents2, is(not(hasIntent(intent1, true))));
}
use of org.onosproject.net.FilteredConnectPoint in project onos by opennetworkinglab.
the class TransportEndpointDescriptionTest method testConstruction.
@Test
public void testConstruction() {
FilteredConnectPoint output = new FilteredConnectPoint(NetTestTools.connectPoint("xxx", 1));
TransportEndpointDescription ted = TransportEndpointDescription.builder().withEnabled(true).withOutput(output).build();
assertThat(ted, notNullValue());
assertThat(ted.isEnabled(), is(true));
assertThat(ted.output(), is(output));
}
Aggregations