use of org.onlab.packet.Ip4Address in project up4 by omec-project.
the class InterfaceInsertCommand method doExecute.
@Override
protected void doExecute() throws Exception {
Up4AdminService app = get(Up4AdminService.class);
Ip4Address n3Addr = Ip4Address.valueOf(this.n3Addr);
print("Adding N3 interface address: %s", n3Addr.toString());
app.adminApply(UpfInterface.createN3From(n3Addr, sliceId));
}
use of org.onlab.packet.Ip4Address in project up4 by omec-project.
the class ReadInternalUp4StoreCommand method doExecute.
@Override
protected void doExecute() {
Up4Service up4Service = get(Up4Service.class);
Up4Store upfStore = get(Up4Store.class);
if (up4Service == null) {
print("Error: Up4Service is null");
return;
}
if (upfStore == null) {
print("Error: FabricUpfStore is null");
return;
}
Set<Ip4Address> bufferUes = upfStore.getBufferUe();
print("bufferFarIds size: " + bufferUes.size());
if (verbose) {
bufferUes.forEach(ue -> print("UEAddress{" + ue.toString() + "}"));
}
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class InstructionCodecTest method modIPSrcInstructionTest.
/**
* Tests the encoding of mod IPv4 src instructions.
*/
@Test
public void modIPSrcInstructionTest() {
final Ip4Address ip = Ip4Address.valueOf("1.2.3.4");
final L3ModificationInstruction.ModIPInstruction instruction = (L3ModificationInstruction.ModIPInstruction) Instructions.modL3Src(ip);
final ObjectNode instructionJson = instructionCodec.encode(instruction, context);
assertThat(instructionJson, matchesInstruction(instruction));
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class InstructionCodecTest method modIPDstInstructionTest.
/**
* Tests the encoding of mod IPv4 dst instructions.
*/
@Test
public void modIPDstInstructionTest() {
final Ip4Address ip = Ip4Address.valueOf("1.2.3.4");
final L3ModificationInstruction.ModIPInstruction instruction = (L3ModificationInstruction.ModIPInstruction) Instructions.modL3Dst(ip);
final ObjectNode instructionJson = instructionCodec.encode(instruction, context);
assertThat(instructionJson, matchesInstruction(instruction));
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpUpdate method parsePathAttributes.
/**
* Parse BGP Path Attributes from the BGP UPDATE message.
*
* @param bgpSession the BGP Session to use
* @param ctx the Channel Handler Context
* @param message the message to parse
* @param decodedBgpRoutes the container to store the decoded BGP Route
* Entries. It might already contain some route entries such as withdrawn
* IPv4 prefixes
* @throws BgpMessage.BgpParseException
*/
// CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
private static void parsePathAttributes(BgpSession bgpSession, ChannelHandlerContext ctx, ChannelBuffer message, DecodedBgpRoutes decodedBgpRoutes) throws BgpMessage.BgpParseException {
//
// Parsed values
//
// Mandatory
Short origin = -1;
// Mandatory
BgpRouteEntry.AsPath asPath = null;
// Legacy NLRI (RFC 4271). Mandatory NEXT_HOP if legacy NLRI is used
MpNlri legacyNlri = new MpNlri(BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4, BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST);
// Optional
long multiExitDisc = BgpConstants.Update.MultiExitDisc.LOWEST_MULTI_EXIT_DISC;
// Mandatory
Long localPref = null;
// Optional: unused
Long aggregatorAsNumber = null;
// Optional: unused
Ip4Address aggregatorIpAddress = null;
// Optional
Collection<MpNlri> mpNlriReachList = new ArrayList<>();
// Optional
Collection<MpNlri> mpNlriUnreachList = new ArrayList<>();
//
// Get and verify the Path Attributes Length
//
int pathAttributeLength = message.readUnsignedShort();
if (pathAttributeLength > message.readableBytes()) {
// ERROR: Malformed Attribute List
actionsBgpUpdateMalformedAttributeList(bgpSession, ctx);
String errorMsg = "Malformed Attribute List";
throw new BgpMessage.BgpParseException(errorMsg);
}
if (pathAttributeLength == 0) {
return;
}
//
// Parse the Path Attributes
//
int pathAttributeEnd = message.readerIndex() + pathAttributeLength;
while (message.readerIndex() < pathAttributeEnd) {
int attrFlags = message.readUnsignedByte();
if (message.readerIndex() >= pathAttributeEnd) {
// ERROR: Malformed Attribute List
actionsBgpUpdateMalformedAttributeList(bgpSession, ctx);
String errorMsg = "Malformed Attribute List";
throw new BgpMessage.BgpParseException(errorMsg);
}
int attrTypeCode = message.readUnsignedByte();
// The Attribute Flags
boolean optionalBit = ((0x80 & attrFlags) != 0);
boolean transitiveBit = ((0x40 & attrFlags) != 0);
boolean partialBit = ((0x20 & attrFlags) != 0);
boolean extendedLengthBit = ((0x10 & attrFlags) != 0);
// The Attribute Length
int attrLen = 0;
int attrLenOctets = 1;
if (extendedLengthBit) {
attrLenOctets = 2;
}
if (message.readerIndex() + attrLenOctets > pathAttributeEnd) {
// ERROR: Malformed Attribute List
actionsBgpUpdateMalformedAttributeList(bgpSession, ctx);
String errorMsg = "Malformed Attribute List";
throw new BgpMessage.BgpParseException(errorMsg);
}
if (extendedLengthBit) {
attrLen = message.readUnsignedShort();
} else {
attrLen = message.readUnsignedByte();
}
if (message.readerIndex() + attrLen > pathAttributeEnd) {
// ERROR: Malformed Attribute List
actionsBgpUpdateMalformedAttributeList(bgpSession, ctx);
String errorMsg = "Malformed Attribute List";
throw new BgpMessage.BgpParseException(errorMsg);
}
// Verify the Attribute Flags
verifyBgpUpdateAttributeFlags(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
//
switch(attrTypeCode) {
case BgpConstants.Update.Origin.TYPE:
// Attribute Type Code ORIGIN
origin = parseAttributeTypeOrigin(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
break;
case BgpConstants.Update.AsPath.TYPE:
// Attribute Type Code AS_PATH
asPath = parseAttributeTypeAsPath(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
break;
case BgpConstants.Update.NextHop.TYPE:
// Attribute Type Code NEXT_HOP
legacyNlri.nextHop4 = parseAttributeTypeNextHop(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
break;
case BgpConstants.Update.MultiExitDisc.TYPE:
// Attribute Type Code MULTI_EXIT_DISC
multiExitDisc = parseAttributeTypeMultiExitDisc(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
break;
case BgpConstants.Update.LocalPref.TYPE:
// Attribute Type Code LOCAL_PREF
localPref = parseAttributeTypeLocalPref(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
break;
case BgpConstants.Update.AtomicAggregate.TYPE:
// Attribute Type Code ATOMIC_AGGREGATE
parseAttributeTypeAtomicAggregate(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
// Nothing to do: this attribute is primarily informational
break;
case BgpConstants.Update.Aggregator.TYPE:
// Attribute Type Code AGGREGATOR
Pair<Long, Ip4Address> aggregator = parseAttributeTypeAggregator(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
aggregatorAsNumber = aggregator.getLeft();
aggregatorIpAddress = aggregator.getRight();
break;
case BgpConstants.Update.MpReachNlri.TYPE:
// Attribute Type Code MP_REACH_NLRI
MpNlri mpNlriReach = parseAttributeTypeMpReachNlri(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
if (mpNlriReach != null) {
mpNlriReachList.add(mpNlriReach);
}
break;
case BgpConstants.Update.MpUnreachNlri.TYPE:
// Attribute Type Code MP_UNREACH_NLRI
MpNlri mpNlriUnreach = parseAttributeTypeMpUnreachNlri(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
if (mpNlriUnreach != null) {
mpNlriUnreachList.add(mpNlriUnreach);
}
break;
default:
// NOTE: Parse any new Attribute Types if needed
if (!optionalBit) {
// ERROR: Unrecognized Well-known Attribute
actionsBgpUpdateUnrecognizedWellKnownAttribute(bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message);
String errorMsg = "Unrecognized Well-known Attribute: " + attrTypeCode;
throw new BgpMessage.BgpParseException(errorMsg);
}
// Skip the data from the unrecognized attribute
log.debug("BGP RX UPDATE message from {}: " + "Unrecognized Attribute Type {}", bgpSession.remoteInfo().address(), attrTypeCode);
message.skipBytes(attrLen);
break;
}
}
//
// Parse the NLRI (Network Layer Reachability Information)
//
int nlriLength = message.readableBytes();
try {
Collection<Ip4Prefix> addedPrefixes4 = parsePackedIp4Prefixes(nlriLength, message);
// Store it inside the legacy NLRI wrapper
legacyNlri.nlri4 = addedPrefixes4;
} catch (BgpMessage.BgpParseException e) {
// ERROR: Invalid Network Field
log.debug("Exception parsing NLRI from BGP peer {}: ", bgpSession.remoteInfo().bgpId(), e);
actionsBgpUpdateInvalidNetworkField(bgpSession, ctx);
// Rethrow the exception
throw e;
}
// Verify the Well-known Attributes
verifyBgpUpdateWellKnownAttributes(bgpSession, ctx, origin, asPath, localPref, legacyNlri, mpNlriReachList);
//
for (MpNlri mpNlri : mpNlriUnreachList) {
BgpRouteEntry bgpRouteEntry;
// The deleted IPv4 routes
for (Ip4Prefix prefix : mpNlri.nlri4) {
bgpRouteEntry = bgpSession.findBgpRoute(prefix);
if (bgpRouteEntry != null) {
decodedBgpRoutes.deletedUnicastRoutes4.put(prefix, bgpRouteEntry);
}
}
// The deleted IPv6 routes
for (Ip6Prefix prefix : mpNlri.nlri6) {
bgpRouteEntry = bgpSession.findBgpRoute(prefix);
if (bgpRouteEntry != null) {
decodedBgpRoutes.deletedUnicastRoutes6.put(prefix, bgpRouteEntry);
}
}
}
//
// Generate the added routes
//
mpNlriReachList.add(legacyNlri);
for (MpNlri mpNlri : mpNlriReachList) {
BgpRouteEntry bgpRouteEntry;
// The added IPv4 routes
for (Ip4Prefix prefix : mpNlri.nlri4) {
bgpRouteEntry = new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop4, origin.byteValue(), asPath, localPref);
bgpRouteEntry.setMultiExitDisc(multiExitDisc);
if (bgpRouteEntry.hasAsPathLoop(bgpSession.localInfo().asNumber())) {
log.debug("BGP RX UPDATE message IGNORED from {}: {} " + "nextHop {}: contains AS Path loop", bgpSession.remoteInfo().address(), prefix, mpNlri.nextHop4);
continue;
} else {
log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}", bgpSession.remoteInfo().address(), prefix, mpNlri.nextHop4);
}
// Remove from the collection of deleted routes
decodedBgpRoutes.deletedUnicastRoutes4.remove(prefix);
decodedBgpRoutes.addedUnicastRoutes4.put(prefix, bgpRouteEntry);
}
// The added IPv6 routes
for (Ip6Prefix prefix : mpNlri.nlri6) {
bgpRouteEntry = new BgpRouteEntry(bgpSession, prefix, mpNlri.nextHop6, origin.byteValue(), asPath, localPref);
bgpRouteEntry.setMultiExitDisc(multiExitDisc);
if (bgpRouteEntry.hasAsPathLoop(bgpSession.localInfo().asNumber())) {
log.debug("BGP RX UPDATE message IGNORED from {}: {} " + "nextHop {}: contains AS Path loop", bgpSession.remoteInfo().address(), prefix, mpNlri.nextHop6);
continue;
} else {
log.debug("BGP RX UPDATE message ADDED from {}: {} nextHop {}", bgpSession.remoteInfo().address(), prefix, mpNlri.nextHop6);
}
// Remove from the collection of deleted routes
decodedBgpRoutes.deletedUnicastRoutes6.remove(prefix);
decodedBgpRoutes.addedUnicastRoutes6.put(prefix, bgpRouteEntry);
}
}
}
Aggregations