Shashikanth VH
Committed by Gerrit Code Review

BGP routepolicy distribution bug fixes.

Change-Id: I2176e3872391658263d6817ac8850a3390de00de
......@@ -241,13 +241,12 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
afi = mpUnReach.afi();
safi = mpUnReach.safi();
}
}
if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
|| (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
if ((afi == Constants.AFI_FLOWSPEC_VALUE) || (afi == Constants.AFI_VALUE)) {
//unfeasible route length
cb.writeShort(0);
}
}
}
......
......@@ -171,6 +171,7 @@ public class As4Path implements BgpValueType {
if ((as4pathSet != null) && (as4pathSeq != null)) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
if (as4pathSeq.size() != 0) {
cb.writeByte(AsPath.ASPATH_SEQ_TYPE);
cb.writeByte(as4pathSeq.size());
......@@ -180,6 +181,7 @@ public class As4Path implements BgpValueType {
int asLen = cb.writerIndex() - iAsLenIndex;
cb.setByte(iAsLenIndex, (byte) (asLen - 1));
}
} else {
cb.writeByte(0);
}
......
......@@ -208,15 +208,16 @@ public class AsPath implements BgpValueType {
if (isaspathSet()) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
if (aspathSeq.size() != 0) {
cb.writeByte(ASPATH_SEQ_TYPE);
cb.writeByte(aspathSeq.size());
for (int j = 0; j < aspathSeq.size(); j++) {
cb.writeShort(aspathSeq.get(j));
}
int asLen = cb.writerIndex() - iAsLenIndex;
cb.setByte(iAsLenIndex, (byte) (asLen - 1));
}
} else {
cb.writeByte(0);
}
......
......@@ -163,7 +163,6 @@ public class WideCommunityAttrHeader implements BgpValueType {
c.writeShort(TYPE);
c.writeByte(flag);
c.writeByte(hopCount);
c.writeShort(length);
return c.writerIndex() - iLenStartIndex;
}
......
......@@ -97,8 +97,8 @@ public class WideCommunityIpV4Neighbour implements BgpValueType {
while (listIterator.hasNext()) {
IpV4Neighbour speaker = listIterator.next();
if (speaker instanceof IpV4Neighbour) {
c.writeInt(Integer.valueOf(speaker.localSpeaker.toString()));
c.writeInt(Integer.valueOf(speaker.remoteSpeaker.toString()));
c.writeBytes(speaker.localSpeaker().toOctets());
c.writeBytes(speaker.remoteSpeaker().toOctets());
}
}
......
......@@ -43,10 +43,10 @@ import java.util.Objects;
public class WideCommunity implements BgpValueType {
private static final Logger log = LoggerFactory.getLogger(WideCommunity.class);
public static final byte TYPE = (byte) 254; /* TODO: IANA Assigned */
public static final byte TYPE = (byte) 129;
public static final short LENGTH = 4;
public static final byte TYPE_LENGTH_SIZE = 3;
public static final byte FLAGS = (byte) 0x40;
public static final byte FLAGS = (byte) 0x90;
private WideCommunityAttrHeader wideCommunityHeader;
private int community;
private int localAsn;
......@@ -238,6 +238,9 @@ public class WideCommunity implements BgpValueType {
wideCommunityHeader.write(c);
int iComLengthIndex = c.writerIndex();
c.writeShort(0);
c.writeInt(community);
c.writeInt(localAsn);
c.writeInt(contextAsn);
......@@ -275,6 +278,9 @@ public class WideCommunity implements BgpValueType {
c.setShort(iTargetLenIndex, (short) (length - 2));
}
length = c.writerIndex() - iComLengthIndex;
c.setShort(iComLengthIndex, (short) (length - 2));
length = c.writerIndex() - iLengthIndex;
c.setShort(iLengthIndex, (short) (length - 2));
......
......@@ -135,7 +135,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
if (decisionResult < 0) {
if (decisionResult <= 0) {
for (BgpNodeListener l : bgpController.listener()) {
l.addNode((BgpNodeLSNlriVer4) nlri, details);
}
......@@ -155,7 +155,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
if (decisionResult < 0) {
if (decisionResult <= 0) {
linkTree.replace(linkLsIdentifier, detailsLocRib);
for (BgpLinkListener l : bgpController.linkListener()) {
l.addLink((BgpLinkLsNlriVer4) nlri, details);
......@@ -175,7 +175,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
if (decisionResult < 0) {
if (decisionResult <= 0) {
prefixTree.replace(prefixIdentifier, detailsLocRib);
log.debug("Local RIB update prefix: {}", detailsLocRib.toString());
}
......
......@@ -168,7 +168,7 @@ public class BgpPeerImpl implements BgpPeer {
List<BgpValueType> attributesList = new LinkedList<>();
byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
byte sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE;
byte sAfi = Constants.SAFI_FLOWSPEC_VALUE;
boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE,
Constants.AFI_FLOWSPEC_VALUE,
......@@ -191,10 +191,10 @@ public class BgpPeerImpl implements BgpPeer {
return;
}
if ((wideCommunity != null) && (isVpnRpdCapabilitySet)) {
sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
} else if (isVpnFsCapabilitySet) {
if (isVpnFsCapabilitySet) {
sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE;
} else if (isVpnRpdCapabilitySet) {
sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
}
attributesList.add(new Origin((byte) 0));
......@@ -223,7 +223,9 @@ public class BgpPeerImpl implements BgpPeer {
}
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));
......