org.onosproject.net.link.LinkEvent Java Examples
The following examples show how to use
org.onosproject.net.link.LinkEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ECLinkStore.java From onos with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: SimpleLinkStore.java From onos with Apache License 2.0 | 6 votes |
@Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { LinkKey key = linkKey(linkDescription.src(), linkDescription.dst()); Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key); synchronized (descs) { final Link oldLink = links.get(key); // update description createOrUpdateLinkDescription(descs, providerId, linkDescription); final Link newLink = composeLink(descs); if (oldLink == null) { return createLink(key, newLink); } return updateLink(key, oldLink, newLink); } }
Example #3
Source File: SimpleLinkStore.java From onos with Apache License 2.0 | 6 votes |
@Override public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { Link link = getLink(src, dst); if (link == null) { return null; } if (link.isExpected()) { return link.state() == INACTIVE ? null : updateLink(linkKey(link.src(), link.dst()), link, DefaultLink.builder() .providerId(link.providerId()) .src(link.src()) .dst(link.dst()) .type(link.type()) .state(INACTIVE) .isExpected(link.isExpected()) .annotations(link.annotations()).build()); } return removeLink(src, dst); }
Example #4
Source File: MQServiceImpl.java From onos with Apache License 2.0 | 6 votes |
/** * Publishes Device, Topology & Link event message to MQ server. * * @param event Event received from the corresponding service like topology, device etc */ @Override public void publish(Event<? extends Enum, ?> event) { byte[] body = null; if (null == event) { log.error("Captured event is null..."); return; } if (event instanceof DeviceEvent) { body = bytesOf(MQUtil.json((DeviceEvent) event)); } else if (event instanceof TopologyEvent) { body = bytesOf(MQUtil.json((TopologyEvent) event)); } else if (event instanceof LinkEvent) { body = bytesOf(MQUtil.json((LinkEvent) event)); } else { log.error("Invalid event: '{}'", event); return; } processAndPublishMessage(body); }
Example #5
Source File: SimpleLinkStoreTest.java From onos with Apache License 2.0 | 6 votes |
@Test public final void testCreateOrUpdateLink() { ConnectPoint src = new ConnectPoint(DID1, P1); ConnectPoint dst = new ConnectPoint(DID2, P2); // add link LinkEvent event = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, INDIRECT)); assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject()); assertEquals(LINK_ADDED, event.type()); // update link type LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject()); assertEquals(LINK_UPDATED, event2.type()); // no change LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertNull("No change event expected", event3); }
Example #6
Source File: EdgeManagerTest.java From onos with Apache License 2.0 | 6 votes |
@Test public void testBasics() { //Setup int numDevices = 20; int numPorts = 4; defaultPopulator(numDevices, numPorts); assertEquals("Unexpected number of ports", numDevices * numPorts, infrastructurePorts.size()); assertFalse("Expected isEdge to return false", mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1))); removeInfraPort(NetTestTools.connectPoint(Integer.toString(1), 1)); postTopologyEvent(new LinkEvent(LINK_REMOVED, NetTestTools.link(Integer.toString(1), 1, "b", 2))); assertTrue("Expected isEdge to return true", mgr.isEdgePoint(NetTestTools.connectPoint(Integer.toString(1), 1))); }
Example #7
Source File: ObjectiveTrackerTest.java From onos with Apache License 2.0 | 6 votes |
/** * 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")); }
Example #8
Source File: ECLinkStore.java From onos with Apache License 2.0 | 6 votes |
@Override public LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst) { Link link = getLink(src, dst); if (link == null) { return null; } if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE && link.isExpected()) { // FIXME: this will not sync link state!!! return link.state() == INACTIVE ? null : updateLink(linkKey(link.src(), link.dst()), link, DefaultLink.builder() .providerId(link.providerId()) .src(link.src()) .dst(link.dst()) .type(link.type()) .state(INACTIVE) .isExpected(link.isExpected()) .annotations(link.annotations()) .build()); } return removeLink(src, dst); }
Example #9
Source File: LinkEventConverter.java From onos with Apache License 2.0 | 6 votes |
private LinkNotificationProto buildDeviceProtoMessage(LinkEvent linkEvent) { LinkNotificationProto notification = LinkNotificationProto.newBuilder() .setLinkEventType(getProtoType(linkEvent)) .setLink(LinkProto.newBuilder() .setState(LinkStateProto.ACTIVE .valueOf(linkEvent.subject().state().name())) .setType(LinkTypeProto.valueOf(linkEvent.subject().type().name())) .setDst(ConnectPointProto.newBuilder() .setDeviceId(linkEvent.subject().dst() .deviceId().toString()) .setPortNumber(linkEvent.subject().dst().port() .toString())) .setSrc(ConnectPointProto.newBuilder() .setDeviceId(linkEvent.subject().src() .deviceId().toString()) .setPortNumber(linkEvent.subject().src().port() .toString()))) .build(); return notification; }
Example #10
Source File: ObjectiveTrackerTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests an event for a link being added. * * @throws InterruptedException if the latch wait fails. */ @Test public void testEventLinkAdded() throws InterruptedException { final Link link = link("src", 1, "dst", 2); final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_ADDED, link); reasons.add(linkEvent); final TopologyEvent event = new TopologyEvent( TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons); listener.event(event); assertThat( delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true)); assertThat(delegate.intentIdsFromEvent, hasSize(0)); assertThat(delegate.compileAllFailedFromEvent, is(true)); }
Example #11
Source File: ObjectiveTrackerTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests an event for a link down where none of the reasons match * currently installed intents. * * @throws InterruptedException if the latch wait fails. */ @Test public void testEventLinkDownNoMatches() throws InterruptedException { 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); listener.event(event); assertThat( delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true)); assertThat(delegate.intentIdsFromEvent, hasSize(0)); assertThat(delegate.compileAllFailedFromEvent, is(false)); }
Example #12
Source File: EdgeManager.java From onos with Apache License 2.0 | 6 votes |
private void processLinkEvent(LinkEvent event) { // negative Link event can result in increase of edge ports boolean addEdgePort = event.type() == LinkEvent.Type.LINK_REMOVED; // but if the Link is an Edge type, it will be the opposite if (event.subject().type() == Type.EDGE) { addEdgePort = !addEdgePort; } if (addEdgePort) { addEdgePort(event.subject().src()); addEdgePort(event.subject().dst()); } else { removeEdgePort(event.subject().src()); removeEdgePort(event.subject().dst()); } }
Example #13
Source File: ECLinkStoreTest.java From onos with Apache License 2.0 | 6 votes |
@Test public final void testCreateOrUpdateLink() { ConnectPoint src = new ConnectPoint(DID1, P1); ConnectPoint dst = new ConnectPoint(DID2, P2); final DefaultLinkDescription linkDescription = new DefaultLinkDescription(src, dst, INDIRECT); LinkEvent event = linkStore.createOrUpdateLink(PID, linkDescription); assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject()); assertEquals(LINK_ADDED, event.type()); LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject()); assertEquals(LINK_UPDATED, event2.type()); // no change LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertNull("No change event expected", event3); }
Example #14
Source File: SimpleLinkStore.java From onos with Apache License 2.0 | 5 votes |
@Override public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { final LinkKey key = linkKey(src, dst); Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key); synchronized (descs) { Link link = links.remove(key); descs.clear(); if (link != null) { srcLinks.remove(link.src().deviceId(), key); dstLinks.remove(link.dst().deviceId(), key); return new LinkEvent(LINK_REMOVED, link); } return null; } }
Example #15
Source File: EdgeManagerTest.java From onos with Apache License 2.0 | 5 votes |
/** * Post Event dispatched from TopologyManager. * * @param event Event */ private void postTopologyEvent(Event event) { if (event instanceof DeviceEvent) { testDeviceManager.listener.event((DeviceEvent) event); } if (event instanceof LinkEvent) { testLinkService.listener.event((LinkEvent) event); } //testTopologyManager.listener.event(topologyEventOf(event)); }
Example #16
Source File: EdgeManagerTest.java From onos with Apache License 2.0 | 5 votes |
/** * @param numDevices the number of devices to populate. * @param numInfraPorts the number of ports to be set as infrastructure on each device, numbered base 0, ports 0 * through numInfraPorts - 1 */ private void defaultPopulator(int numDevices, int numInfraPorts) { for (int device = 0; device < numDevices; device++) { String str = Integer.toString(device); Device deviceToAdd = NetTestTools.device(str); devices.put(deviceToAdd.id(), deviceToAdd); testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, deviceToAdd)); for (int port = 1; port <= numInfraPorts; port++) { testLinkService.listener.event(new LinkEvent(LINK_ADDED, NetTestTools.link(str, port, "other", 1))); infrastructurePorts.add(NetTestTools.connectPoint(str, port)); } } }
Example #17
Source File: DefaultTopologyProviderTest.java From onos with Apache License 2.0 | 5 votes |
@Test public void eventDriven() throws InterruptedException, TimeoutException { assertEquals(1, topologyChangedCounts.awaitAdvanceInterruptibly(0, 1, TimeUnit.SECONDS)); validateSubmission(); deviceService.postEvent(new DeviceEvent(DEVICE_ADDED, device("z"), null)); linkService.postEvent(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4))); assertThat(topologyChangedCounts.awaitAdvanceInterruptibly(1, 1, TimeUnit.SECONDS), is(greaterThanOrEqualTo(2))); // Note: posting event, to trigger topologyChanged call, // but dummy topology will not change. validateSubmission(); }
Example #18
Source File: ObjectiveTracker.java From onos with Apache License 2.0 | 5 votes |
@Override public void run() { // If there is no delegate, why bother? Just bail. if (delegate == null) { return; } if (event.reasons() == null || event.reasons().isEmpty()) { delegate.triggerCompile(Collections.emptySet(), true); } else { Set<Key> intentsToRecompile = new HashSet<>(); boolean dontRecompileAllFailedIntents = true; // Scan through the list of reasons and keep accruing all // intents that need to be recompiled. for (Event reason : event.reasons()) { if (reason instanceof LinkEvent) { LinkEvent linkEvent = (LinkEvent) reason; final LinkKey linkKey = linkKey(linkEvent.subject()); synchronized (intentsByLink) { Set<Key> intentKeys = intentsByLink.get(linkKey); log.debug("recompile triggered by LinkEvent {} ({}) for {}", linkKey, linkEvent.type(), intentKeys); intentsToRecompile.addAll(intentKeys); } dontRecompileAllFailedIntents = dontRecompileAllFailedIntents && (linkEvent.type() == LINK_REMOVED || (linkEvent.type() == LINK_UPDATED && linkEvent.subject().isExpected())); } } delegate.triggerCompile(intentsToRecompile, !dontRecompileAllFailedIntents); } }
Example #19
Source File: SimpleLinkStore.java From onos with Apache License 2.0 | 5 votes |
private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) { if (oldLink.state() != newLink.state() || (oldLink.type() == INDIRECT && newLink.type() == DIRECT) || !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) { links.put(key, newLink); // strictly speaking following can be omitted srcLinks.put(oldLink.src().deviceId(), key); dstLinks.put(oldLink.dst().deviceId(), key); return new LinkEvent(LINK_UPDATED, newLink); } return null; }
Example #20
Source File: ECLinkStoreTest.java From onos with Apache License 2.0 | 5 votes |
@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()); }
Example #21
Source File: SimpleLinkStoreTest.java From onos with Apache License 2.0 | 5 votes |
private void removeOrDownLink(boolean isDurable) { 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, isDurable ? DA1 : A1); putLink(linkId2, DIRECT, isDurable ? DA2 : A2); // DID1,P1 => DID2,P2 // DID2,P2 => DID1,P1 // DID1,P2 => DID2,P3 LinkEvent event = linkStore.removeOrDownLink(d1P1, d2P2); assertEquals(isDurable ? LINK_UPDATED : LINK_REMOVED, event.type()); assertAnnotationsEquals(event.subject().annotations(), isDurable ? DA1 : A1); LinkEvent event2 = linkStore.removeOrDownLink(d1P1, d2P2); assertNull(event2); assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1)); assertAnnotationsEquals(linkStore.getLink(d2P2, d1P1).annotations(), isDurable ? DA2 : A2); // annotations, etc. should not survive remove if (!isDurable) { putLink(linkId1, DIRECT); assertLink(linkId1, DIRECT, linkStore.getLink(d1P1, d2P2)); assertAnnotationsEquals(linkStore.getLink(d1P1, d2P2).annotations()); } }
Example #22
Source File: SimpleLinkStoreTest.java From onos with Apache License 2.0 | 5 votes |
@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()); }
Example #23
Source File: ECLinkStore.java From onos with Apache License 2.0 | 5 votes |
@Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); // Process link update only if we're the master of the destination node, // otherwise signal the actual master. if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { // Only forward for ConfigProvider or NullProvider // Forwarding was added as a workaround for ONOS-490 if (!"cfg".equals(providerId.scheme()) && !"null".equals(providerId.scheme())) { return null; } // Temporary hack for NPE (ONOS-1171). // Proper fix is to implement forwarding to master on ConfigProvider if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } }
Example #24
Source File: ECLinkStore.java From onos with Apache License 2.0 | 5 votes |
private LinkEvent updateLink(LinkKey key, Link oldLink, Link newLink) { // Note: INDIRECT -> DIRECT transition only // so that BDDP discovered Link will not overwrite LDDP Link if (oldLink.state() != newLink.state() || (oldLink.type() == INDIRECT && newLink.type() == DIRECT) || !AnnotationsUtil.isEqual(oldLink.annotations(), newLink.annotations())) { links.put(key, newLink); return new LinkEvent(LINK_UPDATED, newLink); } return null; }
Example #25
Source File: ECLinkStore.java From onos with Apache License 2.0 | 5 votes |
@Override public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) { final LinkKey linkKey = LinkKey.linkKey(src, dst); ProviderId primaryProviderId = getBaseProviderId(linkKey); // Stop if there is no base provider. if (primaryProviderId == null) { return null; } LinkDescription removedLinkDescription = linkDescriptions.remove(new Provided<>(linkKey, primaryProviderId)); if (removedLinkDescription != null) { return purgeLinkCache(linkKey); } return null; }
Example #26
Source File: ECLinkStore.java From onos with Apache License 2.0 | 5 votes |
private LinkEvent purgeLinkCache(LinkKey linkKey) { Link removedLink = links.remove(linkKey); if (removedLink != null) { getAllProviders(linkKey).forEach(p -> linkDescriptions.remove(new Provided<>(linkKey, p))); linkProviders.remove(linkKey); return new LinkEvent(LINK_REMOVED, removedLink); } return null; }
Example #27
Source File: ECLinkStore.java From onos with Apache License 2.0 | 5 votes |
private LinkEvent injectLink(Provided<LinkDescription> linkInjectRequest) { log.trace("Received request to inject link {}", linkInjectRequest); ProviderId providerId = linkInjectRequest.providerId(); LinkDescription linkDescription = linkInjectRequest.key(); final DeviceId deviceId = linkDescription.dst().deviceId(); if (!deviceClockService.isTimestampAvailable(deviceId)) { // workaround for ONOS-1208 log.warn("Not ready to accept update. Dropping {}", linkInjectRequest); return null; } return createOrUpdateLink(providerId, linkDescription); }
Example #28
Source File: Ipv6RoutingComponent.java From ngsdn-tutorial with Apache License 2.0 | 5 votes |
@Override public boolean isRelevant(LinkEvent event) { switch (event.type()) { case LINK_ADDED: break; case LINK_UPDATED: case LINK_REMOVED: default: return false; } DeviceId srcDev = event.subject().src().deviceId(); DeviceId dstDev = event.subject().dst().deviceId(); return mastershipService.isLocalMaster(srcDev) || mastershipService.isLocalMaster(dstDev); }
Example #29
Source File: LinkManager.java From onos with Apache License 2.0 | 5 votes |
private void removeLinks(Set<Link> links, boolean isSoftRemove) { for (Link link : links) { LinkEvent event = isSoftRemove ? store.removeOrDownLink(link.src(), link.dst()) : store.removeLink(link.src(), link.dst()); if (event != null) { log.info("Link {} removed/vanished", event.subject()); post(event); } } }
Example #30
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
@Override public boolean isRelevant(LinkEvent event) { switch (event.type()) { case LINK_ADDED: break; case LINK_UPDATED: case LINK_REMOVED: default: return false; } DeviceId srcDev = event.subject().src().deviceId(); DeviceId dstDev = event.subject().dst().deviceId(); return mastershipService.isLocalMaster(srcDev) || mastershipService.isLocalMaster(dstDev); }