use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testLpmToTernaryTranslation.
@Test
public void testLpmToTernaryTranslation() throws Exception {
IpPrefix ipPrefix = IpPrefix.valueOf("10.0.0.1/23");
int bitWidth = ipPrefix.address().toOctets().length * Byte.SIZE;
IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(ipPrefix);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(criterion, fieldId, TERNARY, bitWidth);
ImmutableByteSequence expectedMask = ImmutableByteSequence.prefixOnes(Integer.BYTES, 23);
ImmutableByteSequence expectedValue = ImmutableByteSequence.copyFrom(ipPrefix.address().toOctets());
assertThat(ternaryMatch.mask(), is(expectedMask));
assertThat(ternaryMatch.value(), is(expectedValue));
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class SoftRouterPipeline method processSpecific.
/**
* SoftRouter has a single specific table - the FIB Table. It emulates
* LPM matching of dstIP by using higher priority flows for longer prefixes.
* Flows are forwarded using flow-actions
*
* @param fwd The forwarding objective of type simple
* @return A collection of flow rules meant to be delivered to the flowrule
* subsystem. Typically the returned collection has a single flowrule.
* May return empty collection in case of failures.
*/
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
log.debug("Processing specific forwarding objective to next:{}", fwd.nextId());
TrafficSelector selector = fwd.selector();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
// XXX currently supporting only the L3 unicast table
if (ethType == null || (ethType.ethType().toShort() != TYPE_IPV4 && ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
fail(fwd, ObjectiveError.UNSUPPORTED);
return Collections.emptySet();
}
// We build the selector according the eth type.
IpPrefix ipPrefix;
TrafficSelector.Builder filteredSelector;
if (ethType.ethType().toShort() == TYPE_IPV4) {
ipPrefix = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
filteredSelector = DefaultTrafficSelector.builder().matchEthType(TYPE_IPV4);
} else {
ipPrefix = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip();
filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV6);
}
// If the prefix is different from the default via.
if (ipPrefix.prefixLength() != 0) {
if (ethType.ethType().toShort() == TYPE_IPV4) {
filteredSelector.matchIPDst(ipPrefix);
} else {
filteredSelector.matchIPv6Dst(ipPrefix);
}
}
TrafficTreatment tt = null;
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
if (next == null) {
log.error("next-id {} does not exist in store", fwd.nextId());
return Collections.emptySet();
}
tt = appKryo.deserialize(next.data());
if (tt == null) {
log.error("Error in deserializing next-id {}", fwd.nextId());
return Collections.emptySet();
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector.build());
if (tt != null) {
ruleBuilder.withTreatment(tt);
}
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
ruleBuilder.forTable(FIB_TABLE);
return Collections.singletonList(ruleBuilder.build());
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class Ofdpa2GroupHandler method processBroadcastNextObjective.
/**
* As per the OFDPA 2.0 TTP, packets are sent out of ports by using
* a chain of groups. The broadcast Next Objective passed in by the application
* has to be broken up into a group chain comprising of an
* L2 Flood group or L3 Multicast group, whose buckets point to L2 Interface groups.
*
* @param nextObj the nextObjective of type BROADCAST
*/
private void processBroadcastNextObjective(NextObjective nextObj) {
VlanId assignedVlan = readVlanFromSelector(nextObj.meta());
if (assignedVlan == null) {
log.warn("VLAN ID required by broadcast next obj is missing. Abort.");
fail(nextObj, ObjectiveError.BADPARAMS);
return;
}
// Handling L2 multicast cases.
MacAddress dstMac = readEthDstFromSelector(nextObj.meta());
if (dstMac != null && dstMac.isMulticast()) {
processL2MulticastNextObjective(nextObj);
return;
}
// FIXME Improve the logic
// If L2 load balancer is not involved, use L2IG. Otherwise, use L2UG.
// The purpose is to make sure existing XConnect logic can still work on a configured port.
List<GroupInfo> groupInfos;
if (nextObj.nextTreatments().stream().allMatch(n -> n.type() == NextTreatment.Type.TREATMENT)) {
groupInfos = prepareL2InterfaceGroup(nextObj, assignedVlan);
log.debug("prepareL2InterfaceGroup");
} else {
groupInfos = prepareL2UnfilteredGroup(nextObj);
log.debug("prepareL2UnfilteredGroup");
}
if (groupInfos == null || groupInfos.isEmpty()) {
log.warn("No buckets for Broadcast NextObj {}", nextObj);
fail(nextObj, ObjectiveError.GROUPMISSING);
return;
}
IpPrefix ipDst = readIpDstFromSelector(nextObj.meta());
if (ipDst != null) {
if (ipDst.isMulticast()) {
createL3MulticastGroup(nextObj, assignedVlan, groupInfos);
} else {
log.warn("Broadcast NextObj with non-multicast IP address {}", nextObj);
fail(nextObj, ObjectiveError.BADPARAMS);
}
} else {
createL2FloodGroup(nextObj, assignedVlan, groupInfos);
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processDoubleTaggedFwd.
/**
* Handles forwarding rules to the IP Unicast Routing.
*
* @param fwd the forwarding objective
* @return A collection of flow rules, or an empty set
*/
protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) {
// inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE
TrafficSelector selector = fwd.selector();
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
sBuilder.matchEthType(Ethernet.TYPE_IPV4);
sBuilder.matchVlanId(VlanId.ANY);
IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) {
sBuilder.matchIPDst(ipv4Dst);
if (fwd.nextId() != null) {
NextGroup next = getGroupForNextObjective(fwd.nextId());
if (next != null) {
List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
// we only need the top level group's key to point the flow to it
Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
if (group == null) {
log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id()));
// ACTSET_OUTPUT in OVS will match output action in write_action() set.
outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id()));
outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
innerTtb.deferred().group(group.id());
innerTtb.transition(ACL_TABLE);
FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(innerTtb.build()).forTable(UNICAST_ROUTING_TABLE_1);
if (fwd.permanent()) {
innerRuleBuilder.makePermanent();
} else {
innerRuleBuilder.makeTemporary(fwd.timeout());
}
Collection<FlowRule> flowRuleCollection = new HashSet<>();
flowRuleCollection.add(innerRuleBuilder.build());
FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(outerTtb.build()).forTable(UNICAST_ROUTING_TABLE);
if (fwd.permanent()) {
outerRuleBuilder.makePermanent();
} else {
outerRuleBuilder.makeTemporary(fwd.timeout());
}
flowRuleCollection.add(innerRuleBuilder.build());
flowRuleCollection.add(outerRuleBuilder.build());
return flowRuleCollection;
} else {
log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", fwd.nextId(), deviceId, fwd.id());
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
} else {
log.warn("NextId is not specified in fwd:{}", fwd.id());
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
}
}
return Collections.emptySet();
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class BgpUpdateMsgVer4 method parseWithdrawnRoutes.
/**
* Parsing withdrawn routes from channel buffer.
*
* @param cb channelBuffer
* @return list of IP prefix
* @throws BgpParseException while parsing withdrawn routes
*/
public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb) throws BgpParseException {
LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>();
while (cb.readableBytes() > 0) {
int length = cb.readByte();
IpPrefix ipPrefix;
if (length == 0) {
byte[] prefix = new byte[] { 0 };
ipPrefix = Validation.bytesToPrefix(prefix, length);
withDrwRoutes.add(ipPrefix);
} else {
int len = length / BYTE_IN_BITS;
int reminder = length % BYTE_IN_BITS;
if (reminder > 0) {
len = len + 1;
}
if (cb.readableBytes() < len) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, cb.readableBytes());
}
byte[] prefix = new byte[len];
cb.readBytes(prefix, 0, len);
ipPrefix = Validation.bytesToPrefix(prefix, length);
withDrwRoutes.add(ipPrefix);
}
}
return withDrwRoutes;
}
Aggregations