use of org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv in project onos by opennetworkinglab.
the class BgpOpenMsgTest method openMessageTest11.
/**
* This test case checks the changes made in.
* BgpOpenMsg
* BgpOpenMsgVer4
* BgpChannelHandler
* as bug fix for bug 8036
*/
@Test
public void openMessageTest11() throws BgpParseException {
/*
Open message received after implementing the changes for the fix. Here we are considering connection type
as IPV4_IPV6.
*/
byte[] openMsg = 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) 0x3d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0x93, (byte) 0x20, (byte) 0x02, (byte) 0x1e, // ------------ IPV4 Multiprotocol Extensions Capability -----------------------------------------------
(byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, // ------------ IPV6 Multiprotocol Extensions Capability -----------------------------------------------
(byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x01, // -----------------------------------------------------------------------------------------------------
(byte) 0x41, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x01, (byte) 0x04, (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x85 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(openMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpOpenMsg.class));
BgpOpenMsg receivedMsg = (BgpOpenMsg) message;
List<BgpValueType> capabilityTlvList = receivedMsg.getCapabilityTlv();
ListIterator<BgpValueType> capabilityTlvListIterator = capabilityTlvList.listIterator();
boolean isIPv4UnicastCapabilityPresent = false;
boolean isIPv6UnicastCapabilityPresent = false;
while (capabilityTlvListIterator.hasNext()) {
BgpValueType bgpLSAttrib = capabilityTlvListIterator.next();
if (bgpLSAttrib instanceof MultiProtocolExtnCapabilityTlv) {
MultiProtocolExtnCapabilityTlv mltiPrtclExtnCapabilityTlv = ((MultiProtocolExtnCapabilityTlv) bgpLSAttrib);
if (mltiPrtclExtnCapabilityTlv.getAfi() == 1 && mltiPrtclExtnCapabilityTlv.getSafi() == 1) {
isIPv4UnicastCapabilityPresent = true;
} else if (((MultiProtocolExtnCapabilityTlv) bgpLSAttrib).getAfi() == 2 && mltiPrtclExtnCapabilityTlv.getSafi() == 1) {
isIPv6UnicastCapabilityPresent = true;
}
}
}
assertThat(isIPv4UnicastCapabilityPresent, is(true));
assertThat(isIPv6UnicastCapabilityPresent, is(true));
}
use of org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv 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.MultiProtocolExtnCapabilityTlv in project onos by opennetworkinglab.
the class BgpPeerImpl method isCapabilitySupported.
/**
* Check if peer support capability.
*
* @param type capability type
* @param afi address family identifier
* @param sAfi subsequent address family identifier
* @return true if capability is supported, otherwise false
*/
public final boolean isCapabilitySupported(short type, short afi, byte sAfi) {
List<BgpValueType> capability = sessionInfo.remoteBgpCapability();
ListIterator<BgpValueType> listIterator = capability.listIterator();
while (listIterator.hasNext()) {
BgpValueType tlv = listIterator.next();
if (tlv.getType() == type) {
if (tlv.getType() == MultiProtocolExtnCapabilityTlv.TYPE) {
MultiProtocolExtnCapabilityTlv temp = (MultiProtocolExtnCapabilityTlv) tlv;
if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) {
log.debug("Multi prorotcol extension capabality TLV is true");
return true;
}
} else if (tlv.getType() == RpdCapabilityTlv.TYPE) {
RpdCapabilityTlv temp = (RpdCapabilityTlv) tlv;
if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) {
log.debug("RPD capabality TLV is true");
return true;
}
}
}
}
log.debug("IS capabality is not supported ");
return false;
}
use of org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest8.
@Test
public void bgpOpenMessageTest8() throws InterruptedException {
// Open message with route policy distribution capability
short afi = Constants.AFI_FLOWSPEC_RPD_VALUE;
byte res = 0;
byte safi = Constants.SAFI_FLOWSPEC_RPD_VALUE;
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
bgpControllerImpl.getConfig().setFlowSpecRpdCapability(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.MultiProtocolExtnCapabilityTlv in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest5.
@Test
public void bgpOpenMessageTest5() throws InterruptedException {
// Open message with LS capability
short afi = 16388;
byte res = 0;
byte safi = 71;
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
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));
result = peer1.peerFrameDecoder.receivedKeepaliveMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
}
Aggregations