use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.
the class BGPOpenMessageParser method fillParams.
private void fillParams(final ByteBuf buffer, final List<BgpParameters> params) throws BGPDocumentedException {
Preconditions.checkArgument(buffer != null && buffer.isReadable(), "BUffer cannot be null or empty.");
if (LOG.isTraceEnabled()) {
LOG.trace("Started parsing of BGP parameter: {}", ByteBufUtil.hexDump(buffer));
}
while (buffer.isReadable()) {
if (buffer.readableBytes() <= 2) {
throw new BGPDocumentedException("Malformed parameter encountered (" + buffer.readableBytes() + " bytes left)", BGPError.OPT_PARAM_NOT_SUPPORTED);
}
final int paramType = buffer.readUnsignedByte();
final int paramLength = buffer.readUnsignedByte();
final ByteBuf paramBody = buffer.readSlice(paramLength);
final BgpParameters param;
try {
param = this.reg.parseParameter(paramType, paramBody);
} catch (final BGPParsingException e) {
throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR, e);
}
if (param != null) {
params.add(param);
} else {
LOG.debug("Ignoring BGP Parameter type: {}", paramType);
}
}
LOG.trace("Parsed BGP parameters: {}", params);
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.
the class BGPRouteRefreshMessageParser method serializeMessage.
/**
* Serializes BGP Route Refresh message.
*
* @param message to be serialized
* @param bytes ByteBuf where the message will be serialized
*/
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh.");
final RouteRefresh msg = (RouteRefresh) message;
final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE);
MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(), msgBuf);
LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf));
MessageUtil.formatMessage(TYPE, msgBuf, bytes);
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.
the class CapabilityParameterParser method serializeParameter.
@Override
public void serializeParameter(final BgpParameters parameter, final ByteBuf byteAggregator) {
if (parameter.getOptionalCapabilities() != null) {
final ByteBuf buffer = Unpooled.buffer();
for (final OptionalCapabilities optionalCapa : parameter.getOptionalCapabilities()) {
LOG.trace("Started serializing BGP Capability: {}", optionalCapa);
serializeOptionalCapability(optionalCapa, buffer);
}
ParameterUtil.formatParameter(TYPE, buffer, byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.
the class AbstractBGPSessionNegotiator method handleMessage.
protected synchronized void handleMessage(final Notification msg) {
LOG.debug("Channel {} handling message in state {}, msg: {}", this.channel, this.state, msg);
switch(this.state) {
case FINISHED:
sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
return;
case IDLE:
// to avoid race condition when Open message was sent by the peer before startNegotiation could be executed
if (msg instanceof Open) {
startNegotiation();
handleOpen((Open) msg);
return;
}
sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
break;
case OPEN_CONFIRM:
if (msg instanceof Keepalive) {
negotiationSuccessful(this.session);
LOG.info("BGP Session with peer {} established successfully.", this.channel);
} else if (msg instanceof Notify) {
final Notify ntf = (Notify) msg;
negotiationFailed(new BGPDocumentedException("Peer refusal", BGPError.forValue(ntf.getErrorCode(), ntf.getErrorSubcode())));
}
this.state = State.FINISHED;
return;
case OPEN_SENT:
if (msg instanceof Open) {
handleOpen((Open) msg);
return;
}
break;
default:
break;
}
// Catch-all for unexpected message
LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
sendMessage(buildErrorNotify(BGPError.FSM_ERROR));
negotiationFailed(new BGPDocumentedException("Unexpected message channel: " + this.channel + ", state: " + this.state + ", message: " + msg, BGPError.FSM_ERROR));
this.state = State.FINISHED;
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.Bgp in project bgpcep by opendaylight.
the class AddPathAbstractRouteEntry method fillAdjRibsOut.
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(final boolean isFirstBestPath, final Attributes attributes, final Route routeNonAddPath, final Route routeAddPath, final Identifier routeKeyAddNonPath, final Identifier routeKeyAddPath, final PeerId fromPeerId, final TablesKey localTK, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
/*
* We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
* expose from which client a particular route was learned from in the local RIB, and have
* the listener perform filtering.
*
* We walk the policy set in order to minimize the amount of work we do for multiple peers:
* if we have two eBGP peers, for example, there is no reason why we should perform the translation
* multiple times.
*/
final RIBSupport ribSupport = routeEntryDep.getRibSupport();
for (final Peer toPeer : this.peerTracker.getPeers()) {
if (!filterRoutes(fromPeerId, toPeer, localTK)) {
continue;
}
final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTK);
if (toPeer.getPeerId().getValue().equals("bgp://127.0.0.5")) {
LOG.debug("Write route {} to peer AdjRibsOut {}", toPeer.getPeerId());
}
if (peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
Optional<Attributes> effAttrib = Optional.empty();
final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
if (fromPeer != null && attributes != null) {
final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
effAttrib = routeEntryDep.getRoutingPolicies().applyExportPolicies(baseExp, attributes);
}
Route newRoute = null;
InstanceIdentifier ribOutRoute = null;
if (destPeerSupAddPath) {
newRoute = routeAddPath;
ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddPath);
} else if (!this.oldNonAddPathBestPathTheSame) {
ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddNonPath);
newRoute = routeNonAddPath;
}
if (effAttrib.isPresent() && newRoute != null) {
LOG.debug("Write route {} to peer AdjRibsOut {}", newRoute, toPeer.getPeerId());
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute, newRoute);
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute.child(Attributes.class), effAttrib.get());
} else if (ribOutRoute != null) {
LOG.trace("Removing {} from transaction for peer {}", ribOutRoute, toPeer.getPeerId());
tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutRoute);
}
}
}
}
Aggregations