use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testNonTrivialSelectorsIntent.
/**
* Tests selector, filtered ingress and egress.
*/
@Test
public void testNonTrivialSelectorsIntent() {
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1), DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).build()), new FilteredConnectPoint(new ConnectPoint(DID_2, PORT_1), DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("200")).build()));
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf("192.168.100.0/24")).build();
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, ipPrefixSelector);
String[] hops = { S3 };
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(3));
assertThat(linkIntent.links(), linksHasPath(S1, S3));
assertThat(linkIntent.links(), linksHasPath(S2, S3));
assertThat(linkIntent.links(), linksHasPath(S3, S4));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class ReactiveRoutingFib method setUpConnectivityHostToHost.
@Override
public void setUpConnectivityHostToHost(IpAddress dstIpAddress, IpAddress srcIpAddress, MacAddress srcMacAddress, ConnectPoint srcConnectPoint) {
checkNotNull(dstIpAddress);
checkNotNull(srcIpAddress);
checkNotNull(srcMacAddress);
checkNotNull(srcConnectPoint);
IpPrefix srcIpPrefix = srcIpAddress.toIpPrefix();
IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
ConnectPoint dstConnectPoint = null;
MacAddress dstMacAddress = null;
for (Host host : hostService.getHostsByIp(dstIpAddress)) {
if (host.mac() != null) {
dstMacAddress = host.mac();
dstConnectPoint = host.location();
break;
}
}
if (dstMacAddress == null) {
hostService.startMonitoringIp(dstIpAddress);
return;
}
//
// Handle intent from source host to destination host
//
MultiPointToSinglePointIntent srcToDstIntent = hostToHostIntentGenerator(dstIpAddress, dstConnectPoint, dstMacAddress, srcConnectPoint);
submitReactiveIntent(dstIpPrefix, srcToDstIntent);
// first.
if (mp2pIntentExists(srcIpPrefix)) {
updateExistingMp2pIntent(srcIpPrefix, dstConnectPoint);
return;
} else {
// There is no existing intent, create a new one.
MultiPointToSinglePointIntent dstToSrcIntent = hostToHostIntentGenerator(srcIpAddress, srcConnectPoint, srcMacAddress, dstConnectPoint);
submitReactiveIntent(srcIpPrefix, dstToSrcIntent);
}
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent 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.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class ReactiveRoutingFib method setUpConnectivityInternetToHost.
@Override
public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
checkNotNull(hostIpAddress);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (hostIpAddress.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
}
// Match the destination IP prefix at the first hop
IpPrefix ipPrefix = hostIpAddress.toIpPrefix();
selector.matchIPDst(ipPrefix);
// Rewrite the destination MAC address
MacAddress hostMac = null;
FilteredConnectPoint egressPoint = null;
for (Host host : hostService.getHostsByIp(hostIpAddress)) {
if (host.mac() != null) {
hostMac = host.mac();
egressPoint = new FilteredConnectPoint(host.location());
break;
}
}
if (hostMac == null) {
hostService.startMonitoringIp(hostIpAddress);
return;
}
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(hostMac);
Key key = Key.of(ipPrefix.toString(), appId);
int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Set<ConnectPoint> interfaceConnectPoints = interfaceService.getInterfaces().stream().map(intf -> intf.connectPoint()).collect(Collectors.toSet());
if (interfaceConnectPoints.isEmpty()) {
log.error("The interface connect points are empty!");
return;
}
Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
for (ConnectPoint connectPoint : interfaceConnectPoints) {
if (!connectPoint.equals(egressPoint.connectPoint())) {
ingressPoints.add(new FilteredConnectPoint(connectPoint));
}
}
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(egressPoint).priority(priority).constraints(CONSTRAINTS).build();
log.trace("Generates ConnectivityInternetToHost intent {}", intent);
submitReactiveIntent(ipPrefix, intent);
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class ReactiveRoutingFib method hostToHostIntentGenerator.
/**
* Generates MultiPointToSinglePointIntent for both source host and
* destination host located in local SDN network.
*
* @param dstIpAddress the destination IP address
* @param dstConnectPoint the destination host connect point
* @param dstMacAddress the MAC address of destination host
* @param srcConnectPoint the connect point where packet-in from
* @return the generated MultiPointToSinglePointIntent
*/
private MultiPointToSinglePointIntent hostToHostIntentGenerator(IpAddress dstIpAddress, ConnectPoint dstConnectPoint, MacAddress dstMacAddress, ConnectPoint srcConnectPoint) {
checkNotNull(dstIpAddress);
checkNotNull(dstConnectPoint);
checkNotNull(dstMacAddress);
checkNotNull(srcConnectPoint);
Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
ingressPoints.add(new FilteredConnectPoint(srcConnectPoint));
IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (dstIpAddress.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(dstIpPrefix);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(dstIpPrefix);
}
// Rewrite the destination MAC address
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(dstMacAddress);
Key key = Key.of(dstIpPrefix.toString(), appId);
int priority = dstIpPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).priority(priority).constraints(CONSTRAINTS).build();
log.trace("Generates ConnectivityHostToHost = {} ", intent);
return intent;
}
Aggregations