use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest40.
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest40() 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) 0x9A, 0x02, 0x00, 0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x7F, // 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
0x14, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x00, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
(byte) 0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, 0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, // BgpLinkAttrName
0x0b };
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) 154));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
while (listIterator1.hasNext()) {
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
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;
assertThat(mpReach.mpReachNlriLen(), is((int) 83));
assertThat(mpReach.getType(), is((short) 14));
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));
byte[] linkName = new byte[] { 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpFlowSpecNlriTest method testEquality.
@Test
public void testEquality() {
flowSpecComponents1.add(portNum1);
byte[] port1 = new byte[] { (byte) 0x1 };
operatorValue1.add(new BgpFsOperatorValue((byte) 0x81, port1));
byte[] port11 = new byte[] { (byte) 0x1 };
operatorValue1.add(new BgpFsOperatorValue((byte) 0x82, port11));
List<BgpValueType> fsTlvs1 = new LinkedList<>();
fsTlvs1.add(new BgpFsActionTrafficRate((short) 1, 1));
flowSpecDetails1.setFsActionTlv(fsTlvs1);
flowSpecComponents.add(portNum);
byte[] port = new byte[] { (byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
byte[] port4 = new byte[] { (byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x82, port4));
List<BgpValueType> fsTlvs = new LinkedList<>();
fsTlvs.add(new BgpFsActionTrafficRate((short) 1, 1));
flowSpecComponents2.add(portNum2);
byte[] port2 = new byte[] { (byte) 0x1 };
operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port2));
byte[] port22 = new byte[] { (byte) 0x1 };
operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port22));
List<BgpValueType> fsTlvs2 = new LinkedList<>();
fsTlvs2.add(new BgpFsActionTrafficRate((short) 1, 1));
flowSpecDetails2.setFsActionTlv(fsTlvs2);
new EqualsTester().addEqualityGroup(flowSpecDetails1, flowSpecDetails).addEqualityGroup(flowSpecDetails2).testEquals();
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpPathAttributes method write.
/**
* Write path attributes to channelBuffer.
*
* @param cb channelBuffer
* @return object of BgpPathAttributes
* @throws BgpParseException while parsing BGP path attributes
*/
public int write(ChannelBuffer cb) throws BgpParseException {
if (pathAttribute == null) {
return 0;
}
int iLenStartIndex = cb.writerIndex();
ListIterator<BgpValueType> iterator = pathAttribute.listIterator();
int pathAttributeIndx = cb.writerIndex();
cb.writeShort(0);
while (iterator.hasNext()) {
BgpValueType attr = iterator.next();
switch(attr.getType()) {
case Origin.ORIGIN_TYPE:
Origin origin = (Origin) attr;
origin.write(cb);
break;
case AsPath.ASPATH_TYPE:
AsPath asPath = (AsPath) attr;
asPath.write(cb);
break;
case As4Path.AS4PATH_TYPE:
As4Path as4Path = (As4Path) attr;
as4Path.write(cb);
break;
case NextHop.NEXTHOP_TYPE:
NextHop nextHop = (NextHop) attr;
nextHop.write(cb);
break;
case Med.MED_TYPE:
Med med = (Med) attr;
med.write(cb);
break;
case LocalPref.LOCAL_PREF_TYPE:
LocalPref localPref = (LocalPref) attr;
localPref.write(cb);
break;
case Constants.BGP_EXTENDED_COMMUNITY:
BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr;
extendedCommunity.write(cb);
break;
case WideCommunity.TYPE:
WideCommunity wideCommunity = (WideCommunity) attr;
wideCommunity.write(cb);
break;
case MpReachNlri.MPREACHNLRI_TYPE:
MpReachNlri mpReach = (MpReachNlri) attr;
mpReach.write(cb);
break;
case MpUnReachNlri.MPUNREACHNLRI_TYPE:
MpUnReachNlri mpUnReach = (MpUnReachNlri) attr;
mpUnReach.write(cb);
break;
case LINK_STATE_ATTRIBUTE_TYPE:
LinkStateAttributes linkState = (LinkStateAttributes) attr;
linkState.write(cb);
break;
default:
return cb.writerIndex() - iLenStartIndex;
}
}
int pathAttrLen = cb.writerIndex() - pathAttributeIndx;
cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2));
return cb.writerIndex() - iLenStartIndex;
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpPathAttributes method read.
/**
* Reads from channelBuffer and parses BGP path attributes.
*
* @param cb channelBuffer
* @return object of BgpPathAttributes
* @throws BgpParseException while parsing BGP path attributes
*/
public static BgpPathAttributes read(ChannelBuffer cb) throws BgpParseException {
BgpValueType pathAttribute = null;
List<BgpValueType> pathAttributeList = new LinkedList<>();
boolean isOrigin = false;
boolean isAsPath = false;
boolean isNextHop = false;
boolean isMpReach = false;
boolean isMpUnReach = false;
while (cb.readableBytes() > 0) {
cb.markReaderIndex();
byte flags = cb.readByte();
byte typeCode = cb.readByte();
cb.resetReaderIndex();
switch(typeCode) {
case Origin.ORIGIN_TYPE:
pathAttribute = Origin.read(cb);
isOrigin = ((Origin) pathAttribute).isOriginSet();
break;
case AsPath.ASPATH_TYPE:
pathAttribute = AsPath.read(cb);
isAsPath = ((AsPath) pathAttribute).isaspathSet();
break;
case As4Path.AS4PATH_TYPE:
pathAttribute = As4Path.read(cb);
break;
case NextHop.NEXTHOP_TYPE:
pathAttribute = NextHop.read(cb);
isNextHop = ((NextHop) pathAttribute).isNextHopSet();
break;
case Med.MED_TYPE:
pathAttribute = Med.read(cb);
break;
case LocalPref.LOCAL_PREF_TYPE:
pathAttribute = LocalPref.read(cb);
break;
case MpReachNlri.MPREACHNLRI_TYPE:
pathAttribute = MpReachNlri.read(cb);
isMpReach = ((MpReachNlri) pathAttribute).isMpReachNlriSet();
break;
case MpUnReachNlri.MPUNREACHNLRI_TYPE:
pathAttribute = MpUnReachNlri.read(cb);
isMpUnReach = ((MpUnReachNlri) pathAttribute).isMpUnReachNlriSet();
break;
case LINK_STATE_ATTRIBUTE_TYPE:
pathAttribute = LinkStateAttributes.read(cb);
break;
case EXTENDED_COMMUNITY_TYPE:
pathAttribute = BgpExtendedCommunity.read(cb);
break;
case WideCommunity.TYPE:
pathAttribute = WideCommunity.read(cb);
break;
default:
log.debug("Skip bytes for unsupported attribute types");
UnSupportedAttribute.read(cb);
}
pathAttributeList.add(pathAttribute);
}
checkMandatoryAttr(isOrigin, isAsPath, isNextHop, isMpReach, isMpUnReach);
// TODO:if mp_reach or mp_unreach not present ignore the packet
return new BgpPathAttributes(pathAttributeList);
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class WideCommunity method decodeWideCommunityTlv.
/**
* Decode wide community target(s).
*
* @param c channel buffer
* @return target list
* @throws BgpParseException on decode error
*/
public static List<BgpValueType> decodeWideCommunityTlv(ChannelBuffer c) throws BgpParseException {
List<BgpValueType> targetTlv = new ArrayList<>();
while (c.readableBytes() > 0) {
if (c.readableBytes() < TYPE_LENGTH_SIZE) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, c.readableBytes());
}
byte atomType = c.readByte();
short atomLength = c.readShort();
if (c.readableBytes() < atomLength) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, atomLength);
}
if (atomType == WideCommunityIpV4Neighbour.TYPE) {
ChannelBuffer tempBuf = c.readBytes(atomLength);
WideCommunityIpV4Neighbour wideCommAtom = new WideCommunityIpV4Neighbour();
while (tempBuf.readableBytes() > 0) {
wideCommAtom.add(IpAddress.valueOf(tempBuf.readInt()), IpAddress.valueOf(tempBuf.readInt()));
}
targetTlv.add(wideCommAtom);
} else if (atomType == WideCommunityInteger.TYPE) {
ChannelBuffer tempBuf = c.readBytes(atomLength);
List<Integer> integer = new ArrayList<>();
while (tempBuf.readableBytes() > 0) {
integer.add(tempBuf.readInt());
}
targetTlv.add(new WideCommunityInteger(integer));
} else {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, atomLength);
}
}
return targetTlv;
}
Aggregations