use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class ProtectedTransportIntentCompiler method createFreshProtectedPaths.
/**
* Creates new protected paths.
*
* @param intent original intention
* @param did1 identifier of first device
* @param did2 identifier of second device
* @return compilation result
* @throws IntentCompilationException when there's no satisfying path.
*/
private List<Intent> createFreshProtectedPaths(ProtectedTransportIntent intent, DeviceId did1, DeviceId did2) {
DisjointPath disjointPath = getDisjointPath(intent, did1, did2);
if (disjointPath == null || disjointPath.backup() == null) {
log.error("Unable to find disjoint path between {}, {}", did1, did2);
throw new IntentCompilationException("Unable to find disjoint paths.");
}
Path primary = disjointPath.primary();
Path secondary = disjointPath.backup();
String fingerprint = intent.key().toString();
// pick and allocate Vlan to use as S-tag
Pair<VlanId, VlanId> vlans = allocateEach(intent, primary, secondary, VlanId.class);
VlanId primaryVlan = vlans.getLeft();
VlanId secondaryVlan = vlans.getRight();
// Build edge Intents for head/tail
// resource for head/tail
Collection<NetworkResource> oneResources = new ArrayList<>();
Collection<NetworkResource> twoResources = new ArrayList<>();
List<TransportEndpointDescription> onePaths = new ArrayList<>();
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.src(), primaryVlan)).build());
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.src(), secondaryVlan)).build());
List<TransportEndpointDescription> twoPaths = new ArrayList<>();
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.dst(), primaryVlan)).build());
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.dst(), secondaryVlan)).build());
ProtectionEndpointIntent oneIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(oneResources).deviceId(did1).description(buildDescription(onePaths, did2, fingerprint)).build();
ProtectionEndpointIntent twoIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).resources(twoResources).deviceId(did2).description(buildDescription(twoPaths, did1, fingerprint)).build();
// Build transit intent for primary/secondary path
Collection<NetworkResource> resources1 = ImmutableList.of(marker("protection1"));
Collection<NetworkResource> resources2 = ImmutableList.of(marker("protection2"));
ImmutableList<Intent> result = ImmutableList.<Intent>builder().addAll(createTransitIntent(intent, primary, primaryVlan, resources1)).addAll(createTransitIntent(intent, secondary, secondaryVlan, resources2)).add(oneIntent).add(twoIntent).build();
log.trace("createFreshProtectedPaths result: {}", result);
return result;
}
use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class FlowRuleIntentInstaller method createIngressToEgressDeviceList.
/**
* Create a list of devices ordered from the ingress to the egress of a path.
* @param resources the resources of the intent
* @return a list of devices
*/
private List<DeviceId> createIngressToEgressDeviceList(Collection<NetworkResource> resources) {
List<DeviceId> deviceIds = Lists.newArrayList();
List<Link> links = Lists.newArrayList();
for (NetworkResource resource : resources) {
if (resource instanceof Link) {
Link linkToAdd = (Link) resource;
if (linkToAdd.type() != Link.Type.EDGE) {
links.add(linkToAdd);
}
}
}
Collections.sort(links, LINK_COMPARATOR);
int i = 0;
for (Link orderedLink : links) {
deviceIds.add(orderedLink.src().deviceId());
if (i == resources.size() - 1) {
deviceIds.add(orderedLink.dst().deviceId());
}
i++;
}
return deviceIds;
}
use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventLinkDownMatch.
/**
* Tests an event for a link down where the link matches existing intents.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventLinkDownMatch() throws Exception {
final Link link = link("src", 1, "dst", 2);
final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
reasons.add(linkEvent);
final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
final Key key = Key.of(0x333L, APP_ID);
Collection<NetworkResource> resources = ImmutableSet.of(link);
tracker.addTrackedResources(key, resources);
listener.event(event);
assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
assertThat(delegate.intentIdsFromEvent, hasSize(1));
assertThat(delegate.compileAllFailedFromEvent, is(false));
assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class FlowObjectiveIntentInstallerTest method createFlowObjectiveIntents.
/**
* Creates flow objective Intents.
*
* @return the flow objective intents
*/
private List<Intent> createFlowObjectiveIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
List<Objective> objectives = ImmutableList.of(filt, next, fwd);
List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
return ImmutableList.of(intent);
}
use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createFlowRuleIntentsNonDisruptive.
/**
* Generates FlowRuleIntents for testing non-disruptive reallocation.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createFlowRuleIntentsNonDisruptive() {
Map<ConnectPoint, ConnectPoint> portsAssociation = Maps.newHashMap();
portsAssociation.put(CP1, CP2);
portsAssociation.put(CP2_1, CP2_2);
portsAssociation.put(CP4_2, CP4_1);
List<FlowRule> flowRules = Lists.newArrayList();
for (ConnectPoint srcPoint : portsAssociation.keySet()) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(srcPoint.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portsAssociation.get(srcPoint).port()).build();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(srcPoint.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
flowRules.add(flowRule);
}
List<NetworkResource> resources = ImmutableList.of(S1_S2, S2_S4);
FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, flowRules, resources, PathIntent.ProtectionType.PRIMARY, RG1);
List<Intent> flowRuleIntents = Lists.newArrayList();
flowRuleIntents.add(intent);
return flowRuleIntents;
}
Aggregations