use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class PeerConnectivityManagerTest method testConnectionSetup.
/**
* Tests whether peer connectivity manager can set up correct BGP and
* ICMP intents according to specific configuration.
* <p/>
* Two tricky cases included in the configuration are: 2 peers on a same
* switch port, peer on the same switch with BGPd.
*/
@Test
public void testConnectionSetup() {
reset(intentSynchronizer);
// Setup the expected intents
for (Intent intent : intentList) {
intentSynchronizer.submit(eqExceptId(intent));
}
replay(intentSynchronizer);
// Running the interface to be tested.
peerConnectivityManager.start();
verify(intentSynchronizer);
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class SimpleFabricRouting method dump.
// Dump Cli Handler
private void dump(String subject, PrintStream out) {
if ("intents".equals(subject)) {
out.println("Routing Route Intents:\n");
for (Intent entry : intentService.getIntents()) {
if (appId.equals(entry.appId())) {
MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
out.println(" " + intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
}
}
out.println("");
out.println("Routing Intercept Flow Rules:\n");
List<FlowRule> rules = new ArrayList(interceptFlowRules);
Collections.sort(rules, new Comparator<FlowRule>() {
@Override
public int compare(FlowRule a, FlowRule b) {
int r = a.deviceId().toString().compareTo(b.deviceId().toString());
// descending on priority
return (r != 0) ? r : Integer.compare(b.priority(), a.priority());
}
});
for (FlowRule rule : rules) {
out.println(" device=" + rule.deviceId().toString() + " priority=" + rule.priority() + " selector=" + rule.selector().criteria().toString());
}
out.println("");
out.println("Routing Intents to Be Purged:\n");
for (Key key : toBePurgedIntentKeys) {
out.println(" " + key.toString());
}
out.println("");
} else if ("reactive-intents".equals(subject)) {
for (Intent entry : intentService.getIntents()) {
if (appId.equals(entry.appId())) {
MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
out.println(intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
}
}
}
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class SimpleFabricRouting method withdrawAllReactiveIntents.
public void withdrawAllReactiveIntents() {
// check all intents of this app
// NOTE: cli calls are handling within the cli called node only; so should not user inents.isLocal()
Set<Intent> myIntents = new HashSet<>();
for (Intent intent : intentService.getIntents()) {
if (appId.equals(intent.appId())) {
myIntents.add(intent);
}
}
// withdraw all my intents
for (Intent intent : myIntents) {
switch(intentService.getIntentState(intent.key())) {
case FAILED:
intentService.purge(intent);
toBePurgedIntentKeys.add(intent.key());
break;
case WITHDRAWN:
intentService.purge(intent);
toBePurgedIntentKeys.add(intent.key());
break;
case INSTALL_REQ:
case INSTALLED:
case INSTALLING:
case RECOMPILING:
case COMPILING:
intentService.withdraw(intent);
toBePurgedIntentKeys.add(intent.key());
break;
case WITHDRAW_REQ:
case WITHDRAWING:
toBePurgedIntentKeys.add(intent.key());
break;
case PURGE_REQ:
case CORRUPT:
default:
// no action
break;
}
}
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class SimpleFabricRouting method refreshRouteIntents.
/**
* Refresh routes by examining network resource status.
*/
private void refreshRouteIntents() {
for (Intent entry : intentService.getIntents()) {
if (!appId.equals(entry.appId())) {
continue;
}
MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
if (!intentService.isLocal(intent.key())) {
if (toBePurgedIntentKeys.contains(intent.key())) {
// clear non local intent
toBePurgedIntentKeys.remove(intent.key());
}
continue;
}
try {
switch(intentService.getIntentState(intent.key())) {
// case FAILED: // failed intent is not auto removed
case WITHDRAWN:
log.warn("intent found failed or withdrawn; " + "remove and try to purge intent: key={}", intent.key());
// purge intents here without withdraw
intentService.purge(intentService.getIntent(intent.key()));
toBePurgedIntentKeys.add(intent.key());
continue;
default:
// no action
break;
}
} catch (Exception e) {
log.warn("intent status lookup failed: error={}", e);
// this intent seems invalid; no action
continue;
}
// dummy loop to break on remove cases
if (!deviceService.isAvailable(intent.egressPoint().deviceId())) {
log.info("refresh route intents; remove intent for no device: key={}", intent.key());
intentService.withdraw(intentService.getIntent(intent.key()));
toBePurgedIntentKeys.add(intent.key());
continue;
}
if (!(simpleFabric.fabricNetwork(intent.egressPoint(), VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getEgressLinks(intent.egressPoint()).isEmpty()))) {
log.info("refresh route intents; remove intent for egress point not available: key={}", intent.key());
intentService.withdraw(intentService.getIntent(intent.key()));
toBePurgedIntentKeys.add(intent.key());
continue;
}
// MAY NEED TO CHECK: intent.egressPoint and intent.treatment's dstMac is valid against hosts
if (REACTIVE_SINGLE_TO_SINGLE && !REACTIVE_ALLOW_LINK_CP) {
// single path intent only; no need to check ingress points
continue;
}
Set<FilteredConnectPoint> newIngressPoints = new HashSet<>();
boolean ingressPointChanged = false;
for (FilteredConnectPoint cp : intent.filteredIngressPoints()) {
if (deviceService.isAvailable(cp.connectPoint().deviceId()) && (simpleFabric.fabricNetwork(cp.connectPoint(), VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getIngressLinks(cp.connectPoint()).isEmpty()))) {
newIngressPoints.add(cp);
} else {
log.info("refresh route ingress cp of " + "not in 2Networks nor links: {}", cp);
ingressPointChanged = true;
}
}
if (newIngressPoints.isEmpty()) {
log.info("refresh route intents; " + "remove intent for no ingress nor egress point available: key={}", intent.key());
intentService.withdraw(intentService.getIntent(intent.key()));
toBePurgedIntentKeys.add(intent.key());
continue;
}
// update ingress points
if (ingressPointChanged) {
MultiPointToSinglePointIntent updatedIntent = MultiPointToSinglePointIntent.builder().appId(appId).key(intent.key()).selector(intent.selector()).treatment(intent.treatment()).filteredIngressPoints(newIngressPoints).filteredEgressPoint(intent.filteredEgressPoint()).priority(intent.priority()).constraints(intent.constraints()).build();
log.info("refresh route update intent: key={} updatedIntent={}", intent.key(), updatedIntent);
// may remove from old purged entry
toBePurgedIntentKeys.remove(intent.key());
intentService.submit(updatedIntent);
}
}
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class SimpleFabricRouting method checkIntentsPurge.
private void checkIntentsPurge() {
// check intents to be purge
if (!toBePurgedIntentKeys.isEmpty()) {
Set<Key> removeKeys = new HashSet<>();
for (Key key : toBePurgedIntentKeys) {
if (!intentService.isLocal(key)) {
removeKeys.add(key);
continue;
}
Intent intentToPurge = intentService.getIntent(key);
if (intentToPurge == null) {
log.info("purged intent: key={}", key);
removeKeys.add(key);
} else {
switch(intentService.getIntentState(key)) {
// case FAILED: // not auto removed
case WITHDRAWN:
log.info("try to purge intent: key={}", key);
intentService.purge(intentToPurge);
break;
case INSTALL_REQ:
case INSTALLED:
case INSTALLING:
case RECOMPILING:
case COMPILING:
log.warn("not to purge for active intent: key={}", key);
removeKeys.add(key);
break;
case WITHDRAW_REQ:
case WITHDRAWING:
case PURGE_REQ:
case CORRUPT:
default:
// no action
break;
}
}
}
toBePurgedIntentKeys.removeAll(removeKeys);
}
}
Aggregations