use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method removePeerSession.
@Override
public synchronized void removePeerSession(final IpAddress oldIp) {
IpAddress fullIp = getFullIp(oldIp);
this.sessionIds.remove(fullIp);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionRemoved(fullIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method removePeer.
@Override
public synchronized void removePeer(final IpAddress oldIp) {
IpAddress fullIp = getFullIp(oldIp);
this.peers.remove(fullIp);
for (final PeerRegistryListener peerRegistryListener : this.listeners) {
peerRegistryListener.onPeerRemoved(fullIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method getPeer.
@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open openObj) throws BGPDocumentedException {
requireNonNull(ip);
requireNonNull(sourceId);
requireNonNull(remoteId);
final AsNumber remoteAsNumber = AsNumberUtil.advertizedAsNumber(openObj);
requireNonNull(remoteAsNumber);
final BGPSessionPreferences prefs = getPeerPreferences(ip);
checkPeerConfigured(ip);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
final BGPSessionListener p = this.peers.get(ip);
final BGPSessionId previousConnection = this.sessionIds.get(ip);
if (previousConnection != null) {
LOG.warn("Duplicate BGP session established with {}", ip);
// Session reestablished with different ids
if (!previousConnection.equals(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
throw new BGPDocumentedException(String.format("BGP session with %s %s has to be dropped. Same session already present %s", ip, currentConnection, previousConnection), BGPError.CEASE);
// Session reestablished with lower source bgp id, dropping current
} else if (previousConnection.isHigherDirection(currentConnection) || previousConnection.hasHigherAsNumber(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Opposite session already present", ip, currentConnection), BGPError.CEASE);
// Session reestablished with higher source bgp id, dropping previous
} else if (currentConnection.isHigherDirection(previousConnection) || currentConnection.hasHigherAsNumber(previousConnection)) {
LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
this.peers.get(ip).releaseConnection();
return this.peers.get(ip);
// Session reestablished with same source bgp id, dropping current as duplicate
} else {
LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Same session already present", ip, currentConnection), BGPError.CEASE);
}
}
validateAs(remoteAsNumber, openObj, prefs);
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionCreated(ip);
}
return p;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method addPeer.
@Override
public synchronized void addPeer(final IpAddress oldIp, final BGPSessionListener peer, final BGPSessionPreferences preferences) {
IpAddress fullIp = getFullIp(oldIp);
Preconditions.checkArgument(!this.peers.containsKey(fullIp), "Peer for %s already present", fullIp);
this.peers.put(fullIp, requireNonNull(peer));
requireNonNull(preferences.getMyAs());
requireNonNull(preferences.getParams());
requireNonNull(preferences.getBgpId());
this.peerPreferences.put(fullIp, preferences);
for (final PeerRegistryListener peerRegistryListener : this.listeners) {
peerRegistryListener.onPeerAdded(fullIp, preferences);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.endpoint.endpoint.type.IpAddress in project bgpcep by opendaylight.
the class NodeChangedListenerTest method testNodeChangedListener.
@Test
public void testNodeChangedListener() throws ReadFailedException, TransactionCommitFailedException {
// add node -> create two nodes with TPs and link
createNode(NODE1_ID, NODE1_IPV4, LSP1_NAME, LSP1_ID, NODE2_IPV4);
final Topology tunnelTopo = readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, tunnelTopo1 -> {
assertNotNull(tunnelTopo1.getNode());
assertEquals(2, tunnelTopo1.getNode().size());
return tunnelTopo1;
});
final NodeId srcId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE1_IPV4)));
final NodeId dstId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE2_IPV4)));
final Node dst;
final Node src;
if (tunnelTopo.getNode().get(0).getNodeId().equals(srcId)) {
src = tunnelTopo.getNode().get(0);
dst = tunnelTopo.getNode().get(1);
} else {
src = tunnelTopo.getNode().get(1);
dst = tunnelTopo.getNode().get(0);
}
Assert.assertEquals(srcId, src.getNodeId());
Assert.assertEquals(dstId, dst.getNodeId());
Assert.assertEquals(1, dst.getTerminationPoint().size());
Assert.assertEquals(1, src.getTerminationPoint().size());
final TerminationPoint dstTp = dst.getTerminationPoint().get(0);
final TerminationPoint srcTp = src.getTerminationPoint().get(0);
final TpId dstNodeTpId = new TpId(dstId.getValue());
final TpId srcNodeTpId = new TpId(srcId.getValue());
Assert.assertEquals(dstNodeTpId, dstTp.getTpId());
Assert.assertEquals(srcNodeTpId, srcTp.getTpId());
Assert.assertEquals(1, src.getSupportingNode().size());
Assert.assertNull(dst.getSupportingNode());
final SupportingNode sNode = src.getSupportingNode().get(0);
Assert.assertEquals(NODE1_ID, sNode.getKey().getNodeRef());
Assert.assertEquals(1, tunnelTopo.getLink().size());
final Link link = tunnelTopo.getLink().get(0);
Assert.assertEquals(srcId, link.getSource().getSourceNode());
Assert.assertEquals(srcNodeTpId, link.getSource().getSourceTp());
Assert.assertEquals(dstId, link.getDestination().getDestNode());
Assert.assertEquals(dstNodeTpId, link.getDestination().getDestTp());
// update second node -> adds supporting node and second link
createNode(NODE2_ID, NODE2_IPV4, LSP2_NAME, LSP2_ID, NODE1_IPV4);
readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
assertNotNull(updatedNodeTopo.getNode());
Assert.assertEquals(2, updatedNodeTopo.getNode().size());
final Node updatedNode;
if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
updatedNode = updatedNodeTopo.getNode().get(1);
} else {
updatedNode = updatedNodeTopo.getNode().get(0);
}
assertNotNull(updatedNode.getSupportingNode());
Assert.assertEquals(1, updatedNode.getSupportingNode().size());
final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
Assert.assertEquals(2, updatedNodeTopo.getLink().size());
return updatedNodeTopo;
});
readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
final Link link2;
if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
link2 = updatedNodeTopo.getLink().get(1);
} else {
link2 = updatedNodeTopo.getLink().get(0);
}
assertEquals(dstId, link2.getSource().getSourceNode());
assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
assertEquals(srcId, link2.getDestination().getDestNode());
assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
return updatedNodeTopo;
});
// remove nodes -> remove link
removeNode(NODE1_ID);
removeNode(NODE2_ID);
readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, removedNodeTopo -> {
assertEquals(0, removedNodeTopo.getNode().size());
assertEquals(0, removedNodeTopo.getLink().size());
return removedNodeTopo;
});
}
Aggregations