use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPParserTest method testEORIpv4.
/*
* End of Rib for Ipv4.
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 17 <- length (23) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 00 <- total path attribute length
*/
@Test
public void testEORIpv4() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(5), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(5), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
assertEquals(new UpdateBuilder().build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(INPUT_BYTES.get(5), ByteArray.readAllBytes(buffer));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class SimpleAttributeRegistry method parseAttributes.
@Override
public ParsedAttributes parseAttributes(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException, BGPParsingException {
final RevisedErrorHandling errorHandling = RevisedErrorHandling.from(constraint);
final Map<Integer, RawAttribute> attributes = new TreeMap<>();
BGPTreatAsWithdrawException withdrawCause = null;
while (buffer.isReadable()) {
try {
addAttribute(buffer, errorHandling, attributes);
} catch (BGPTreatAsWithdrawException e) {
LOG.info("Failed to completely parse attributes list.");
withdrawCause = e;
break;
}
}
/*
* TreeMap guarantees that we will be invoking the parser in the order
* of increasing attribute type.
*/
// We may have multiple attribute errors, each specifying a withdraw. We need to finish parsing the message
// all attributes before we can decide whether we can discard attributes, or whether we need to terminate
// the session.
final AttributesBuilder builder = new AttributesBuilder();
for (final Entry<Integer, RawAttribute> entry : attributes.entrySet()) {
LOG.debug("Parsing attribute type {}", entry.getKey());
final RawAttribute a = entry.getValue();
try {
a.parser.parseAttribute(a.buffer, builder, errorHandling, constraint);
} catch (BGPTreatAsWithdrawException e) {
LOG.info("Attribute {} indicated treat-as-withdraw", entry.getKey(), e);
if (withdrawCause == null) {
withdrawCause = e;
} else {
withdrawCause.addSuppressed(e);
}
}
}
builder.setUnrecognizedAttributes(BindingMap.ordered(this.unrecognizedAttributes));
return new ParsedAttributes(builder.build(), withdrawCause);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class BGPSynchronization method updReceived.
/**
* For each received Update message, the upd sync variable needs to be updated to true, for particular AFI/SAFI
* combination. Currently we only assume Unicast SAFI. From the Update message we have to extract the AFI. Each
* Update message can contain BGP Object with one type of AFI. If the object is BGP Link, BGP Node or a BGPPrefix
* the AFI is Linkstate. In case of BGPRoute, the AFI depends on the IP Address of the prefix.
*
* @param msg received Update message
*/
public void updReceived(final Update msg) {
TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
boolean isEOR = false;
if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
final Attributes attrs = msg.getAttributes();
if (attrs != null) {
if (attrs.augmentation(AttributesReach.class) != null) {
final AttributesReach pa = attrs.augmentation(AttributesReach.class);
if (pa.getMpReachNlri() != null) {
type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
}
} else if (attrs.augmentation(AttributesUnreach.class) != null) {
final AttributesUnreach pa = attrs.augmentation(AttributesUnreach.class);
if (pa.getMpUnreachNlri() != null) {
type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
}
if (pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
// EOR message contains only MPUnreach attribute and no NLRI
isEOR = true;
}
}
} else {
// true for empty Update Message
isEOR = true;
}
}
syncType(type, isEOR);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createLink.
private void createLink(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
// defensive lookup
final LinkAttributes la;
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
la = ((LinkAttributesCase) attrType).getLinkAttributes();
} else {
LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
la = null;
}
} else {
LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
la = null;
}
final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
Long adjSid = null;
if (la != null) {
if (la.getMetric() != null) {
ilab.setMetric(la.getMetric().getValue());
}
ilab.setName(la.getLinkName());
if (la.getSrAdjIds() != null && !la.getSrAdjIds().isEmpty()) {
final SrAdjIds srAdjIds = la.getSrAdjIds().get(0);
if (srAdjIds != null) {
final SidLabelIndex sidLabelIndex = srAdjIds.getSidLabelIndex();
if (sidLabelIndex instanceof LocalLabelCase) {
adjSid = ((LocalLabelCase) sidLabelIndex).getLocalLabel().getValue().longValue();
}
}
}
}
ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
final LinkBuilder lb = new LinkBuilder().setLinkId(buildLinkId(base, linkCase)).addAugmentation(new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
LOG.trace("Link {} implies source node {}", linkCase, srcNode);
final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
LOG.trace("Created TP {} as link source", srcTp);
NodeHolder snh = this.nodes.get(srcNode);
if (snh == null) {
snh = getNode(srcNode);
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, false, lb.getLinkId(), adjSid);
}
putNode(trans, snh);
} else {
snh.addTp(srcTp, lb.getLinkId(), false);
if (adjSid != null) {
snh.createSrHolderIfRequired().addAdjacencySid(trans, true, lb.getLinkId(), adjSid);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.key()), srcTp);
}
if (adjSid != null) {
lb.addAugmentation(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.Link1Builder().setSegment(new SegmentId(Uint32.valueOf(adjSid))).build());
}
LOG.debug("Created TP {} as link destination", dstTp);
NodeHolder dnh = this.nodes.get(dstNode);
if (dnh == null) {
dnh = getNode(dstNode);
dnh.addTp(dstTp, lb.getLinkId(), true);
putNode(trans, dnh);
} else {
dnh.addTp(dstTp, lb.getLinkId(), true);
final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.key()), dstTp);
}
final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
final Link link = lb.build();
trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute in project bgpcep by opendaylight.
the class LinkstateTopologyBuilder method createPrefix.
private void createPrefix(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final PrefixCase prefixCase, final Attributes attributes) {
final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
if (ippfx == null) {
LOG.warn("IP reachability not present in prefix {} route {}, skipping it", prefixCase, value);
return;
}
final PrefixBuilder pb = new PrefixBuilder();
final PrefixKey pk = new PrefixKey(ippfx);
pb.withKey(pk);
pb.setPrefix(ippfx);
final PrefixAttributes pa;
// Very defensive lookup
final Attributes1 attr = attributes.augmentation(Attributes1.class);
if (attr != null) {
final LinkStateAttribute attrType = attr.getLinkStateAttribute();
if (attrType != null) {
pa = ((PrefixAttributesCase) attrType).getPrefixAttributes();
} else {
LOG.debug("Missing attribute type in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
} else {
LOG.debug("Missing attributes in IP {} prefix {} route {}, skipping it", ippfx, prefixCase, value);
pa = null;
}
SrPrefix srPrefix = null;
if (pa != null) {
if (pa.getPrefixMetric() != null) {
pb.setMetric(pa.getPrefixMetric().getValue());
}
if (pa.getSrPrefix() != null) {
srPrefix = pa.getSrPrefix();
}
}
ProtocolUtil.augmentProtocolId(value, pa, pb);
final Prefix pfx = pb.build();
LOG.debug("Created prefix {} for {}", pfx, prefixCase);
/*
* All set, but... the hosting node may not exist, we may need to fake it.
*/
final NodeId node = buildNodeId(base, prefixCase.getAdvertisingNodeDescriptors());
NodeHolder nh = this.nodes.get(node);
if (nh == null) {
nh = getNode(node);
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, false, ippfx, srPrefix);
}
putNode(trans, nh);
} else {
nh.addPrefix(pfx);
if (srPrefix != null) {
nh.createSrHolderIfRequired().addSrPrefix(trans, true, ippfx, srPrefix);
}
final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
}
}
Aggregations