use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest10.
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpAttrNodeFlagBitTlv.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest10() 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, (byte) 0x93, 0x02, 0x00, 0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x78, // origin
0x04, // origin
0x01, // origin
0x01, // origin
0x00, // as_path
0x40, // as_path
0x02, // as_path
0x04, // as_path
0x02, // as_path
0x01, // as_path
(byte) 0xfd, // as_path
(byte) 0xe9, // med
(byte) 0x80, // med
0x04, // med
0x04, // med
0x00, // med
0x00, // med
0x00, // med
0x00, // mpreach
(byte) 0x80, // mpreach
0x0e, // mpreach
0x53, // mpreach
0x40, // mpreach
0x04, // mpreach
0x47, // nexthop
0x04, // nexthop
0x04, // nexthop
0x00, // nexthop
0x00, // nexthop
0x01, // reserved
0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
0x00, // link nlri
(byte) 0x95, // link nlri
0x02, // link nlri
0x50, // link nlri
0x21, // linkstate attr
(byte) 0x80, // linkstate attr
0x1d, // linkstate attr
0x0D, // BgpAttrNodeRouterId
0x04, // BgpAttrNodeRouterId
0x04, // BgpAttrNodeRouterId
0x00, // BgpAttrNodeRouterId
0x04, // BgpAttrNodeRouterId
(byte) 0x15, // BgpAttrNodeRouterId
0x15, // BgpAttrNodeRouterId
0x15, // BgpAttrNodeRouterId
0x15, 0x04, 0x00, 0x00, 0x01, // BgpAttrNodeFlagBitTlv
0x20 };
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;
byte[] marker = 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 };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 147));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
while (listIterator1.hasNext()) {
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
OriginType originValue = OriginType.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
assertThat(mpReach.mpReachNlriLen(), is((int) 83));
assertThat(mpReach.getType(), is((short) 14));
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
BgpAttrNodeFlagBitTlv obj = new BgpAttrNodeFlagBitTlv(false, false, true, false);
assertThat(((BgpAttrNodeFlagBitTlv) list.next()).equals(obj), is(true));
}
use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.
the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest14.
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrMplsProtocolMask.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest14() 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, (byte) 0x93, 0x02, 0x00, 0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x78, // origin
0x04, // origin
0x01, // origin
0x01, // origin
0x00, // as_path
0x40, // as_path
0x02, // as_path
0x04, // as_path
0x02, // as_path
0x01, // as_path
(byte) 0xfd, // as_path
(byte) 0xe9, // med
(byte) 0x80, // med
0x04, // med
0x04, // med
0x00, // med
0x00, // med
0x00, // med
0x00, // mpreach
(byte) 0x80, // mpreach
0x0e, // mpreach
0x53, // mpreach
0x40, // mpreach
0x04, // mpreach
0x47, // nexthop
0x04, // nexthop
0x04, // nexthop
0x00, // nexthop
0x00, // nexthop
0x01, // reserved
0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
0x00, // link nlri
(byte) 0x95, // link nlri
0x02, // link nlri
0x50, // link nlri
0x21, // linkstate attr
(byte) 0x80, // linkstate attr
0x1d, // linkstate attr
0x0D, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
0x00, // BgpAttrRouterIdV4
0x04, // BgpAttrRouterIdV4
(byte) 0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, // BgpAttrRouterIdV4
0x15, 0x04, 0x46, 0x00, 0x01, // BgpLinkAttrMplsProtocolMask
(byte) 0xC0 };
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;
byte[] marker = 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 };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 147));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
while (listIterator1.hasNext()) {
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
OriginType originValue = OriginType.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
assertThat(mpReach.mpReachNlriLen(), is((int) 83));
assertThat(mpReach.getType(), is((short) 14));
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
BgpLinkAttrMplsProtocolMask obj = new BgpLinkAttrMplsProtocolMask(true, true);
assertThat(((BgpLinkAttrMplsProtocolMask) list.next()).equals(obj), is(true));
}
use of org.onlab.packet.Ip4Address in project fabric-tna by stratum.
the class FabricUpfTranslator method fabricEntryToUpfTerminationUplink.
/**
* Translate a fabric.p4 termination table entry to a uplink UpfTermination instance for easier handling.
*
* @param entry the fabric.p4 entry to translate
* @return the corresponding UpfTerminationUplink
* @throws UpfProgrammableException if the entry cannot be translated
*/
public UpfTerminationUplink fabricEntryToUpfTerminationUplink(FlowRule entry) throws UpfProgrammableException {
assertTableId(entry, FABRIC_INGRESS_UPF_UPLINK_TERMINATIONS);
UpfTerminationUplink.Builder builder = UpfTerminationUplink.builder();
Pair<PiCriterion, PiTableAction> matchActionPair = FabricUpfTranslatorUtil.fabricEntryToPiPair(entry);
PiCriterion match = matchActionPair.getLeft();
PiAction action = (PiAction) matchActionPair.getRight();
if (!FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_UE_SESSION_ID) || !FabricUpfTranslatorUtil.fieldIsPresent(match, HDR_APP_ID)) {
throw new UpfProgrammableException("Malformed uplink termination from dataplane!: " + entry);
}
// Match keys
Ip4Address ueSessionId = FabricUpfTranslatorUtil.getFieldAddress(match, HDR_UE_SESSION_ID);
builder.withUeSessionId(ueSessionId);
byte applicationId = FabricUpfTranslatorUtil.getFieldByte(match, HDR_APP_ID);
builder.withApplicationId(applicationId);
PiActionId actionId = action.id();
builder.withCounterId(FabricUpfTranslatorUtil.getParamInt(action, CTR_ID));
if (actionId.equals(FABRIC_INGRESS_UPF_UPLINK_DROP)) {
builder.needsDropping(true);
} else {
builder.withAppMeterIdx(FabricUpfTranslatorUtil.getParamShort(action, APP_METER_IDX));
if (actionId.equals(FABRIC_INGRESS_UPF_APP_FWD)) {
builder.withTrafficClass(FabricUpfTranslatorUtil.getParamByte(action, TC));
}
}
return builder.build();
}
use of org.onlab.packet.Ip4Address in project fabric-tna by stratum.
the class FabricUpfTranslatorUtil method getFieldPrefix.
static Ip4Prefix getFieldPrefix(PiCriterion criterion, PiMatchFieldId fieldId) {
Optional<PiFieldMatch> optField = criterion.fieldMatch(fieldId);
if (optField.isEmpty()) {
return null;
}
PiLpmFieldMatch field = (PiLpmFieldMatch) optField.get();
Ip4Address address = Ip4Address.valueOf(field.value().asArray());
return Ip4Prefix.valueOf(address, field.prefixLength());
}
use of org.onlab.packet.Ip4Address in project fabric-tna by stratum.
the class FabricIntProgrammable method buildReportEntryWithType.
private FlowRule buildReportEntryWithType(SegmentRoutingDeviceConfig srCfg, IntReportConfig intCfg, short bridgedMdType, short reportType, short mirrorType) {
final Ip4Address srcIp = srCfg.routerIpv4();
final int switchId = srCfg.nodeSidIPv4();
if (srcIp == null) {
log.warn("Invalid switch IP, skip configuring the report table");
return null;
}
final PiActionParam srcIpParam = new PiActionParam(P4InfoConstants.SRC_IP, srcIp.toOctets());
final PiActionParam monIpParam = new PiActionParam(P4InfoConstants.MON_IP, intCfg.collectorIp().toOctets());
final PiActionParam monPortParam = new PiActionParam(P4InfoConstants.MON_PORT, intCfg.collectorPort().toInt());
final PiActionParam switchIdParam = new PiActionParam(P4InfoConstants.SWITCH_ID, switchId);
PiAction.Builder reportActionBuilder = PiAction.builder();
if (!srCfg.isEdgeRouter()) {
// If the device is a spine device, we need to find which
// switch is the INT collector attached to and find the SID of that device.
// TODO: replace this with SR API.
Optional<Integer> sid = getSidForCollector(intCfg.collectorIp());
if (sid.isEmpty()) {
// Error log will be shown in getSidForCollector method.
return null;
}
if ((reportType & (INT_REPORT_TYPE_FLOW | INT_REPORT_TYPE_QUEUE)) != 0) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_LOCAL_REPORT_ENCAP_MPLS);
} else if (reportType == INT_REPORT_TYPE_DROP) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_DROP_REPORT_ENCAP_MPLS);
} else {
// Invalid report type
log.warn("Invalid report type {}", reportType);
return null;
}
final PiActionParam monLabelParam = new PiActionParam(P4InfoConstants.MON_LABEL, sid.get());
reportActionBuilder.withParameter(monLabelParam);
} else {
if ((reportType & (INT_REPORT_TYPE_FLOW | INT_REPORT_TYPE_QUEUE)) != 0) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_LOCAL_REPORT_ENCAP);
} else if (reportType == INT_REPORT_TYPE_DROP) {
reportActionBuilder.withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_DO_DROP_REPORT_ENCAP);
} else {
// Invalid report type
log.warn("Invalid report type {}", reportType);
return null;
}
}
reportActionBuilder.withParameter(srcIpParam).withParameter(monIpParam).withParameter(monPortParam).withParameter(switchIdParam);
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(reportActionBuilder.build()).build();
final TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(P4InfoConstants.HDR_BMD_TYPE, bridgedMdType).matchExact(P4InfoConstants.HDR_MIRROR_TYPE, mirrorType).matchExact(P4InfoConstants.HDR_INT_REPORT_TYPE, reportType).build()).build();
return DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(this.data().deviceId()).forTable(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_REPORT).build();
}
Aggregations