use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method decode.
private Intent decode(ObjectNode json) {
JsonNode ingressJson = json.get(INGRESS_POINT);
if (!ingressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
JsonNode egressJson = json.get(EGRESS_POINT);
if (!egressJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
}
ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
JsonNode signalJson = json.get(SIGNAL);
OchSignal signal = null;
if (signalJson != null) {
if (!signalJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
signal = OchSignalCodec.decode((ObjectNode) signalJson);
}
}
String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
CoreService service = getService(CoreService.class);
ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
Key key = null;
DeviceService deviceService = get(DeviceService.class);
JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
DefaultPath suggestedPath = null;
LinkService linkService = get(LinkService.class);
if (suggestedPathJson != null) {
if (!suggestedPathJson.isObject()) {
throw new IllegalArgumentException(JSON_INVALID);
} else {
ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
List<Link> listLinks = new ArrayList<>();
for (JsonNode node : linksJson) {
String srcString = node.get("src").asText();
String dstString = node.get("dst").asText();
ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
if (link == null) {
throw new IllegalArgumentException("Not existing link in the suggested path");
}
listLinks.add(link);
}
if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
}
if (!isPathContiguous(listLinks)) {
throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
}
suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
}
}
return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class SimpleFabricForwarding method checkIntentsPurge.
private void checkIntentsPurge() {
// check intents to be purge
if (!toBePurgedIntentKeys.isEmpty()) {
Set<Key> purgedKeys = new HashSet<>();
for (Key key : toBePurgedIntentKeys) {
Intent intentToPurge = intentService.getIntent(key);
if (intentToPurge == null) {
log.info("simple fabric forwarding purged intent: key={}", key.toString());
purgedKeys.add(key);
} else {
switch(intentService.getIntentState(key)) {
case FAILED:
case WITHDRAWN:
log.info("simple fabric forwarding try to purge intent: key={}", key.toString());
intentService.purge(intentToPurge);
break;
case INSTALL_REQ:
case INSTALLED:
case INSTALLING:
case RECOMPILING:
case COMPILING:
log.warn("simple fabric forwarding withdraw intent to purge: key={}", key);
intentService.withdraw(intentToPurge);
break;
case WITHDRAW_REQ:
case WITHDRAWING:
case PURGE_REQ:
case CORRUPT:
default:
// no action
break;
}
}
}
toBePurgedIntentKeys.removeAll(purgedKeys);
}
}
use of org.onosproject.net.intent.Key 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.Key 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.Key in project onos by opennetworkinglab.
the class ConnectivityManager method setUpL2.
@Override
public void setUpL2(Peer peer) {
if (!castorStore.getLayer2Intents().isEmpty()) {
updateExistingL2Intents(peer);
}
Set<FilteredConnectPoint> ingressPorts = new HashSet<>();
ConnectPoint egressPort = ConnectPoint.deviceConnectPoint(peer.getPort());
for (Peer inPeer : castorStore.getAllPeers()) {
if (!inPeer.getName().equals(peer.getName())) {
ingressPorts.add(new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(inPeer.getPort())));
}
}
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
MacAddress macAddress = castorStore.getAddressMap().get(IpAddress.valueOf(peer.getIpAddress()));
selector.matchEthDst(macAddress);
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
Key key = Key.of(peer.getIpAddress(), appId);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment).filteredIngressPoints(ingressPorts).filteredEgressPoint(new FilteredConnectPoint(egressPort)).priority(FLOW_PRIORITY).build();
intentSynchronizer.submit(intent);
castorStore.storeLayer2Intent(peer.getIpAddress(), intent);
castorStore.removeCustomer(peer);
peer.setL2(true);
castorStore.storeCustomer(peer);
}
Aggregations