use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OpticalConnectivityTest method testCreate.
/**
* Checks the construction of OpticalConnectivity object.
*/
@Test
public void testCreate() {
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
// Mock 3-nodes linear topology
ConnectPoint cp12 = createConnectPoint(1, 2);
ConnectPoint cp21 = createConnectPoint(2, 1);
ConnectPoint cp22 = createConnectPoint(2, 2);
ConnectPoint cp31 = createConnectPoint(3, 1);
Link link1 = createLink(cp12, cp21);
Link link2 = createLink(cp22, cp31);
List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency, Collections.emptySet(), Collections.emptySet());
assertNotNull(oc);
assertEquals(oc.id(), cid);
assertEquals(oc.links(), links);
assertEquals(oc.bandwidth(), bandwidth);
assertEquals(oc.latency(), latency);
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OpticalConnectivityTest method testLinkEstablishedByConnectivityIntent.
/**
* Checks that isAllRealizingLink(Not)Established works for OpticalConnectivityIntent.
*/
@Test
public void testLinkEstablishedByConnectivityIntent() {
// Mock 7-nodes linear topology
ConnectPoint cp12 = createConnectPoint(1, 2);
ConnectPoint cp21 = createConnectPoint(2, 1);
ConnectPoint cp22 = createConnectPoint(2, 2);
ConnectPoint cp31 = createConnectPoint(3, 1);
ConnectPoint cp32 = createConnectPoint(3, 2);
ConnectPoint cp41 = createConnectPoint(4, 1);
ConnectPoint cp42 = createConnectPoint(4, 2);
ConnectPoint cp51 = createConnectPoint(5, 1);
ConnectPoint cp52 = createConnectPoint(5, 2);
ConnectPoint cp61 = createConnectPoint(6, 1);
ConnectPoint cp62 = createConnectPoint(6, 2);
ConnectPoint cp71 = createConnectPoint(7, 1);
Link link1 = createLink(cp12, cp21);
Link link2 = createLink(cp22, cp31);
Link link3 = createLink(cp32, cp41);
Link link4 = createLink(cp42, cp51);
Link link5 = createLink(cp52, cp61);
Link link6 = createLink(cp62, cp71);
List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
// Mocks 2 intents to create OduCtl connectivity
OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41, connIntent1);
OpticalConnectivityIntent connIntent2 = createConnectivityIntent(cp51, cp62);
PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71, connIntent2);
Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, plinks, Collections.emptySet());
assertTrue(oc1.isAllRealizingLinkNotEstablished());
assertFalse(oc1.isAllRealizingLinkEstablished());
// Sets link realized by connIntent1 to be established
OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
assertFalse(oc2.isAllRealizingLinkNotEstablished());
assertFalse(oc2.isAllRealizingLinkEstablished());
// Sets link realized by connIntent2 to be established
OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
assertFalse(oc3.isAllRealizingLinkNotEstablished());
assertTrue(oc3.isAllRealizingLinkEstablished());
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OpticalPathProvisionerTest method testGetPath.
/**
* Checks getPath method works.
*/
@Test
public void testGetPath() {
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
Optional<List<Link>> path = target.getPath(cid);
// Checks returned path is as expected
assertTrue(path.isPresent());
assertEquals(links, path.get());
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class EventsCommand method printEvent.
private void printEvent(Event<?, ?> event) {
if (event instanceof DeviceEvent) {
DeviceEvent deviceEvent = (DeviceEvent) event;
if (event.type().toString().startsWith("PORT")) {
// Port event
print("%s %s\t%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.port().number(), deviceEvent.port());
} else {
// Device event
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.subject());
}
} else if (event instanceof MastershipEvent) {
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), ((MastershipEvent) event).roleInfo());
} else if (event instanceof LinkEvent) {
LinkEvent linkEvent = (LinkEvent) event;
Link link = linkEvent.subject();
print("%s %s\t%s/%s-%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link);
} else if (event instanceof HostEvent) {
HostEvent hostEvent = (HostEvent) event;
print("%s %s\t%s [%s->%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), hostEvent.subject().id(), hostEvent.prevSubject(), hostEvent.subject());
} else if (event instanceof TopologyEvent) {
TopologyEvent topoEvent = (TopologyEvent) event;
List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
Topology topo = topoEvent.subject();
String summary = String.format("(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(), topo.clusterCount());
print("%s %s%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), summary, reasons.stream().map(e -> e.type()).collect(toList()));
} else if (event instanceof ClusterEvent) {
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), ((ClusterEvent) event).subject().id(), event.subject());
} else {
// Unknown Event?
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), event);
}
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class EventsCommand method doExecute.
@Override
protected void doExecute() {
EventHistoryService eventHistoryService = get(EventHistoryService.class);
Stream<Event<?, ?>> events = eventHistoryService.history().stream();
boolean dumpAll = all || !(mastership || device || link || topology || host || cluster || intent);
if (!dumpAll) {
Predicate<Event<?, ?>> filter = (defaultIs) -> false;
if (mastership) {
filter = filter.or(evt -> evt instanceof MastershipEvent);
}
if (device) {
filter = filter.or(evt -> evt instanceof DeviceEvent);
}
if (link) {
filter = filter.or(evt -> evt instanceof LinkEvent);
}
if (topology) {
filter = filter.or(evt -> evt instanceof TopologyEvent);
}
if (host) {
filter = filter.or(evt -> evt instanceof HostEvent);
}
if (cluster) {
filter = filter.or(evt -> evt instanceof ClusterEvent);
}
if (intent) {
filter = filter.or(evt -> evt instanceof IntentEvent);
}
events = events.filter(filter);
}
if (maxSize > 0) {
events = events.limit(maxSize);
}
if (outputJson()) {
ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
printJson(jsonEvents);
} else {
events.forEach(this::printEvent);
}
}
Aggregations