use of org.onosproject.bgpio.types.As4Path in project onos by opennetworkinglab.
the class BgpPeerImpl method sendFlowSpecUpdateMessageToPeer.
/**
* Send flow specification update message to peer.
*
* @param operType operation type
* @param routeKey flow rule key
* @param flowSpec flow specification details
* @param wideCommunity for route policy
*/
public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) {
List<BgpValueType> attributesList = new LinkedList<>();
byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
byte sAfi = Constants.SAFI_FLOWSPEC_VALUE;
boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_VALUE, Constants.SAFI_FLOWSPEC_VALUE);
boolean isVpnFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_VALUE, Constants.VPN_SAFI_FLOWSPEC_VALUE);
boolean isRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_RPD_VALUE, Constants.SAFI_FLOWSPEC_RPD_VALUE);
boolean isVpnRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_RPD_VALUE, Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE);
if ((!isFsCapabilitySet) && (!isVpnFsCapabilitySet) && (!isRpdCapabilitySet) && (!isVpnRpdCapabilitySet)) {
log.debug("Peer do not support BGP flow spec capability", channel.getRemoteAddress());
return;
}
if (isVpnFsCapabilitySet) {
sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE;
} else if (isVpnRpdCapabilitySet) {
sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
}
attributesList.add(new Origin((byte) 0));
if (sessionType != 0) {
// EBGP
if (!bgpController.getConfig().getLargeASCapability()) {
List<Short> aspathSet = new ArrayList<>();
List<Short> aspathSeq = new ArrayList<>();
aspathSeq.add((short) bgpController.getConfig().getAsNumber());
AsPath asPath = new AsPath(aspathSet, aspathSeq);
attributesList.add(asPath);
} else {
List<Integer> aspathSet = new ArrayList<>();
List<Integer> aspathSeq = new ArrayList<>();
aspathSeq.add(bgpController.getConfig().getAsNumber());
As4Path as4Path = new As4Path(aspathSet, aspathSeq);
attributesList.add(as4Path);
}
attributesList.add(new Med(0));
} else {
attributesList.add(new AsPath());
attributesList.add(new Med(0));
attributesList.add(new LocalPref(100));
}
attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv()));
if (wideCommunity != null) {
attributesList.add(wideCommunity);
}
if (operType == FlowSpecOperation.ADD) {
attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
} else if (operType == FlowSpecOperation.DELETE) {
attributesList.add(new MpUnReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
}
BgpMessage msg = Controller.getBgpMessageFactory4().updateMessageBuilder().setBgpPathAttributes(attributesList).build();
log.debug("Sending flow spec update message to {}", channel.getRemoteAddress());
channel.write(Collections.singletonList(msg));
}
use of org.onosproject.bgpio.types.As4Path in project onos by opennetworkinglab.
the class BgpPeerImpl method sendEvpnUpdateMessageToPeer.
private void sendEvpnUpdateMessageToPeer(FlowSpecOperation operType, IpAddress nextHop, List<BgpValueType> extcommunity, List<BgpEvpnNlri> evpnNlris) {
List<BgpValueType> attributesList = new LinkedList<>();
byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
short afi = Constants.AFI_EVPN_VALUE;
byte safi = Constants.SAFI_EVPN_VALUE;
boolean isEvpnCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, afi, safi);
if (!isEvpnCapabilitySet) {
log.debug("Peer do not support BGP Evpn capability", channel.getRemoteAddress());
return;
}
attributesList.add(new Origin((byte) 0));
if (sessionType != 0) {
// EBGP
if (!bgpController.getConfig().getLargeASCapability()) {
List<Short> aspathSet = new ArrayList<>();
List<Short> aspathSeq = new ArrayList<>();
aspathSeq.add((short) bgpController.getConfig().getAsNumber());
AsPath asPath = new AsPath(aspathSet, aspathSeq);
attributesList.add(asPath);
} else {
List<Integer> aspathSet = new ArrayList<>();
List<Integer> aspathSeq = new ArrayList<>();
aspathSeq.add(bgpController.getConfig().getAsNumber());
As4Path as4Path = new As4Path(aspathSet, aspathSeq);
attributesList.add(as4Path);
}
} else {
attributesList.add(new AsPath());
}
if (!extcommunity.isEmpty()) {
attributesList.add(new BgpExtendedCommunity(extcommunity));
}
if (operType == FlowSpecOperation.ADD || operType == FlowSpecOperation.UPDATE) {
attributesList.add(new MpReachNlri(evpnNlris, afi, safi, nextHop.getIp4Address()));
} else if (operType == FlowSpecOperation.DELETE) {
attributesList.add(new MpUnReachNlri(evpnNlris, afi, safi));
}
BgpMessage msg = Controller.getBgpMessageFactory4().updateMessageBuilder().setBgpPathAttributes(attributesList).build();
channel.write(Collections.singletonList(msg));
}
use of org.onosproject.bgpio.types.As4Path 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.As4Path in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest30.
/**
* This test case checks update message with as4 path attribute.
*/
@Test
public void bgpUpdateMessageTest30() 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, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x21, 0x40, 0x01, 0x01, 0x00, (byte) 0xc0, 0x11, 0x0a, 0x02, 0x02, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x28, 0x00, 0x01, 0x40, 0x02, 0x06, 0x02, 0x02, 0x5b, (byte) 0xa0, 0x5b, (byte) 0xa0, 0x40, 0x03, 0x04, (byte) 0xac, 0x10, 0x03, 0x01, 0x08, 0x28 };
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;
assertThat(other.getHeader().getMarker(), is(MARKER));
assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
assertThat(other.getHeader().getLength(), is((short) 58));
BgpValueType testPathAttribute;
Origin origin;
As4Path as4Path;
AsPath asPath;
NextHop nextHop;
List<BgpValueType> pathAttributes = new LinkedList<>();
BgpPathAttributes actualpathAttribute = other.bgpPathAttributes();
pathAttributes = actualpathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributes.listIterator();
OriginType originValue = OriginType.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
as4Path = (As4Path) testPathAttribute;
ListIterator<Integer> listIterator2 = as4Path.as4PathSeq().listIterator();
assertThat(listIterator2.next(), is(655361));
testPathAttribute = listIterator.next();
asPath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator3 = asPath.asPathSeq().listIterator();
assertThat(listIterator3.next(), is((short) 23456));
testPathAttribute = listIterator.next();
nextHop = (NextHop) testPathAttribute;
byte[] nextHopAddr = new byte[] { (byte) 0xac, 0x10, 0x03, 0x01 };
assertThat(nextHop.nextHop().toOctets(), is(nextHopAddr));
ListIterator<IpPrefix> listIterator1 = other.nlri().listIterator();
byte[] prefix = new byte[] { 0x28, 0x00, 0x00, 0x00 };
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 8));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
Aggregations