use of org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv in project onos by opennetworkinglab.
the class BgpChannelHandler method capabilityValidation.
/**
* Capability Validation.
*
* @param h channel handler
* @param openmsg open message
* @return success or failure
* @throws BgpParseException
*/
private boolean capabilityValidation(BgpChannelHandler h, BgpOpenMsg openmsg) throws BgpParseException {
log.debug("capability validation");
boolean isFourOctetCapabilityExits = false;
boolean isRpdCapabilityExits = false;
int capAsNum = 0;
byte sendReceive = 0;
List<BgpValueType> capabilityTlv = openmsg.getCapabilityTlv();
ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
List<BgpValueType> unSupportedCapabilityTlv = new CopyOnWriteArrayList<BgpValueType>();
ListIterator<BgpValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator();
BgpValueType tempTlv;
boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability();
boolean isFlowSpecRpdCapabilityCfg = h.bgpconfig.flowSpecRpdCapability();
boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability();
boolean isFlowSpecIpv4CapabilityCfg = false;
boolean isFlowSpecVpnv4CapabilityCfg = false;
MultiProtocolExtnCapabilityTlv tempCapability;
boolean isMultiProtocolLsCapability = false;
boolean isMultiProtocolFlowSpecCapability = false;
boolean isMultiProtocolVpnFlowSpecCapability = false;
BgpCfg.FlowSpec flowSpec = h.bgpconfig.flowSpecCapability();
boolean isEvpnCapability = false;
boolean isEvpnCapabilityCfg = h.bgpconfig.getEvpnCapability();
if (flowSpec == BgpCfg.FlowSpec.IPV4) {
isFlowSpecIpv4CapabilityCfg = true;
} else if (flowSpec == BgpCfg.FlowSpec.VPNV4) {
isFlowSpecVpnv4CapabilityCfg = true;
} else if (flowSpec == BgpCfg.FlowSpec.IPV4_VPNV4) {
isFlowSpecIpv4CapabilityCfg = true;
isFlowSpecVpnv4CapabilityCfg = true;
}
while (listIterator.hasNext()) {
BgpValueType tlv = listIterator.next();
if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) {
tempCapability = (MultiProtocolExtnCapabilityTlv) tlv;
if (Constants.SAFI_FLOWSPEC_VALUE == tempCapability.getSafi()) {
isMultiProtocolFlowSpecCapability = true;
}
if (Constants.SAFI_EVPN_VALUE == tempCapability.getSafi()) {
isEvpnCapability = true;
}
if (Constants.VPN_SAFI_FLOWSPEC_VALUE == tempCapability.getSafi()) {
isMultiProtocolVpnFlowSpecCapability = true;
}
if (SAFI == tempCapability.getSafi()) {
isMultiProtocolLsCapability = true;
}
}
if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
isFourOctetCapabilityExits = true;
capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
}
if (tlv.getType() == RpdCapabilityTlv.TYPE) {
isRpdCapabilityExits = true;
sendReceive = ((RpdCapabilityTlv) tlv).sendReceive();
}
}
if (isFourOctetCapabilityExits) {
if (capAsNum > MAX_AS2_NUM) {
if (openmsg.getAsNumber() != AS_TRANS) {
throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
}
} else {
if (capAsNum != openmsg.getAsNumber()) {
throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
}
}
}
if (isRpdCapabilityExits) {
if (sendReceive > 2) {
throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, null);
}
}
if ((isLsCapabilityCfg)) {
if (!isMultiProtocolLsCapability) {
tempTlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI);
unSupportedCapabilityTlv.add(tempTlv);
}
}
if (isFlowSpecIpv4CapabilityCfg) {
if (!isMultiProtocolFlowSpecCapability) {
tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_FLOWSPEC_VALUE, RES, Constants.SAFI_FLOWSPEC_VALUE);
unSupportedCapabilityTlv.add(tempTlv);
}
}
if (isEvpnCapabilityCfg) {
if (!isEvpnCapability) {
tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_EVPN_VALUE, RES, Constants.SAFI_EVPN_VALUE);
unSupportedCapabilityTlv.add(tempTlv);
}
}
if (isFlowSpecVpnv4CapabilityCfg) {
if (!isMultiProtocolVpnFlowSpecCapability) {
tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_FLOWSPEC_VALUE, RES, Constants.VPN_SAFI_FLOWSPEC_VALUE);
unSupportedCapabilityTlv.add(tempTlv);
}
}
if ((isLargeAsCapabilityCfg)) {
if (!isFourOctetCapabilityExits) {
tempTlv = new FourOctetAsNumCapabilityTlv(h.bgpconfig.getAsNumber());
unSupportedCapabilityTlv.add(tempTlv);
}
}
if ((isFlowSpecRpdCapabilityCfg)) {
if (!isRpdCapabilityExits) {
tempTlv = new RpdCapabilityTlv(Constants.RPD_CAPABILITY_SEND_VALUE);
unSupportedCapabilityTlv.add(tempTlv);
}
}
if (unSupportedCapabilityTlv.size() == MAX_UNSUPPORTED_CAPABILITY) {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
while (unSupportedCaplistIterator.hasNext()) {
BgpValueType tlv = unSupportedCaplistIterator.next();
tlv.write(buffer);
}
throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, buffer);
} else {
return true;
}
}
use of org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest6.
@Test
public void bgpOpenMessageTest6() throws InterruptedException {
// Open message with as4 capability
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
bgpControllerImpl.getConfig().setLargeASCapability(true);
BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
peer1.connect(connectToSocket);
boolean result;
result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
}
use of org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest4.
@Test
public void bgpOpenMessageTest4() throws InterruptedException {
// Open message with invalid as number
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(766545);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
peer1.connect(connectToSocket);
boolean result;
result = peer1.peerFrameDecoder.receivedNotificationMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
}
use of org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest7.
@Test
public void bgpOpenMessageTest7() throws InterruptedException {
// Open message with both LS capability and as4 capability
short afi = 16388;
byte res = 0;
byte safi = 71;
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
bgpControllerImpl.getConfig().setLargeASCapability(true);
BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
bgpControllerImpl.getConfig().setLsCapability(true);
BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
peer1.connect(connectToSocket);
boolean result;
result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
}
use of org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv in project onos by opennetworkinglab.
the class BgpOpenMsgVer4 method parseCapabilityTlv.
/**
* Parsing capabilities.
*
* @param cb of type channel buffer
* @return capabilityTlv of open message
* @throws BgpParseException while parsing capabilities
*/
protected static LinkedList<BgpValueType> parseCapabilityTlv(ChannelBuffer cb) throws BgpParseException {
LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
while (cb.readableBytes() > 0) {
BgpValueType tlv;
short type = cb.readByte();
short length = cb.readByte();
switch(type) {
case FourOctetAsNumCapabilityTlv.TYPE:
log.debug("FourOctetAsNumCapabilityTlv");
if (FourOctetAsNumCapabilityTlv.LENGTH != length) {
throw new BgpParseException("Invalid length received for FourOctetAsNumCapabilityTlv.");
}
if (length > cb.readableBytes()) {
throw new BgpParseException("Four octet as num tlv length" + " is more than readableBytes.");
}
int as4Num = cb.readInt();
tlv = new FourOctetAsNumCapabilityTlv(as4Num);
break;
case RpdCapabilityTlv.TYPE:
log.debug("RpdCapability");
if (RpdCapabilityTlv.LENGTH != length) {
throw new BgpParseException("Invalid length received for RpdCapability.");
}
if (length > cb.readableBytes()) {
throw new BgpParseException("Four octet as num TLV length" + " is more than readableBytes.");
}
short rpdAfi = cb.readShort();
byte rpdAsafi = cb.readByte();
byte sendReceive = cb.readByte();
tlv = new RpdCapabilityTlv(sendReceive);
break;
case MultiProtocolExtnCapabilityTlv.TYPE:
log.debug("MultiProtocolExtnCapabilityTlv");
if (MultiProtocolExtnCapabilityTlv.LENGTH != length) {
throw new BgpParseException("Invalid length received for MultiProtocolExtnCapabilityTlv.");
}
if (length > cb.readableBytes()) {
throw new BgpParseException("BGP LS tlv length is more than readableBytes.");
}
short afi = cb.readShort();
byte res = cb.readByte();
byte safi = cb.readByte();
tlv = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
break;
case RouteRefreshCapabilityTlv.TYPE:
log.debug("RouteRefreshCapabilityTlv");
if (RouteRefreshCapabilityTlv.LENGTH != length) {
throw new BgpParseException("Invalid length received for RouteRefreshCapabilityTlv.");
}
tlv = new RouteRefreshCapabilityTlv(true);
break;
default:
log.debug("Warning: Unsupported TLV: " + type);
cb.skipBytes(length);
continue;
}
capabilityTlv.add(tlv);
}
return capabilityTlv;
}
Aggregations