import java.math.BigInteger;
import java.util.Arrays;
+import java.util.List;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
public final class LinkstateNlriParser implements NlriParser {
byteOffset += LENGTH_SIZE;
final NodeIdentifier remote = null;
if (type == 257) {
- builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
+ builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length),
+ false));
byteOffset += length;
}
builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
+ logger.trace("Parsing Link Descriptor: {}", Arrays.toString(value));
switch (type) {
case 258:
builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
- logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+ logger.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
builder.getLinkRemoteIdentifier());
break;
case 259:
final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4InterfaceAddress(lipv4);
- logger.trace("Parsed IPv4 interface address {}.", lipv4);
+ logger.debug("Parsed IPv4 interface address {}.", lipv4);
break;
case 260:
final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4NeighborAddress(ripv4);
- logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
+ logger.debug("Parsed IPv4 neighbor address {}.", ripv4);
break;
case 261:
final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6InterfaceAddress(lipv6);
- logger.trace("Parsed IPv6 interface address {}.", lipv6);
+ logger.debug("Parsed IPv6 interface address {}.", lipv6);
break;
case 262:
final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6NeighborAddress(ripv6);
- logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
+ logger.debug("Parsed IPv6 neighbor address {}.", ripv6);
break;
case 263:
final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
builder.setMultiTopologyId(topId);
- logger.trace("Parsed topology identifier {}.", topId);
+ logger.debug("Parsed topology identifier {}.", topId);
break;
default:
throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
}
byteOffset += length;
}
- logger.debug("Finished parsing Link descriptors.");
+ logger.trace("Finished parsing Link descriptors.");
return builder.build();
}
- private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
+ private static NodeIdentifier parseNodeDescriptors(final byte[] bytes, final boolean local) throws BGPParsingException {
int byteOffset = 0;
AsNumber asnumber = null;
DomainIdentifier bgpId = null;
final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
+ logger.trace("Parsing Node Descriptor: {}", Arrays.toString(value));
switch (type) {
case 512:
asnumber = new AsNumber(ByteArray.bytesToLong(value));
- logger.trace("Parsed AS number {}", asnumber);
+ logger.debug("Parsed {}", asnumber);
break;
case 513:
bgpId = new DomainIdentifier(value);
- logger.trace("Parsed bgpId {}", bgpId);
+ logger.debug("Parsed {}", bgpId);
break;
case 514:
ai = new AreaIdentifier(value);
- logger.trace("Parsed area identifier {}", ai);
+ logger.debug("Parsed area identifier {}", ai);
break;
case 515:
routerId = parseRouterId(value);
- logger.trace("Parsed Router Identifier {}", routerId);
+ logger.debug("Parsed Router Identifier {}", routerId);
break;
default:
throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
}
byteOffset += length;
}
- logger.debug("Finished parsing Node descriptors.");
- return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+ logger.trace("Finished parsing Node descriptors.");
+ return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
+ routerId).build()
+ : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
}
private static CRouterIdentifier parseRouterId(final byte[] value) throws BGPParsingException {
* @return BGPLinkMP or BGPNodeMP
* @throws BGPParsingException
*/
- private CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+ private List<CLinkstateDestination> parseNlri(final byte[] nlri) throws BGPParsingException {
if (nlri.length == 0) {
return null;
}
int byteOffset = 0;
- final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+ final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+ CLinkstateDestinationBuilder builder = null;
while (byteOffset != nlri.length) {
+ builder = new CLinkstateDestinationBuilder();
final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH)));
builder.setNlriType(type);
locallength = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
if (localtype == 256) {
- localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength));
+ localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength), true);
}
byteOffset += locallength;
builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH
- - LENGTH_SIZE - locallength;
- logger.debug("Restlength {}", restLength);
+ final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+ - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ logger.trace("Restlength {}", restLength);
switch (type) {
case Link:
parseLink(builder, ByteArray.subByte(nlri, byteOffset, restLength));
break;
}
byteOffset += restLength;
+ dests.add(builder.build());
}
- return builder.build();
+ return dests;
}
@Override
public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
- if (nlri.length == 0)
+ if (nlri.length == 0) {
return;
- final CLinkstateDestination dst = parseNlri(nlri);
+ }
+ final List<CLinkstateDestination> dst = parseNlri(nlri);
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
@Override
public void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
- final CLinkstateDestination dst = parseNlri(nlri);
+ final List<CLinkstateDestination> dst = parseNlri(nlri);
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
}
grouping linkstate-destination {
- container c-linkstate-destination {
+ list c-linkstate-destination {
leaf nlri-type {
type nlri-type;
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigInteger;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
+
+public class LinkstateNlriParserTest {
+
+ private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+ (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+ (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39 };
+
+ private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+ (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+ (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
+ (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28,
+ (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+ (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
+ (byte) 0x28 };
+
+ private final byte[] nextHop = new byte[] { (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b };
+
+ @Test
+ public void testNodeNlri() throws BGPParsingException {
+ final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ parser.parseNlri(this.nodeNlri, this.nextHop, builder);
+
+ assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+ final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+ assertEquals(1, ls.getCLinkstateDestination().size());
+
+ final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+ assertEquals(NlriType.Node, dest.getNlriType());
+ assertNull(dest.getDistinguisher());
+ assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+ assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+ final LocalNodeDescriptors nodeD = dest.getLocalNodeDescriptors();
+ assertEquals(new AsNumber(72L), nodeD.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), nodeD.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x39 })).build()).build(), nodeD.getCRouterIdentifier());
+
+ assertNull(dest.getRemoteNodeDescriptors());
+ }
+
+ @Test
+ public void testLinkNlri() throws BGPParsingException {
+ final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ parser.parseNlri(this.linkNlri, this.nextHop, builder);
+
+ assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+ final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+ assertEquals(1, ls.getCLinkstateDestination().size());
+
+ final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+ assertEquals(NlriType.Link, dest.getNlriType());
+ assertNull(dest.getDistinguisher());
+ assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+ assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+ final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
+ assertEquals(new AsNumber(72L), local.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
+ final RemoteNodeDescriptors remote = dest.getRemoteNodeDescriptors();
+ assertEquals(new AsNumber(72L), remote.getAsNumber());
+ assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), remote.getDomainId());
+ assertEquals(
+ new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x40 })).build()).build(), remote.getCRouterIdentifier());
+ final LinkDescriptors ld = dest.getLinkDescriptors();
+ assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
+ assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
+ }
+}
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
// check nlri
- List<Ipv4Prefix> prefs = Lists.newArrayList();
+ final List<Ipv4Prefix> prefs = Lists.newArrayList();
prefs.add(new Ipv4Prefix("172.17.2.0/24"));
prefs.add(new Ipv4Prefix("172.17.1.0/24"));
prefs.add(new Ipv4Prefix("172.17.0.0/24"));
- Nlri nlri = new NlriBuilder().setNlri(prefs).build();
+ final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
assertEquals(nlri, message.getNlri());
// check path attributes
- PathAttributes attrs = message.getPathAttributes();
+ final PathAttributes attrs = message.getPathAttributes();
- PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
// check NLRI
- List<Ipv6Prefix> prefs = Lists.newArrayList();
+ final List<Ipv6Prefix> prefs = Lists.newArrayList();
prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
// check path attributes
- PathAttributes attrs = message.getPathAttributes();
+ final PathAttributes attrs = message.getPathAttributes();
- PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setClusterId(clusters);
assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
- MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
// check path attributes
- PathAttributes attrs = message.getPathAttributes();
+ final PathAttributes attrs = message.getPathAttributes();
- PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
final List<Segments> asPath = Lists.newArrayList();
// check path attributes
- PathAttributes attrs = message.getPathAttributes();
+ final PathAttributes attrs = message.getPathAttributes();
- PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
00 00 01 <- value
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testBGPLink() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
+ final UpdateBuilder builder = new UpdateBuilder();
+
// check fields
assertNull(message.getWithdrawnRoutes());
- // network object state
- // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-
- // network link state
- // final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
- // container.setDefaultEntry(new IGPMetric(1));
- // final NetworkLinkState linkState = new NetworkLinkState(objState, container, null,
- // LinkProtectionType.UNPROTECTED, null, null, null);
-
- // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
- // DomainIdentifier(new byte[] { 25, 25,
- // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
- //
- // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
- // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
- // 0x0b, 0x0b, 0x0b, 0x03 })));
- // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
- //
- // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+ final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
- // check API message
+ final List<Segments> asPath = Lists.newArrayList();
+
+ final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+ clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+ clBuilder.setNlriType(NlriType.Link);
+ clBuilder.setProtocolId(ProtocolId.Ospf);
+
+ final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(LinkstateAddressFamily.class);
+ mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+ mpBuilder.setCNextHop(nextHop);
+
+ final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+ new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+ linkstates.add(clBuilder.build());
+
+ lsBuilder.setMpReachNlri(mpBuilder.build());
+
+ // check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
+
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
- // final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
- // final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
- // final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new
- // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
- //
- // final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
- // final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
- // final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
- //
- // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1,
- // (BGPObject) link2,
- // (BGPObject) link3), Collections.<Identifier> emptySet());
- //
- // assertEquals(expectedMessage, message);
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+ paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+ final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+ assertEquals(mpBuilder.getAfi(), mp.getAfi());
+ assertEquals(mpBuilder.getSafi(), mp.getSafi());
+ assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+ final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+ dBuilder.setCLinkstateDestination(linkstates);
+
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+ lsBuilder.setMpReachNlri(mpBuilder.build());
+
+ paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder();
+
+ lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
+ new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
+ paBuilder.addAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class,
+ lsAttrBuilder.build());
+
+ assertEquals(
+ lsAttrBuilder.build().getLinkstatePathAttribute(),
+ attrs.getAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class).getLinkstatePathAttribute());
+
+ final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+ assertEquals(linkstates.size(), dests.size());
+
+ assertEquals(linkstates, dests);
+ // check API message
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
04 <- next hop length
19 19 19 01 - nexthop (25.25.25.1)
00 <- reserved
+
00 01 <- NLRI type (1 - nodeNLRI)
00 31 <- NLRI length (49)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
-
01 00 <- local node descriptor type (256)
00 24 <- length (36)
02 00 <- node descriptor type (member AS - 512)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
-
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 00 00 64 <- value
*/
@Test
- @Ignore
- // FIXME: to be fixed in testing phase
public void testBGPNode() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
MessageUtil.LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
+ final UpdateBuilder builder = new UpdateBuilder();
+
// check fields
assertNull(message.getWithdrawnRoutes());
- // network object state
- // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
- // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
- // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
- // final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(),
- // Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier>
- // emptySet(), null);
-
- // network link state
-
- // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
- // DomainIdentifier(new byte[] { 25, 25,
- // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
- //
- // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
- // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
- // 0x0b, 0x0b, 0x0b, 0x03 })));
- // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
- //
- // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+ // attributes
- // check API message
+ final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+ new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+ final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+ new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+ new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+ final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+ clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+ clBuilder.setNlriType(NlriType.Node);
+ clBuilder.setProtocolId(ProtocolId.Ospf);
+
+ final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+ new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+ new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+ linkstates.add(clBuilder.build());
+
+ final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(LinkstateAddressFamily.class);
+ mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+ mpBuilder.setCNextHop(nextHop);
- // final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
- // final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
- // final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
- //
- // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1,
- // (BGPObject) node2,
- // (BGPObject) node3), Collections.<Identifier> emptySet());
- //
- // assertEquals(expectedMessage, message);
+ final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+ dBuilder.setCLinkstateDestination(linkstates);
+
+ mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+ lsBuilder.setMpReachNlri(mpBuilder.build());
+
+ final List<Segments> asPath = Lists.newArrayList();
+
+ // check path attributes
+ final PathAttributes attrs = message.getPathAttributes();
+
+ final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+ paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+ assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+ paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+ assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+ paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+ paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+ final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+ assertEquals(mpBuilder.getAfi(), mp.getAfi());
+ assertEquals(mpBuilder.getSafi(), mp.getSafi());
+ assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+ final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+ assertEquals(linkstates.size(), dests.size());
+
+ assertEquals(linkstates, dests);
+
+ // check API message
+ builder.setPathAttributes(paBuilder.build());
+ assertEquals(builder.build(), message);
}
/*
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.parser.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
+
+import com.google.common.collect.Lists;
+
+public class OpenTest {
+
+ private final byte[] result = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0x00, (byte) 0x25, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x1e, (byte) 0x00, (byte) 0x03, (byte) 0x7f,
+ (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x06, (byte) 0x41, (byte) 0x04, (byte) 0x00,
+ (byte) 0x00, (byte) 0x03, (byte) 0xe8 };
+
+ @Test
+ public void testSerializeOpen() throws Exception {
+ final List<BgpParameters> tlvs = Lists.newArrayList();
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).build()).build());
+ final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(
+ new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
+ final byte[] msg = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getParameterRegistry()).serializeMessage(open);
+ assertArrayEquals(this.result, msg);
+ }
+}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateDestination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final Ipv4Prefix key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv4Prefix key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv4Routes.class);
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
}
};
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
+ for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
super.remove(trans, peer, id);
}
}
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final Ipv6Prefix key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv6Prefix key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv6Routes.class);
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
}
};
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
+ for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
super.remove(trans, peer, id);
}
}
}
@Override
- public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
- final CLinkstateDestination key) {
+ public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final CLinkstateDestination key) {
final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
switch (key.getNlriType()) {
@Override
public void addRoutes(
- final DataModificationTransaction trans,
+ final DataModificationTransaction trans,
final Peer peer,
final MpReachNlri nlri,
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
- final CLinkstateDestination key =
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+ final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
RIBEntryData data = null;
switch (key.getNlriType()) {
}
@Override
- public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
- final MpUnreachNlri nlri) {
- final CLinkstateDestination key =
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstate) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
+ public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+ final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
super.remove(trans, peer, key);
}
static {
final AdjRIBsInFactoryRegistry reg = new AdjRIBsInFactoryRegistryImpl();
- reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new Ipv4AdjRIBsIn(comparator, key);
}
});
- reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new Ipv6AdjRIBsIn(comparator, key);
}
});
- reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
- new AdjRIBsInFactory() {
+ reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new AdjRIBsInFactory() {
@Override
public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
return new LinkstateAdjRIBsIn(comparator, key);
final Class<? extends SubsequentAddressFamily> safi, final AdjRIBsInFactory factory) {
final TablesKey key = new TablesKey(afi, safi);
- if (factories.containsKey(key)) {
+ if (this.factories.containsKey(key)) {
throw new RuntimeException("Specified AFI/SAFI combination is already registered");
}
- factories.put(key, factory);
+ this.factories.put(key, factory);
final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
synchronized (lock) {
- factories.remove(key);
+ AdjRIBsInFactoryRegistryImpl.this.factories.remove(key);
}
}
};
}
@Override
- public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
- return factories.get(new TablesKey(afi, safi));
+ public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
+ return this.factories.get(new TablesKey(afi, safi));
}
}
*/
public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
- private static final int MAX_FRAME_SIZE = 4096; // min 19, max 4096
+ private static final int MAX_FRAME_SIZE = 4096;
private static final int MARKER_SIZE = 16;
- private static final int LENGTH_SIZE = 2; // the length field represents the length of the whole message including
- // the header
+ /*
+ * the length field represents the length of the whole message including the header
+ */
+ private static final int LENGTH_SIZE = 2;
/*
@Override
public void onMessage(final BGPSession session, final Notification message) {
if (message instanceof Update) {
- this.rib.updateTables(this, (Update)message);
+ this.rib.updateTables(this, (Update) message);
} else {
logger.info("Ignoring unhandled message class " + message.getClass());
}
public void onSessionUp(final BGPSession session) {
logger.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
- for (BgpTableType t : session.getAdvertisedTableTypes()) {
- tables.add(new TablesKey(t.getAfi(), t.getSafi()));
+ for (final BgpTableType t : session.getAdvertisedTableTypes()) {
+ this.tables.add(new TablesKey(t.getAfi(), t.getSafi()));
}
}
this.rib.clearTable(this, key);
}
- tables.clear();
+ this.tables.clear();
}
@Override
}
@Override
- public final String toString() {
+ public String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
+ /*
+ * 240
+ */
private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
private static final Notification keepalive = new KeepaliveBuilder().build();
- private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE; // 240
+ private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
/**
* Internal session state.
this.keepAlive = remoteOpen.getHoldTimer() / 3;
holdTimerValue = remoteOpen.getHoldTimer();
- final Set<BgpTableType> tts = Sets.newHashSet();
+ final Set<TablesKey> tts = Sets.newHashSet();
+ final Set<BgpTableType> tats = Sets.newHashSet();
if (remoteOpen.getBgpParameters() != null) {
for (final BgpParameters param : remoteOpen.getBgpParameters()) {
if (param instanceof CParameters) {
final CParameters cp = (CParameters) param;
- final BgpTableType tt = new BgpTableTypeImpl(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+ final TablesKey tt = new TablesKey(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
tts.add(tt);
+ tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
}
}
}
this.sync = new BGPSynchronization(this, this.listener, tts);
- this.tableTypes = tts;
+ this.tableTypes = tats;
if (remoteOpen.getHoldTimer() != 0) {
this.stateTimer.newTimeout(new TimerTask() {
}
@Override
- final public String toString() {
+ public final String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
case OpenSent:
if (msg instanceof Open) {
final Open openObj = (Open) msg;
-
- final List<BgpParameters> prefs = openObj.getBgpParameters();
- if (prefs != null && !prefs.isEmpty()) {
- for (final BgpParameters param : openObj.getBgpParameters()) {
- final CParameters cap = param.getCParameters();
- if (cap instanceof CMultiprotocol) {
- if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
- && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
- this.remotePref = openObj;
- this.channel.writeAndFlush(new KeepaliveBuilder().build());
- this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
- this.state = State.OpenConfirm;
- logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
- return;
- }
- }
- }
- }
- final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
- BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
- this.channel.writeAndFlush(ntf);
- negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
- ntf.getErrorCode(), ntf.getErrorSubcode())));
- this.state = State.Finished;
+ handleOpen(openObj);
return;
}
break;
this.state = State.Finished;
}
+ private void handleOpen(final Open openObj) {
+ final List<BgpParameters> prefs = openObj.getBgpParameters();
+ if (prefs != null && !prefs.isEmpty()) {
+ for (final BgpParameters param : openObj.getBgpParameters()) {
+ final CParameters cap = param.getCParameters();
+ if (cap instanceof CMultiprotocol
+ && ((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+ && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+ this.remotePref = openObj;
+ this.channel.writeAndFlush(new KeepaliveBuilder().build());
+ this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+ this.state = State.OpenConfirm;
+ logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+ return;
+ }
+ }
+ }
+ final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
+ BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
+ this.channel.writeAndFlush(ntf);
+ negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
+ ntf.getErrorCode(), ntf.getErrorSubcode())));
+ this.state = State.Finished;
+ }
+
public synchronized State getState() {
return this.state;
}
new CMultiprotocolBuilder().setMultiprotocolCapability(
new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
LinkstateSubsequentAddressFamily.class).build()).build()).build());
- // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
- // tableTypes.put(ipv4, true);
- // tableTypes.put(linkstate,true);
- // tlvs.add(new GracefulCapability(true, 0, tableTypes));
tlvs.add(new BgpParametersBuilder().setCParameters(
new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
}
}
- private final Map<BgpTableType, SyncVariables> syncStorage = Maps.newHashMap();
+ private final Map<TablesKey, SyncVariables> syncStorage = Maps.newHashMap();
private final BGPSessionListener listener;
private final BGPSession session;
- public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<BgpTableType> types) {
+ public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<TablesKey> types) {
this.listener = Preconditions.checkNotNull(listener);
this.session = Preconditions.checkNotNull(bgpSession);
- for (final BgpTableType type : types) {
+ for (final TablesKey type : types) {
this.syncStorage.put(type, new SyncVariables());
}
}
if (msg.getNlri() != null || msg.getWithdrawnRoutes() != null) {
type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
} else if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
- PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
+ final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
if (pa.getMpReachNlri() != null) {
type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
}
} else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
- PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
+ final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
if (pa.getMpUnreachNlri() != null) {
type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
}
* session.
*/
public void kaReceived() {
- for (final Entry<BgpTableType, SyncVariables> entry : this.syncStorage.entrySet()) {
+ for (final Entry<TablesKey, SyncVariables> entry : this.syncStorage.entrySet()) {
final SyncVariables s = entry.getValue();
if (!s.getEor()) {
if (!s.getUpd()) {
}
}
- private Update generateEOR(final BgpTableType type) {
+ private Update generateEOR(final TablesKey type) {
if (type.getAfi().equals(Ipv4AddressFamily.class) && type.getSafi().equals(UnicastSubsequentAddressFamily.class)) {
return new UpdateBuilder().build();
}
- return new UpdateBuilder().setPathAttributes(new PathAttributesBuilder().addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
+ return new UpdateBuilder().setPathAttributes(
+ new PathAttributesBuilder().addAugmentation(
+ PathAttributes1.class,
+ new PathAttributes1Builder().setMpReachNlri(
+ new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
}
}
import javax.annotation.concurrent.ThreadSafe;
-
-
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
}
synchronized void updateTables(final BGPPeer peer, final Update message) {
- final DataModificationTransaction trans = dps.beginTransaction();
+ final DataModificationTransaction trans = this.dps.beginTransaction();
// FIXME: detect and handle end-of-RIB markers
- //remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
+ // remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+ // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
final PathAttributes attrs = message.getPathAttributes();
final PathAttributes2 mpu = attrs.getAugmentation(PathAttributes2.class);
if (mpu != null) {
final MpUnreachNlri nlri = mpu.getMpUnreachNlri();
- AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+ final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
if (ari != null) {
ari.removeRoutes(trans, peer, nlri);
} else {
}
}
- //add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- // trans, peer, message.getNlri().getNlri().iterator(), attrs);
+ // add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+ // trans, peer, message.getNlri().getNlri().iterator(), attrs);
final PathAttributes1 mpr = message.getPathAttributes().getAugmentation(PathAttributes1.class);
if (mpr != null) {
final MpReachNlri nlri = mpr.getMpReachNlri();
- final AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+ final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
if (ari != null) {
ari.addRoutes(trans, peer, nlri, attrs);
} else {
}
// FIXME: we need to attach to this future for failures
- Future<RpcResult<TransactionStatus>> f = trans.commit();
+ final Future<RpcResult<TransactionStatus>> f = trans.commit();
}
synchronized void clearTable(final BGPPeer peer, final TablesKey key) {
- final AdjRIBsIn ari = tables.get(key);
+ final AdjRIBsIn ari = this.tables.get(key);
if (ari != null) {
- final DataModificationTransaction trans = dps.beginTransaction();
+ final DataModificationTransaction trans = this.dps.beginTransaction();
ari.clear(trans, peer);
// FIXME: we need to attach to this future for failures
- Future<RpcResult<TransactionStatus>> f = trans.commit();
+ final Future<RpcResult<TransactionStatus>> f = trans.commit();
}
}
@Override
- public final String toString() {
+ public String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
import io.netty.util.concurrent.Future;
-import java.io.IOException;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
* @param connection attributes required for connection
* @param parser BGP message parser
* @return client session
- * @throws IOException
*/
- Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener, final ReconnectStrategy strategy);
+ Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener,
+ final ReconnectStrategy strategy);
}
package org.opendaylight.protocol.bgp.rib.impl;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import java.util.Collections;
import java.util.Set;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public class SynchronizationTest {
@Before
public void setUp() {
this.listener = new SimpleSessionListener();
-// final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
-// this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
-// final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
-// this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
-// this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
+ this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build();
- final Set<BgpTableType> types = Sets.newHashSet();
- types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+ final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+ mpBuilder.setAfi(Ipv6AddressFamily.class);
+ mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+
+ PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class,
+ new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+
+ this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+ final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
+ mpUBuilder.setAfi(LinkstateAddressFamily.class);
+ mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+
+ paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
+ new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
+
+ this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+ final Set<TablesKey> types = Sets.newHashSet();
+ types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
this.bs = new BGPSynchronization(new BGPSession() {
@Override
public Set<BgpTableType> getAdvertisedTableTypes() {
+ final Set<BgpTableType> types = Sets.newHashSet();
+ types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+ types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
return types;
}
}, this.listener, types);
}
@Test
- @Ignore
- //FIXME: to be fixed in testing phase
public void testSynchronize() {
// simulate sync
-// this.bs.updReceived(this.ipv6m);
-//
-// this.bs.updReceived(this.ipv4m);
-// this.bs.updReceived(this.lsm);
-// this.bs.kaReceived(); // nothing yet
-// this.bs.updReceived(this.ipv4m);
+ this.bs.updReceived(this.ipv6m);
+ this.bs.updReceived(this.ipv4m);
+ this.bs.updReceived(this.lsm);
+ this.bs.kaReceived(); // nothing yet
+ this.bs.updReceived(this.ipv4m);
this.bs.kaReceived(); // linkstate
assertEquals(1, this.listener.getListMsg().size());
+ assertEquals(
+ LinkstateAddressFamily.class,
+ ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
this.bs.kaReceived(); // ipv4 sync
assertEquals(2, this.listener.getListMsg().size());
- assertEquals(Ipv4AddressFamily.class,
- ((Update) this.listener.getListMsg().get(1)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
}
}
@ThreadSafe
public final class BGPMock implements BGP, Closeable {
- private final static Logger logger = LoggerFactory.getLogger(BGPMock.class);
+ private static final Logger logger = LoggerFactory.getLogger(BGPMock.class);
- static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
+ static final Notification CONNECTION_LOST_MAGIC_MSG = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
@GuardedBy("this")
private final List<byte[]> allPreviousByteMessages;
}
public synchronized void insertConnectionLostEvent() {
- this.insertMessage(connectionLostMagicMessage);
+ this.insertMessage(CONNECTION_LOST_MAGIC_MSG);
}
public synchronized void insertMessages(final List<Notification> messages) {
}
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
- if (BGPMock.connectionLostMagicMessage.equals(message)) {
+ if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, null);
} else if (message instanceof Open) {
final Set<BgpTableType> tts = Sets.newHashSet();
return tts;
}
});
- } else if (message instanceof Keepalive) {
- // do nothing
- } else {
+ } else if (!(message instanceof Keepalive)) {
listener.onMessage(null, message);
}
}
*/
public class Main {
- private final static Logger logger = LoggerFactory.getLogger(Main.class);
+ private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static String usage = "DESCRIPTION:\n"
+ "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
private final BGPDispatcherImpl dispatcher;
- public Main() throws Exception {
+ private static final int INITIAL_HOLD_TIME = 90;
+
+ private static final int RECONNECT_MILLIS = 5000;
+
+ Main() throws Exception {
this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
}
}
InetSocketAddress address = null;
- short holdTimerValue = 90;
+ short holdTimerValue = INITIAL_HOLD_TIME;
AsNumber as = null;
int i = 0;
logger.debug("{} {} {}", address, sessionListener, proposal);
final InetSocketAddress addr = address;
- m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
+ m.dispatcher.createClient(addr, proposal, sessionListener,
+ new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
}
}
*/
package org.opendaylight.protocol.bgp.util;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@Immutable
public final class BinaryBGPDumpFileParser {
- private static final byte ff = (byte) 255;
private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
private static final int MINIMAL_LENGTH = 19;
+ private static final int MARKER_LENGTH = 16;
+
private BinaryBGPDumpFileParser() {
}
*
* @param file file with BGP messages in binary form.
* @return list with byte arrays representing extracted messages.
- * @throws IOException
*/
public static List<byte[]> parseMessages(final byte[] byteArray) {
final byte b = byteArray[i];
// Marker start
- if (b == ff) {
+ if (b == UnsignedBytes.MAX_VALUE) {
final int start = i;
int ffCount = 0;
for (int j = i; j < i + (17); j++) {
// Check marker
- if (byteArray[j] == ff) {
+ if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
ffCount++;
- } else if (ffCount == 16) {
- if (j == (i + 16)) {
+ } else if (ffCount == MARKER_LENGTH) {
+ if (j == (i + MARKER_LENGTH)) {
// Parse length
final int length = UnsignedBytes.toInt(byteArray[j]) * 256 + UnsignedBytes.toInt(byteArray[j + 1]);
final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
messages.add(message);
- j += length - 16;
+ j += length - MARKER_LENGTH;
}
i = j;
break;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
* this format.
*/
@Immutable
-public class HexDumpBGPFileParser {
+public final class HexDumpBGPFileParser {
private static final int MINIMAL_LENGTH = 19;
private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
- private static final String ff_16 = Strings.repeat("FF", 16);
+ private static final String FF_16 = Strings.repeat("FF", 16);
private HexDumpBGPFileParser() {
}
- public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
+ public static List<byte[]> parseMessages(final File file) throws IOException {
Preconditions.checkArgument(file != null, "Filename cannot be null");
return parseMessages(new FileInputStream(file));
}
}
}
- public static List<byte[]> parseMessages(String content) {
- content = clearWhiteSpaceToUpper(content);
+ public static List<byte[]> parseMessages(final String c) {
+ final String content = clearWhiteSpaceToUpper(c);
// search for 16 FFs
final List<byte[]> messages = Lists.newLinkedList();
int idx = 0;
- while ((idx = content.indexOf(ff_16, idx)) > -1) {
+ while ((idx = content.indexOf(FF_16, idx)) > -1) {
// next 2 bytes are length
final int lengthIdx = idx + 16 * 2;
final int messageIdx = lengthIdx + 4;
}
public static byte[] bytesForPrefix(final Ipv4Prefix prefix) {
- String p = prefix.getValue();
+ final String p = prefix.getValue();
final int sep = p.indexOf("/");
try {
- byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
+ final byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
public static Ipv4Prefix prefixForBytes(final byte[] bytes, final int length) {
Preconditions.checkArgument(length <= bytes.length * 8);
- byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
+ final byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
InetAddress a = null;
try {
a = InetAddress.getByAddress(tmp);
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage());
}
return new Ipv4Prefix(InetAddresses.toAddrString(a) + "/" + length);