*/
package org.opendaylight.protocol.bgp.parser;
+import com.google.common.collect.Maps;
+import java.util.Map;
+
+
/**
* Possible errors from implemented RFCs and drafts. Each error consists of error code and error subcode (code/subcode
* in comments).
*/
CEASE((short) 6, (short) 0);
- private final short code;
+ private static final Map<BGPErrorIdentifier, BGPError> VALUE_MAP;
+
+ static {
+ VALUE_MAP = Maps.newHashMap();
+ for (final BGPError enumItem : BGPError.values()) {
+ VALUE_MAP.put(enumItem.getErrorIdentifier(), enumItem);
+ }
+ }
- private final short subcode;
+ private final BGPErrorIdentifier errorId;
BGPError(final short code, final short subcode) {
- this.code = code;
- this.subcode = subcode;
+ this.errorId = new BGPErrorIdentifier(code, subcode);
}
public short getCode() {
- return this.code;
+ return this.errorId.getCode();
}
public short getSubcode() {
- return this.subcode;
+ return this.errorId.getSubCode();
}
- public static BGPError forValue(final int e, final int s) {
- if (e == 1) {
- if (s == 1) {
- return BGPError.CONNECTION_NOT_SYNC;
- }
- if (s == 2) {
- return BGPError.BAD_MSG_LENGTH;
- }
- if (s == 3) {
- return BGPError.BAD_MSG_TYPE;
- }
- } else if (e == 2) {
- if (s == 0) {
- return BGPError.UNSPECIFIC_OPEN_ERROR;
- }
- if (s == 1) {
- return BGPError.VERSION_NOT_SUPPORTED;
- }
- if (s == 2) {
- return BGPError.BAD_PEER_AS;
- }
- if (s == 3) {
- return BGPError.BAD_BGP_ID;
- }
- if (s == 4) {
- return BGPError.OPT_PARAM_NOT_SUPPORTED;
- }
- if (s == 6) {
- return BGPError.HOLD_TIME_NOT_ACC;
- }
- } else if (e == 3) {
- if (s == 1) {
- return BGPError.MALFORMED_ATTR_LIST;
- }
- if (s == 2) {
- return BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED;
- }
- if (s == 3) {
- return BGPError.WELL_KNOWN_ATTR_MISSING;
- }
- if (s == 4) {
- return BGPError.ATTR_FLAGS_MISSING;
- }
- if (s == 5) {
- return BGPError.ATTR_LENGTH_ERROR;
- }
- if (s == 6) {
- return BGPError.ORIGIN_ATTR_NOT_VALID;
+ private BGPErrorIdentifier getErrorIdentifier() {
+ return this.errorId;
+ }
+
+ /**
+ * Caret for combination of Error-type and Error-value
+ */
+ private static final class BGPErrorIdentifier {
+ private final short code;
+ private final short subcode;
+
+ BGPErrorIdentifier(final short code, final short subcode) {
+ this.code = code;
+ this.subcode = subcode;
+ }
+
+ public short getCode() {
+ return this.code;
+ }
+
+ public short getSubCode() {
+ return this.subcode;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + this.code;
+ result = prime * result + this.subcode;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final java.lang.Object obj) {
+ if (this == obj) {
+ return true;
}
- if (s == 8) {
- return BGPError.NEXT_HOP_NOT_VALID;
+ if (obj == null) {
+ return false;
}
- if (s == 9) {
- return BGPError.OPT_ATTR_ERROR;
+ if (this.getClass() != obj.getClass()) {
+ return false;
}
- if (s == 10) {
- return BGPError.NETWORK_NOT_VALID;
+ final BGPErrorIdentifier other = (BGPErrorIdentifier) obj;
+ if (this.code != other.code) {
+ return false;
}
- if (s == 11) {
- return BGPError.AS_PATH_MALFORMED;
+ if (this.subcode != other.subcode) {
+ return false;
}
- } else if (e == 4) {
- return BGPError.HOLD_TIMER_EXPIRED;
- } else if (e == 5) {
- return BGPError.FSM_ERROR;
- } else if (e == 6) {
- return BGPError.CEASE;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "type " + this.code + " value " + this.subcode;
+ }
+ }
+
+ public static BGPError forValue(final int code, final int subcode) {
+ final BGPError e = VALUE_MAP.get(new BGPErrorIdentifier((short) code, (short) subcode));
+ if (e != null) {
+ return e;
}
- throw new IllegalArgumentException("BGP Error code " + e + " and subcode " + s + " not recognized.");
+ throw new IllegalArgumentException("BGP Error code " + code + " and subcode " + subcode + " not recognized.");
}
}
int flagBits = 0;
final RestartFlags flags = grace.getRestartFlags();
- if (flags != null) {
- if (flags.isRestartState()) {
- flagBits |= RESTART_FLAG_STATE;
- }
+ if (flags != null && flags.isRestartState()) {
+ flagBits |= RESTART_FLAG_STATE;
}
int timeval = 0;
final Integer time = grace.getRestartTime();
* BGP peer acceptor that handles incoming bgp connections.
*/
public class BGPPeerAcceptorModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPPeerAcceptorModule {
+
+ private static final int PRIVILEGED_PORTS = 1024;
+
public BGPPeerAcceptorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
@Override
public void customValidation() {
// check if unix root user
- if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() && getBindingPort().getValue() < 1024) {
+ if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() && getBindingPort().getValue() < PRIVILEGED_PORTS) {
throw new AccessControlException("Unable to bind port " + getBindingPort().getValue() + " while running as non-root user.");
}
// Try to parse address
package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.base.Preconditions;
-
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-
import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
return ribOut;
}
- static final boolean isNone(final Object o) {
+ static boolean isNone(final Object o) {
return o == NLRIENTRY_NONE_VALUE;
}
}
\ No newline at end of file
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
public interface AdjRIBsOut {
- public void put(final RouteEncoder ribOut, final Object key, final Route newValue);
+ void put(final RouteEncoder ribOut, final Object key, final Route newValue);
}
import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
-
import java.util.List;
import java.util.Set;
-
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
listener.onSessionUp(new BGPSession() {
+ private static final long AS = 30L;
+
@Override
public void close() {
LOG.debug("Session {} closed", this);
@Override
public AsNumber getAsNumber() {
- return new AsNumber(30L);
+ return new AsNumber(AS);
}
});
} else if (!(message instanceof Keepalive)) {
// TODO: what should we do with in.getOspfRouterId()?
// final OspfNode in = ((OspfNodeCase) ri).getOspfNode();
- if (na != null) {
+ if (na != null && na.getNodeFlags() != null) {
final NodeFlagBits nf = na.getNodeFlags();
- if (nf != null) {
- if (nf.isAbr()) {
- ab.setRouterType(new AbrBuilder().setAbr(Boolean.TRUE).build());
- } else if (!nf.isExternal()) {
- ab.setRouterType(new InternalBuilder().setInternal(Boolean.TRUE).build());
- }
+ if (nf.isAbr()) {
+ ab.setRouterType(new AbrBuilder().setAbr(Boolean.TRUE).build());
+ } else if (!nf.isExternal()) {
+ ab.setRouterType(new InternalBuilder().setInternal(Boolean.TRUE).build());
}
}
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
-
import java.util.List;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
// FIXME: No TLVs by default, fallback to augments
}
- abstract protected void addVendorInformationTlvs(final T builder, final List<VendorInformationTlv> tlvs);
+ protected abstract void addVendorInformationTlvs(final T builder, final List<VendorInformationTlv> tlvs);
protected final void serializeVendorInformationTlvs(final List<VendorInformationTlv> tlvs, final ByteBuf buffer) {
if (tlvs != null && !tlvs.isEmpty()) {
final int lengthIdx = idx + LENGTH.length();
final int messageIdx = content.indexOf('.', lengthIdx);
final int length = Integer.parseInt(content.substring(lengthIdx, messageIdx));
- final int messageEndIdx = messageIdx + (length * 2) + 1; // dot
+ // dot
+ final int messageEndIdx = messageIdx + (length * 2) + 1;
// Assert that message is longer than minimum 4(header.length == 4)
// If length in PCEP message would be 0, loop would never end
Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+ MINIMAL_LENGTH);
- final String hexMessage = content.substring(messageIdx + 1, messageEndIdx); // dot
+ // dot
+ final String hexMessage = content.substring(messageIdx + 1, messageEndIdx);
byte[] message = null;
try {
message = Hex.decodeHex(hexMessage.toCharArray());