use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest41.
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrIGPFlags.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest41() throws BgpParseException {
byte[] updateMsg = 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, 0x00, (byte) 0x93, 0x02, 0x00, 0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x78, // origin
0x04, // origin
0x01, // origin
0x01, // origin
0x00, // as_path
0x40, // as_path
0x02, // as_path
0x04, // as_path
0x02, // as_path
0x01, // as_path
(byte) 0xfd, // as_path
(byte) 0xe9, // med
(byte) 0x80, // med
0x04, // med
0x04, // med
0x00, // med
0x00, // med
0x00, // med
0x00, // mpreach
(byte) 0x80, // mpreach
0x0e, // mpreach
0x53, // mpreach
0x40, // mpreach
0x04, // mpreach
0x47, // nexthop
0x04, // nexthop
0x04, // nexthop
0x00, // nexthop
0x00, // nexthop
0x01, // reserved
0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
0x00, // link nlri
(byte) 0x95, // link nlri
0x02, // link nlri
0x50, // link nlri
0x21, // linkstate attr
(byte) 0x80, // linkstate attr
0x1d, // linkstate attr
0x0D, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x00, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
(byte) 0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, 0x04, (byte) 0x80, 0x00, 0x01, // BgpPrefixAttrIGPFlags
(byte) 0xA0 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message = null;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
byte[] marker = 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 };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 147));
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
OriginType originValue = OriginType.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
BgpPrefixAttrIgpFlags obj = new BgpPrefixAttrIgpFlags(true, false, true, false);
assertThat(((BgpPrefixAttrIgpFlags) list.next()).equals(obj), is(true));
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpSessionManager method peerConnected.
/**
* Processes the connection from a BGP peer.
*
* @param bgpSession the BGP session for the peer
* @return true if the connection can be established, otherwise false
*/
boolean peerConnected(BgpSession bgpSession) {
// Test whether there is already a session from the same remote
if (bgpSessions.get(bgpSession.remoteInfo().address()) != null) {
// Duplicate BGP session
return false;
}
bgpSessions.put(bgpSession.remoteInfo().address(), bgpSession);
//
if (bgpSession.localInfo().address() instanceof InetSocketAddress) {
InetAddress inetAddr = ((InetSocketAddress) bgpSession.localInfo().address()).getAddress();
Ip4Address ip4Address = Ip4Address.valueOf(inetAddr.getAddress());
updateMyBgpId(ip4Address);
}
return true;
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpRouteEntry method isBetterThan.
/**
* Compares this BGP route against another BGP route by using the
* BGP Decision Process.
* <p>
* NOTE: The comparison needs to be performed only on routes that have
* same IP Prefix.
* </p>
*
* @param other the BGP route to compare against
* @return true if this BGP route is better than the other BGP route
* or same, otherwise false
*/
boolean isBetterThan(BgpRouteEntry other) {
if (this == other) {
// Return true if same route
return true;
}
// Compare the LOCAL_PREF values: larger is better
if (getLocalPref() != other.getLocalPref()) {
return (getLocalPref() > other.getLocalPref());
}
// Compare the AS number in the path: smaller is better
if (getAsPath().getAsPathLength() != other.getAsPath().getAsPathLength()) {
return getAsPath().getAsPathLength() < other.getAsPath().getAsPathLength();
}
// Compare the Origin number: lower is better
if (getOrigin() != other.getOrigin()) {
return (getOrigin() < other.getOrigin());
}
// Compare the MED if the neighbor AS is same: larger is better
medLabel: {
if (isLocalRoute() || other.isLocalRoute()) {
// Compare MEDs for non-local routes only
break medLabel;
}
long thisNeighborAs = getNeighborAs();
if (thisNeighborAs != other.getNeighborAs()) {
// AS number is different
break medLabel;
}
if (thisNeighborAs == BgpConstants.BGP_AS_0) {
// Invalid AS number
break medLabel;
}
// Compare the MED
if (getMultiExitDisc() != other.getMultiExitDisc()) {
return (getMultiExitDisc() > other.getMultiExitDisc());
}
}
// Compare the peer BGP ID: lower is better
Ip4Address peerBgpId = getBgpSession().remoteInfo().bgpId();
Ip4Address otherPeerBgpId = other.getBgpSession().remoteInfo().bgpId();
if (!peerBgpId.equals(otherPeerBgpId)) {
return (peerBgpId.compareTo(otherPeerBgpId) < 0);
}
// Compare the peer BGP address: lower is better
Ip4Address peerAddress = getBgpSession().remoteInfo().ip4Address();
Ip4Address otherPeerAddress = other.getBgpSession().remoteInfo().ip4Address();
if (!peerAddress.equals(otherPeerAddress)) {
return (peerAddress.compareTo(otherPeerAddress) < 0);
}
// Routes are same. Shouldn't happen?
return true;
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class RouteEntryTest method testInvalidConstructorNullIpv4Prefix.
/**
* Tests invalid class constructor for null IPv4 prefix.
*/
@Test(expected = NullPointerException.class)
public void testInvalidConstructorNullIpv4Prefix() {
Ip4Prefix prefix = null;
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
new RouteEntry(prefix, nextHop);
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class RouteEntryTest method testNonEquality.
/**
* Tests non-equality of {@link RouteEntry}.
*/
@Test
public void testNonEquality() {
Ip4Prefix prefix1 = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop1 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry1 = new RouteEntry(prefix1, nextHop1);
// Different
Ip4Prefix prefix2 = Ip4Prefix.valueOf("1.2.3.0/25");
Ip4Address nextHop2 = Ip4Address.valueOf("5.6.7.8");
RouteEntry routeEntry2 = new RouteEntry(prefix2, nextHop2);
Ip4Prefix prefix3 = Ip4Prefix.valueOf("1.2.3.0/24");
// Different
Ip4Address nextHop3 = Ip4Address.valueOf("5.6.7.9");
RouteEntry routeEntry3 = new RouteEntry(prefix3, nextHop3);
assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry2)));
assertThat(routeEntry1, Matchers.is(Matchers.not(routeEntry3)));
Ip6Prefix prefix4 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop4 = Ip6Address.valueOf("2000::1");
RouteEntry routeEntry4 = new RouteEntry(prefix4, nextHop4);
Ip6Prefix prefix5 = Ip6Prefix.valueOf("1000::/65");
Ip6Address nextHop5 = Ip6Address.valueOf("2000::1");
RouteEntry routeEntry5 = new RouteEntry(prefix5, nextHop5);
Ip6Prefix prefix6 = Ip6Prefix.valueOf("1000::/64");
Ip6Address nextHop6 = Ip6Address.valueOf("2000::2");
RouteEntry routeEntry6 = new RouteEntry(prefix6, nextHop6);
assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry5)));
assertThat(routeEntry4, Matchers.is(Matchers.not(routeEntry6)));
}
Aggregations