use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project openflowplugin by opendaylight.
the class OF10FeaturesReplyMessageFactoryTest method testSerialize.
@Test
public void testSerialize() throws Exception {
GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setDatapathId(BigInteger.valueOf(1L));
builder.setBuffers(1L);
builder.setTables((short) 1);
builder.setCapabilitiesV10(new CapabilitiesV10(true, false, true, false, true, false, true, false));
builder.setActionsV10(new ActionTypeV10(true, false, true, false, true, false, true, false, true, false, true, false, true));
builder.setPhyPort(createPorts());
GetFeaturesOutput message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 80);
Assert.assertEquals("Wrong datapath id", message.getDatapathId().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong n buffers", message.getBuffers().longValue(), serializedBuffer.readUnsignedInt());
Assert.assertEquals("Wrong n tables", message.getTables().shortValue(), serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(3);
Assert.assertEquals("Wrong capabilities", message.getCapabilitiesV10(), createCapabilities(serializedBuffer.readInt()));
Assert.assertEquals("Wrong actions", message.getActionsV10(), createActionsV10(serializedBuffer.readInt()));
PhyPort port = message.getPhyPort().get(0);
Assert.assertEquals("Wrong port No", port.getPortNo().intValue(), serializedBuffer.readShort());
byte[] address = new byte[6];
serializedBuffer.readBytes(address);
Assert.assertEquals("Wrong MacAddress", port.getHwAddr().getValue().toLowerCase(), new MacAddress(ByteBufUtils.macAddressToString(address)).getValue().toLowerCase());
byte[] name = new byte[16];
serializedBuffer.readBytes(name);
Assert.assertEquals("Wrong name", port.getName(), new String(name).trim());
Assert.assertEquals("Wrong config", port.getConfigV10(), createPortConfig(serializedBuffer.readInt()));
Assert.assertEquals("Wrong state", port.getStateV10(), createPortState(serializedBuffer.readInt()));
Assert.assertEquals("Wrong current", port.getCurrentFeaturesV10(), createPortFeatures(serializedBuffer.readInt()));
Assert.assertEquals("Wrong advertised", port.getAdvertisedFeaturesV10(), createPortFeatures(serializedBuffer.readInt()));
Assert.assertEquals("Wrong supported", port.getSupportedFeaturesV10(), createPortFeatures(serializedBuffer.readInt()));
Assert.assertEquals("Wrong peer", port.getPeerFeaturesV10(), createPortFeatures(serializedBuffer.readInt()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project openflowplugin by opendaylight.
the class PortStatusMessageFactoryTest method testWithDifferentBitmaps.
/**
* Testing {@link PortStatusMessageFactory} for correct translation into POJO.
*/
@Test
public void testWithDifferentBitmaps() {
ByteBuf bb = BufferHelper.buildBuffer(// reason, padding
"01 00 00 00 00 00 00 00 " + // port no, padding
"00 01 02 03 00 00 00 00 " + // mac address, padding
"08 00 27 00 B0 EB 00 00 " + // port name, String "s1-eth1"
"73 31 2d 65 74 68 31 00 00 00 00 00 00 00 00 00 " + // port config
"00 00 00 24 " + // port state
"00 00 00 02 " + // current + advertised features
"00 00 00 81 00 00 00 A1 " + // supported + peer features
"00 00 FF FF 00 00 00 00 " + // curr speed, max speed
"00 00 00 81 00 00 00 80");
PortStatusMessage message = BufferHelper.deserialize(statusFactory, bb);
Assert.assertEquals("Wrong portConfig", new PortConfig(true, false, true, false), message.getConfig());
Assert.assertEquals("Wrong portState", new PortState(true, false, false), message.getState());
Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true), message.getSupportedFeatures());
Assert.assertEquals("Wrong peerFeatures", new PortFeatures(false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false), message.getPeerFeatures());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer in project bgpcep by opendaylight.
the class LocRibWriter method update.
@SuppressWarnings("unchecked")
private Map<RouteUpdateKey, RouteEntry> update(final WriteTransaction tx, final Collection<DataTreeModification<Tables>> changes) {
final Map<RouteUpdateKey, RouteEntry> ret = new HashMap<>();
for (final DataTreeModification<Tables> tc : changes) {
final DataObjectModification<Tables> table = tc.getRootNode();
final DataTreeIdentifier<Tables> rootPath = tc.getRootPath();
final KeyedInstanceIdentifier<Peer, PeerKey> peerKIid = (KeyedInstanceIdentifier<Peer, PeerKey>) rootPath.getRootIdentifier().firstIdentifierOf(Peer.class);
final UnsignedInteger peerUuid = RouterIds.routerIdForPeerId(peerKIid.getKey().getPeerId());
/*
Initialize Peer with routes under loc rib
*/
if (!this.routeEntries.isEmpty() && table.getDataBefore() == null) {
final org.opendaylight.protocol.bgp.rib.spi.Peer peer = this.peerTracker.getPeer(peerKIid.getKey().getPeerId());
if (peer != null && peer.supportsTable(this.entryDep.getLocalTablesKey())) {
LOG.debug("Peer {} table has been created, inserting existent routes", peer.getPeerId());
this.routeEntries.forEach((key, value) -> value.initializeBestPaths(this.entryDep, new RouteEntryInfoImpl(peer, key), tx));
}
}
/*
Process new routes from Peer
*/
updateNodes(table, peerUuid, tx, ret);
}
return ret;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer 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.params.xml.ns.yang.bmp.monitor.rev200120.peers.Peer 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);
}
}
Aggregations