use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class MQEventHandlerTest method testUpdateLink.
@Test
public void testUpdateLink() throws Exception {
Link link = createLink();
LinkEvent event = new LinkEvent(LINK_UPDATED, link, 123L);
validateEvent(event, LINK_UPDATED, link, 123L);
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class ECLinkStore method refreshLinkCache.
private LinkEvent refreshLinkCache(LinkKey linkKey) {
AtomicReference<LinkEvent.Type> eventType = new AtomicReference<>();
Link link = links.compute(linkKey, (key, existingLink) -> {
Link newLink = composeLink(linkKey);
if (newLink == null) {
return null;
}
if (existingLink == null) {
eventType.set(LINK_ADDED);
return newLink;
} else if (existingLink.state() != newLink.state() || existingLink.isExpected() != newLink.isExpected() || (existingLink.type() != newLink.type()) || !AnnotationsUtil.isEqual(existingLink.annotations(), newLink.annotations())) {
eventType.set(LINK_UPDATED);
return newLink;
} else {
return existingLink;
}
});
return eventType.get() != null ? new LinkEvent(eventType.get(), link) : null;
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class ECLinkStoreTest method testRemoveLink.
@Test
public final void testRemoveLink() {
final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
putLink(linkId1, DIRECT, A1);
putLink(linkId2, DIRECT, A2);
// DID1,P1 => DID2,P2
// DID2,P2 => DID1,P1
// DID1,P2 => DID2,P3
LinkEvent event = linkStore.removeLink(d1P1, d2P2);
assertEquals(LINK_REMOVED, event.type());
assertAnnotationsEquals(event.subject().annotations(), A1);
LinkEvent event2 = linkStore.removeLink(d1P1, d2P2);
assertNull(event2);
assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1));
assertAnnotationsEquals(linkStore.getLink(d2P2, d1P1).annotations(), A2);
// annotations, etc. should not survive remove
putLink(linkId1, DIRECT);
assertLink(linkId1, DIRECT, linkStore.getLink(d1P1, d2P2));
assertAnnotationsEquals(linkStore.getLink(d1P1, d2P2).annotations());
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class ECLinkStoreTest method testCreateOrUpdateLinkAncillary.
@Test
public final void testCreateOrUpdateLinkAncillary() {
ConnectPoint src = new ConnectPoint(DID1, P1);
ConnectPoint dst = new ConnectPoint(DID2, P2);
// add Ancillary link
LinkEvent event = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, INDIRECT, A1));
assertNotNull("Ancillary only link is ignored", event);
// add Primary link
LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, INDIRECT, A2));
assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject());
assertAnnotationsEquals(event2.subject().annotations(), A2, A1);
assertEquals(LINK_UPDATED, event2.type());
// update link type
LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2));
assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject());
assertAnnotationsEquals(event3.subject().annotations(), A2, A1);
assertEquals(LINK_UPDATED, event3.type());
// no change
LinkEvent event4 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT));
assertNull("No change event expected", event4);
// update link annotation (Primary)
LinkEvent event5 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2_2));
assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject());
assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1);
assertEquals(LINK_UPDATED, event5.type());
// update link annotation (Ancillary)
LinkEvent event6 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, DIRECT, A1_2));
assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject());
assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2);
assertEquals(LINK_UPDATED, event6.type());
// update link type (Ancillary) : ignored
LinkEvent event7 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, EDGE));
assertNull("Ancillary change other than annotation is ignored", event7);
}
use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.
the class VirtualNetworkTopologyProviderTest method testTopologyChanged.
/**
* Test the topologyChanged() method.
*/
@Test
public void testTopologyChanged() {
// Initial setup is two clusters of devices/links.
assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
// Adding this link will join the two clusters together.
List<Event> reasons = new ArrayList<>();
VirtualLink link = manager.createVirtualLink(virtualNetwork.id(), cp6, cp7);
virtualNetworkManagerStore.updateLink(link, link.tunnelId(), Link.State.ACTIVE);
VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp7, cp6);
virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link));
reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link2));
TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
topologyProvider.topologyListener.event(event);
// Wait for the topology changed event, and that the topologyChanged method was called.
try {
if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for topology changed event.");
}
} catch (InterruptedException e) {
fail("Semaphore exception." + e.getMessage());
}
// Validate that the topology changed method received a single cluster of connect points.
// This means that the two previous clusters have now joined into a single cluster.
assertEquals("The cluster count did not match.", 1, this.clusters.size());
assertEquals("The cluster count did not match.", 1, topologyService.currentTopology().clusterCount());
// Now remove the virtual link to split it back into two clusters.
manager.removeVirtualLink(virtualNetwork.id(), link.src(), link.dst());
manager.removeVirtualLink(virtualNetwork.id(), link2.src(), link2.dst());
assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
reasons = new ArrayList<>();
reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link));
reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2));
event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
topologyProvider.topologyListener.event(event);
// Wait for the topology changed event, and that the topologyChanged method was called.
try {
if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for topology changed event.");
}
} catch (InterruptedException e) {
fail("Semaphore exception." + e.getMessage());
}
// Validate that the topology changed method received two clusters of connect points.
// This means that the single previous clusters has now split into two clusters.
assertEquals("The cluster count did not match.", 2, this.clusters.size());
}
Aggregations