use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest31.
/**
* This test case checks update message with MPUnreach.
*/
@Test
public void bgpUpdateMessageTest31() 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, // withdrawn routes
(byte) 0xff, // withdrawn routes
(byte) 0xff, // withdrawn routes
0x00, // withdrawn routes
0x5e, // withdrawn routes
0x02, // withdrawn routes
0x00, // withdrawn routes
0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x43, // 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, // mpunreach with safi = 71
(byte) 0x80, // mpunreach with safi = 71
0x0f, // mpunreach with safi = 71
0x2e, // mpunreach with safi = 71
0x40, // mpunreach with safi = 71
0x04, // mpunreach with safi = 71
0x47, 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, // node nlri
0x58 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
assertThat(other.getHeader().getMarker(), is(MARKER));
assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
assertThat(other.getHeader().getLength(), is((short) 94));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
BgpValueType testPathAttribute;
Origin origin;
AsPath asPath;
Med med;
MpUnReachNlri mpUnReach;
List<BgpValueType> pathAttributes = new LinkedList<>();
BgpPathAttributes actualpathAttribute = other.bgpPathAttributes();
pathAttributes = actualpathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributes.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();
mpUnReach = (MpUnReachNlri) testPathAttribute;
assertThat(mpUnReach.mpUnReachNlriLen(), is((int) 46));
assertThat(mpUnReach.getType(), is((short) 15));
List<BgpLSNlri> testMpUnReachNlri = new LinkedList<>();
testMpUnReachNlri = mpUnReach.mpUnReachNlri();
ListIterator<BgpLSNlri> list1 = testMpUnReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE;
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));
BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri;
BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors();
List<BgpValueType> testSubTlvs = new LinkedList<>();
NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors();
testSubTlvs = localNodeDescriptors.getSubTlvs();
ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator();
AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next();
assertThat(testAutonomousSystemTlv.getAsNum(), is(2222));
assertThat(testAutonomousSystemTlv.getType(), is((short) 512));
BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next();
assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018));
assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513));
IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next();
byte[] expIsoNodeId = new byte[] { 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58 };
assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId));
assertThat(testIsIsNonPseudonode.getType(), is((short) 515));
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class OpenstackVtapCriterionCodec method decode.
@Override
public OpenstackVtapCriterion decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
OpenstackVtapCriterion.Builder cBuilder = DefaultOpenstackVtapCriterion.builder();
// parse source IP address
IpPrefix srcIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(SRC_IP).asText(), SRC_IP + MISSING_MESSAGE)), 32);
// parse destination IP address
IpPrefix dstIp = IpPrefix.valueOf(IpAddress.valueOf(nullIsIllegal(json.get(DST_IP).asText(), DST_IP + MISSING_MESSAGE)), 32);
cBuilder.srcIpPrefix(srcIp);
cBuilder.dstIpPrefix(dstIp);
// parse IP protocol
String ipProtoStr = json.get(IP_PROTOCOL).asText();
if (ipProtoStr != null) {
cBuilder.ipProtocol(getProtocolTypeFromString(ipProtoStr));
}
// parse source port number
int srcPort = json.get(SRC_PORT).asInt(0);
// parse destination port number
int dstPort = json.get(DST_PORT).asInt(0);
cBuilder.srcTpPort(TpPort.tpPort(srcPort));
cBuilder.dstTpPort(TpPort.tpPort(dstPort));
return cBuilder.build();
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class InterfaceConfigTest method getIp.
private InterfaceIpAddress getIp(int index, int position) {
IpPrefix subnet1 = IpPrefix.valueOf("1.2.0.0/16");
IpAddress ip = IpAddress.valueOf("1.2.3." + Integer.toString(index + ((position - 1) * 10)));
return new InterfaceIpAddress(ip, subnet1);
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class LinkCollectionCompiler method updateBuilder.
/**
* Update the selector builder using a L3 instruction.
*
* @param builder the builder to update
* @param l3instruction the l3 instruction to use
*/
private void updateBuilder(TrafficSelector.Builder builder, L3ModificationInstruction l3instruction) {
// TODO check ethernet proto
switch(l3instruction.subtype()) {
case IPV4_SRC:
case IPV4_DST:
case IPV6_SRC:
case IPV6_DST:
ModIPInstruction ipInstr = (ModIPInstruction) l3instruction;
// TODO check if ip falls in original prefix
IpPrefix prefix = ipInstr.ip().toIpPrefix();
switch(ipInstr.subtype()) {
case IPV4_SRC:
builder.matchIPSrc(prefix);
break;
case IPV4_DST:
builder.matchIPSrc(prefix);
break;
case IPV6_SRC:
builder.matchIPv6Src(prefix);
break;
case IPV6_DST:
builder.matchIPv6Dst(prefix);
break;
default:
throw new IntentCompilationException(UNSUPPORTED_IP_SUBTYPE);
}
break;
case IPV6_FLABEL:
ModIPv6FlowLabelInstruction ipFlowInstr = (ModIPv6FlowLabelInstruction) l3instruction;
builder.matchIPv6FlowLabel(ipFlowInstr.flowLabel());
break;
case DEC_TTL:
// no-op
break;
case TTL_OUT:
// no-op
break;
case TTL_IN:
// no-op
break;
case ARP_SPA:
ModArpIPInstruction srcArpIpInstr = (ModArpIPInstruction) l3instruction;
if (srcArpIpInstr.ip().isIp4()) {
builder.matchArpSpa((Ip4Address) srcArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_SHA:
ModArpEthInstruction srcArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpSha(srcArpEthInstr.mac());
break;
case ARP_TPA:
ModArpIPInstruction dstArpIpInstr = (ModArpIPInstruction) l3instruction;
if (dstArpIpInstr.ip().isIp4()) {
builder.matchArpTpa((Ip4Address) dstArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_THA:
ModArpEthInstruction dstArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpTha(dstArpEthInstr.mac());
break;
case ARP_OP:
ModArpOpInstruction arpOpInstr = (ModArpOpInstruction) l3instruction;
// FIXME is the long to int cast safe?
builder.matchArpOp((int) arpOpInstr.op());
break;
default:
throw new IntentCompilationException(UNSUPPORTED_L3);
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method buildIpv6Selector.
/**
* Helper method to build Ipv6 selector using the selector provided by
* a forwarding objective.
*
* @param builderToUpdate the builder to update
* @param fwd the selector to read
* @return 0 if the update ends correctly. -1 if the matches
* are not yet supported
*/
int buildIpv6Selector(TrafficSelector.Builder builderToUpdate, ForwardingObjective fwd) {
TrafficSelector selector = fwd.selector();
IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
if (ipv6Dst.isMulticast()) {
if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) {
log.warn("Multicast specific forwarding objective can only be /128");
fail(fwd, ObjectiveError.BADPARAMS);
return -1;
}
VlanId assignedVlan = readVlanFromSelector(fwd.meta());
if (assignedVlan == null) {
log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort.");
fail(fwd, ObjectiveError.BADPARAMS);
return -1;
}
if (requireVlanExtensions()) {
OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan);
builderToUpdate.extension(ofdpaMatchVlanVid, deviceId);
} else {
builderToUpdate.matchVlanId(assignedVlan);
}
builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst);
log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
} else {
if (ipv6Dst.prefixLength() != 0) {
builderToUpdate.matchIPv6Dst(ipv6Dst);
}
builderToUpdate.matchEthType(Ethernet.TYPE_IPV6);
log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}" + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
}
return 0;
}
Aggregations