private long peerAs = 0L;
private int asPathLength = 0;
private Long localPref;
- private Long multiExitDisc;
+ private long multiExitDisc;
private BgpOrigin origin;
private boolean resolved;
localPref = attrLocalPref != null ? attrLocalPref.getPref() : null;
final MultiExitDisc attrMed = attributes.getMultiExitDisc();
- multiExitDisc = attrMed != null ? attrMed.getMed() : null;
+ if (attrMed != null) {
+ final Long med = attrMed.getMed();
+ multiExitDisc = med == null ? 0L : med;
+ } else {
+ multiExitDisc = 0L;
+ }
final Origin attrOrigin = attributes.getOrigin();
origin = attrOrigin != null ? attrOrigin.getValue() : null;
}
@Override
- public Long getMultiExitDisc() {
+ public long getMultiExitDisc() {
resolveValues();
return this.multiExitDisc;
}
int result = 1;
result = prime * result + this.attributes.hashCode();
result = prime * result + (this.localPref == null ? 0 : this.localPref.hashCode());
- result = prime * result + (this.multiExitDisc == null ? 0 : this.multiExitDisc.hashCode());
+ result = prime * result + Long.hashCode(multiExitDisc);
result = prime * result + (this.origin == null ? 0 : this.origin.hashCode());
return result;
}
} else if (!this.localPref.equals(other.localPref)) {
return false;
}
- if (this.multiExitDisc == null) {
- if (other.multiExitDisc != null) {
- return false;
- }
- } else if (!this.multiExitDisc.equals(other.multiExitDisc)) {
+ if (this.multiExitDisc != other.multiExitDisc) {
return false;
}
if (this.origin != other.origin) {
* FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
* before we ever get here.
*/
- if (this.bestState.getLocalPref() == null && state.getLocalPref() != null) {
- return true;
- }
- if (this.bestState.getLocalPref() != null && state.getLocalPref() == null) {
- return false;
- }
- if (state.getLocalPref() != null && state.getLocalPref() > this.bestState.getLocalPref()) {
+ final Long bestLocal = this.bestState.getLocalPref();
+ final Long stateLocal = state.getLocalPref();
+ if (stateLocal != null) {
+ if (bestLocal == null) {
+ return true;
+ }
+
+ final Boolean bool = firstLower(stateLocal, bestLocal);
+ if (bool != null) {
+ return bool;
+ }
+ } else if (bestLocal != null) {
return false;
}
- if (state.getLocalPref() != null && state.getLocalPref() < this.bestState.getLocalPref()) {
- return true;
- }
+
// 3. prefer learned path
// - we assume that all paths are learned
return no.ordinal() > bo.ordinal();
}
// FIXME: we should be able to cache the best AS
- final Long bestAs = this.bestState.getPeerAs();
- final Long newAs = state.getPeerAs();
+ final long bestAs = this.bestState.getPeerAs();
+ final long newAs = state.getPeerAs();
/*
* Checks 6 and 7 are mutually-exclusive, as MEDs are comparable
* relationship.
*
*/
- if (bestAs.equals(newAs)) {
+ if (bestAs == newAs) {
// 6. prefer the path with the lowest multi-exit discriminator (MED)
- if (this.bestState.getMultiExitDisc() != null || state.getMultiExitDisc() != null) {
- final Long bmed = this.bestState.getMultiExitDisc();
- final Long nmed = state.getMultiExitDisc();
- return nmed >= bmed;
+ final Boolean cmp = firstLower(this.bestState.getMultiExitDisc(), state.getMultiExitDisc());
+ if (cmp != null) {
+ return cmp;
}
} else {
/*
*/
return true;
}
+
+ private static Boolean firstLower(final long first, final long second) {
+ return first < second ? Boolean.TRUE : first == second ? null : Boolean.FALSE;
+
+ }
}