use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class SimpleFabricRouting method setUpConnectivity.
/**
* Update intents for connectivity.
*
* ToHost: dstPrefix = dstHostIp.toIpPrefix(), nextHopIp = destHostIp
* ToInternet: dstPrefix = route.prefix(), nextHopIp = route.nextHopIp
* returns intent submitted or not
*/
private boolean setUpConnectivity(ConnectPoint srcCp, byte ipProto, IpPrefix srcPrefix, IpPrefix dstPrefix, IpAddress nextHopIp, MacAddress treatmentSrcMac, EncapsulationType encap, boolean updateMac, boolean isDstLocalSubnet, int borderRoutePrefixLength) {
if (!(simpleFabric.fabricNetwork(srcCp, VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getIngressLinks(srcCp).isEmpty()))) {
log.warn("NO REGI for srcCp not in DefaultFabricNetwork; srcCp={} srcPrefix={} dstPrefix={} nextHopIp={}", srcCp, srcPrefix, dstPrefix, nextHopIp);
return false;
}
MacAddress nextHopMac = null;
ConnectPoint egressPoint = null;
for (Host host : hostService.getHostsByIp(nextHopIp)) {
if (host.mac() != null) {
nextHopMac = host.mac();
egressPoint = host.location();
break;
}
}
if (nextHopMac == null || egressPoint == null) {
log.info("NO REGI for unknown nextHop Cp and Mac: srcPrefix={} dstPrefix={} nextHopIp={}", srcPrefix, dstPrefix, nextHopIp);
hostService.startMonitoringIp(nextHopIp);
simpleFabric.requestMac(nextHopIp);
return false;
}
TrafficTreatment treatment;
if (updateMac && ALLOW_ETH_ADDRESS_SELECTOR) {
treatment = generateSetMacTreatment(nextHopMac, treatmentSrcMac);
} else {
treatment = DefaultTrafficTreatment.builder().build();
}
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (dstPrefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
if (REACTIVE_SINGLE_TO_SINGLE && srcPrefix.prefixLength() > 0) {
selector.matchIPSrc(srcPrefix);
}
if (dstPrefix.prefixLength() > 0) {
selector.matchIPDst(dstPrefix);
}
if (ipProto != 0 && REACTIVE_MATCH_IP_PROTO) {
selector.matchIPProtocol(ipProto);
}
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
if (REACTIVE_SINGLE_TO_SINGLE && srcPrefix.prefixLength() > 0) {
selector.matchIPv6Src(srcPrefix);
}
if (dstPrefix.prefixLength() > 0) {
selector.matchIPv6Dst(dstPrefix);
}
if (ipProto != 0 && REACTIVE_MATCH_IP_PROTO) {
selector.matchIPProtocol(ipProto);
}
}
Key key;
String keyProtoTag = "";
if (REACTIVE_MATCH_IP_PROTO) {
keyProtoTag = "-p" + ipProto;
}
if (REACTIVE_SINGLE_TO_SINGLE) {
// allocate intent per (srcPrefix, dstPrefix)
key = Key.of(srcPrefix.toString() + "-to-" + dstPrefix.toString() + keyProtoTag, appId);
} else {
// allocate intent per (srcDeviceId, dstPrefix)
key = Key.of(srcCp.deviceId().toString() + "-to-" + dstPrefix.toString() + keyProtoTag, appId);
}
// check and merge already existing ingress points
Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
MultiPointToSinglePointIntent existingIntent = (MultiPointToSinglePointIntent) intentService.getIntent(key);
if (existingIntent != null) {
ingressPoints.addAll(existingIntent.filteredIngressPoints());
if (// alread exists and dst not changed
!ingressPoints.add(new FilteredConnectPoint(srcCp)) && egressPoint.equals(existingIntent.egressPoint()) && treatment.equals(existingIntent.treatment())) {
log.warn("srcCP is already in mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
return false;
}
log.info("update mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
} else {
log.info("create mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
ingressPoints.add(new FilteredConnectPoint(srcCp));
}
// priority for forwarding case
int priority = reactivePriority(true, isDstLocalSubnet, borderRoutePrefixLength);
MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder().key(key).appId(appId).selector(selector.build()).treatment(treatment).filteredIngressPoints(ingressPoints).filteredEgressPoint(new FilteredConnectPoint(egressPoint)).priority(priority).constraints(buildConstraints(reactiveConstraints, encap)).build();
log.info("submit mp2p intent: srcPrefix={} dstPrefix={} srcCp={} " + "newIntent={} nextHopIp={} nextHopMac={} priority={}", srcPrefix, dstPrefix, ingressPoints, newIntent, nextHopIp, nextHopMac, priority);
toBePurgedIntentKeys.remove(newIntent.key());
intentService.submit(newIntent);
return true;
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class SdnIpFib method addInterface.
private void addInterface(Interface intf) {
synchronized (this) {
for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
// Retrieve the IP prefix and affected intent
IpPrefix prefix = entry.getKey();
MultiPointToSinglePointIntent intent = entry.getValue();
// Add new ingress FilteredConnectPoint
Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(intent.filteredIngressPoints());
// Create the new traffic selector
TrafficSelector.Builder selector = buildIngressTrafficSelector(intf, prefix);
// Create the Filtered ConnectPoint and add it to the existing set
FilteredConnectPoint newIngressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), selector.build());
ingressFilteredCPs.add(newIngressFilteredCP);
// Create new intent
MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder(intent).filteredIngressPoints(ingressFilteredCPs).build();
routeIntents.put(entry.getKey(), newIntent);
intentSynchronizer.submit(newIntent);
}
}
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class SdnIpFib method withdraw.
private void withdraw(ResolvedRoute route) {
synchronized (this) {
IpPrefix prefix = route.prefix();
MultiPointToSinglePointIntent intent = routeIntents.remove(prefix);
if (intent == null) {
log.trace("No intent in routeIntents to delete for prefix: {}", prefix);
return;
}
intentSynchronizer.withdraw(intent);
}
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class SdnIpFib method generateRouteIntent.
/**
* Generates a route intent for a prefix, the next hop IP address, and
* the next hop MAC address.
* <p/>
* This method will find the egress interface for the intent.
* Intent will match dst IP prefix and rewrite dst MAC address at all other
* border switches, then forward packets according to dst MAC address.
*
* @param prefix the IP prefix of the route to add
* @param nextHopIpAddress the IP address of the next hop
* @param nextHopMacAddress the MAC address of the next hop
* @param encap the encapsulation type in use
* @return the generated intent, or null if no intent should be submitted
*/
private MultiPointToSinglePointIntent generateRouteIntent(IpPrefix prefix, IpAddress nextHopIpAddress, MacAddress nextHopMacAddress, EncapsulationType encap) {
// 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 null;
}
ConnectPoint egressPort = egressInterface.connectPoint();
log.debug("Generating intent for prefix {}, next hop mac {}", prefix, nextHopMacAddress);
Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
// TODO this should be only peering interfaces
interfaceService.getInterfaces().forEach(intf -> {
// Get ony ingress interfaces with IPs configured
if (validIngressIntf(intf, egressInterface)) {
TrafficSelector.Builder selector = buildIngressTrafficSelector(intf, prefix);
FilteredConnectPoint ingressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), selector.build());
ingressFilteredCPs.add(ingressFilteredCP);
}
});
// Build treatment: rewrite the destination MAC address
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(nextHopMacAddress);
// Build the egress selector for VLAN Id
TrafficSelector.Builder selector = buildTrafficSelector(egressInterface);
FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(egressPort, selector.build());
// Set priority
int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
// Set key
Key key = Key.of(prefix.toString(), appId);
MultiPointToSinglePointIntent.Builder intentBuilder = MultiPointToSinglePointIntent.builder().appId(appId).key(key).filteredIngressPoints(ingressFilteredCPs).filteredEgressPoint(egressFilteredCP).treatment(treatment.build()).priority(priority).constraints(CONSTRAINTS);
setEncap(intentBuilder, CONSTRAINTS, encap);
return intentBuilder.build();
}
use of org.onosproject.net.intent.MultiPointToSinglePointIntent in project onos by opennetworkinglab.
the class SdnIpFibTest method createIntentToOne.
/*
* Builds a MultiPointToSinglePointIntent with dest sw1 (VLAN Id) and src
* sw2, sw3.
*/
private MultiPointToSinglePointIntent createIntentToOne(IpPrefix ipPrefix) {
// Build the expected treatment
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
treatmentBuilder.setEthDst(MAC1);
// Build the expected egress FilteredConnectPoint
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchVlanId(VLAN10);
FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW1_ETH1, selector.build());
// Build the expected selectors
Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet();
// Build the expected ingress FilteredConnectPoint for sw2
selector = DefaultTrafficSelector.builder();
selector.matchVlanId(VLAN20);
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(ipPrefix);
FilteredConnectPoint ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build());
ingressFilteredCPs.add(ingressFilteredCP);
// Build the expected ingress FilteredConnectPoint for sw3
selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(ipPrefix);
ingressFilteredCP = new FilteredConnectPoint(SW3_ETH1, selector.build());
ingressFilteredCPs.add(ingressFilteredCP);
// Build the expected intent
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(APPID).key(Key.of(ipPrefix.toString(), APPID)).filteredIngressPoints(ingressFilteredCPs).filteredEgressPoint(egressFilteredCP).treatment(treatmentBuilder.build()).constraints(SdnIpFib.CONSTRAINTS).build();
return intent;
}
Aggregations