typedef cluster-identifier {
reference "http://tools.ietf.org/html/rfc4456#section-8";
- type binary {
- length "4";
- }
+ type inet:ipv4-address;
}
typedef short-as-number {
uses bgp-t:extended-community;
}
leaf originator-id {
- type binary {
- length "4";
- }
+ type inet:ipv4-address;
}
leaf-list cluster-id {
type bgp-t:cluster-identifier;
import java.util.List;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
final List<ClusterIdentifier> list = Lists.newArrayList();
int i = 0;
while (i < bytes.length) {
- list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, CLUSTER_LENGTH)));
+ list.add(new ClusterIdentifier(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, i, CLUSTER_LENGTH))));
i += CLUSTER_LENGTH;
}
package org.opendaylight.protocol.bgp.parser.impl.message.update;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
public final class OriginatorIdAttributeParser implements AttributeParser {
throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be " + ORIGINATOR_LENGTH + ", but is "
+ bytes.length);
}
- builder.setOriginatorId(bytes);
+ builder.setOriginatorId(Ipv4Util.addressForBytes(bytes));
}
}
\ No newline at end of file
*/
package org.opendaylight.protocol.bgp.parser.impl;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
final Ipv6NextHopCase nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(
new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
- final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new byte[] { 1, 2, 3, 4 }),
- new ClusterIdentifier(new byte[] { 5, 6, 7, 8 }));
+ final List<ClusterIdentifier> clusters = Lists.newArrayList(new ClusterIdentifier(new Ipv4Address("1.2.3.4")),
+ new ClusterIdentifier(new Ipv4Address("5.6.7.8")));
// check path attributes
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
- paBuilder.setOriginatorId(new byte[] { 127, 0, 0, 1 });
- assertArrayEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
+ paBuilder.setOriginatorId(new Ipv4Address("127.0.0.1"));
+ assertEquals(paBuilder.getOriginatorId(), attrs.getOriginatorId());
paBuilder.setClusterId(clusters);
assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as.path.segment.c.segment.ASetCase;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.net.InetAddresses;
/**
* This comparator is intended to implement BGP Best Path Selection algorithm, as described at
byte[] oid1 = this.id1;
byte[] oid2 = this.id2;
if (o1.getOriginatorId() != null) {
- oid1 = o1.getOriginatorId();
+ oid1 = InetAddresses.forString(o1.getOriginatorId().getValue()).getAddress();
}
if (o2.getOriginatorId() != null) {
- oid2 = o2.getOriginatorId();
+ oid2 = InetAddresses.forString(o2.getOriginatorId().getValue()).getAddress();
}
if (!Arrays.equals(oid1, oid2)) {
return compareByteArrays(oid1, oid2);
import org.junit.Before;
import org.junit.Test;
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.rev130919.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPathBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPrefBuilder;
public class BestPathSelectionTest {
private final BGPObjectComparator comparator = new BGPObjectComparator(new AsNumber(40L), new byte[] { (byte) 192, (byte) 150, 20, 38 }, new byte[] {
- (byte) 192, (byte) 150, 20, 38 });
+ (byte) 192, (byte) 150, 20, 38 });
private PathAttributes attr1;
private PathAttributes attr2;
asBuilder2.setSegments(segs);
final List<ClusterIdentifier> clusters = new ArrayList<>();
- clusters.add(new ClusterIdentifier(new byte[4]));
- clusters.add(new ClusterIdentifier(new byte[4]));
+ clusters.add(new ClusterIdentifier(new Ipv4Address("0.0.0.0")));
+ clusters.add(new ClusterIdentifier(new Ipv4Address("0.0.0.0")));
final PathAttributesBuilder builder = new PathAttributesBuilder();
builder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());