use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class SdnIpFib method withdraw.
private void withdraw(ResolvedRoute route) {
synchronized (this) {
IpPrefix prefix = route.prefix();
MultiPointToSinglePointIntent intent = routeIntents.remove(prefix);
if (intent == null) {
log.trace("No intent in routeIntents to delete for prefix: {}", prefix);
return;
}
intentSynchronizer.withdraw(intent);
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class SdnIpFib method addInterface.
private void addInterface(Interface intf) {
synchronized (this) {
for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
// Retrieve the IP prefix and affected intent
IpPrefix prefix = entry.getKey();
MultiPointToSinglePointIntent intent = entry.getValue();
// Add new ingress FilteredConnectPoint
Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(intent.filteredIngressPoints());
// Create the new traffic selector
TrafficSelector.Builder selector = buildIngressTrafficSelector(intf, prefix);
// Create the Filtered ConnectPoint and add it to the existing set
FilteredConnectPoint newIngressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), selector.build());
ingressFilteredCPs.add(newIngressFilteredCP);
// Create new intent
MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder(intent).filteredIngressPoints(ingressFilteredCPs).build();
routeIntents.put(entry.getKey(), newIntent);
intentSynchronizer.submit(newIntent);
}
}
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class SimpleFabricRouting method generateLocalSubnetIpBctFlowRule.
private FlowRule generateLocalSubnetIpBctFlowRule(DeviceId deviceId, IpPrefix prefix, FabricNetwork fabricNetwork) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
IpPrefix bctPrefix;
if (prefix.isIp4()) {
bctPrefix = Ip4Prefix.valueOf(prefix.getIp4Prefix().address().toInt() | ~Ip4Address.makeMaskPrefix(prefix.prefixLength()).toInt(), Ip4Address.BIT_LENGTH);
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(bctPrefix);
} else {
byte[] p = prefix.getIp6Prefix().address().toOctets();
byte[] m = Ip6Address.makeMaskPrefix(prefix.prefixLength()).toOctets();
for (int i = 0; i < p.length; i++) {
p[i] |= ~m[i];
}
bctPrefix = Ip6Prefix.valueOf(p, Ip6Address.BIT_LENGTH);
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(bctPrefix);
}
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
Set<ConnectPoint> newEgressPoints = new HashSet<>();
for (Interface iface : fabricNetwork.interfaces()) {
if (iface.connectPoint().deviceId().equals(deviceId)) {
treatment.setOutput(iface.connectPoint().port());
}
}
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withPriority(reactivePriority(true, true, bctPrefix.prefixLength())).withSelector(selector.build()).withTreatment(treatment.build()).fromApp(appId).makePermanent().forTable(0).build();
return rule;
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class SimpleFabricRouting method ipPacketReactiveProcessor.
/**
* Routes packet reactively.
*/
private void ipPacketReactiveProcessor(PacketContext context, Ethernet ethPkt, ConnectPoint srcCp, IpAddress srcIp, IpAddress dstIp, byte ipProto) {
/* check reactive handling and forward packet */
log.trace("ip packet: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
EncapsulationType encap = EncapsulationType.NONE;
// prefix and nextHop for local Subnet
IpPrefix srcPrefix = srcIp.toIpPrefix();
IpPrefix dstPrefix = dstIp.toIpPrefix();
IpAddress srcNextHop = srcIp;
IpAddress dstNextHop = dstIp;
MacAddress treatmentSrcMac = ethPkt.getDestinationMAC();
int borderRoutePrefixLength = 0;
boolean updateMac = simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC());
// check subnet local or route
FabricSubnet srcSubnet = simpleFabric.fabricSubnet(srcIp);
if (srcSubnet == null) {
FabricRoute route = simpleFabric.fabricRoute(srcIp);
if (route == null) {
log.warn("unknown srcIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
return;
}
srcPrefix = route.prefix();
srcNextHop = route.nextHop();
borderRoutePrefixLength = route.prefix().prefixLength();
}
FabricSubnet dstSubnet = simpleFabric.fabricSubnet(dstIp);
if (dstSubnet == null) {
FabricRoute route = simpleFabric.fabricRoute(dstIp);
if (route == null) {
log.warn("unknown dstIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
return;
}
dstPrefix = route.prefix();
dstNextHop = route.nextHop();
borderRoutePrefixLength = route.prefix().prefixLength();
}
if (dstSubnet != null) {
// destination is local subnet ip
if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
// NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
treatmentSrcMac = ethPkt.getSourceMAC();
if (fabricNetwork != null && fabricNetwork.isForward()) {
// NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
// update mac only if dstMac is virtualGatewayMac, else assume valid mac already for the l2 network
log.info("LOCAL FORWARD ONLY: " + "srcCp={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
forwardPacketToDstIp(context, dstIp, treatmentSrcMac, updateMac);
return;
}
}
encap = dstSubnet.encapsulation();
if (encap == EncapsulationType.NONE && srcSubnet != null) {
encap = srcSubnet.encapsulation();
}
} else {
// destination is external network
if (srcSubnet == null) {
// both are externel network
log.warn("INVALID PACKET: srcIp and dstIp are both NON-LOCAL: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
return;
}
encap = srcSubnet.encapsulation();
}
log.info("REGI AND FORWARD: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
setUpConnectivity(srcCp, ipProto, srcPrefix, dstPrefix, dstNextHop, treatmentSrcMac, encap, updateMac, dstSubnet != null, borderRoutePrefixLength);
forwardPacketToDstIp(context, dstNextHop, treatmentSrcMac, updateMac);
}
use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.
the class VbngConfigurationManager method getAvailablePublicIpAddress.
// TODO handle the case: the number of public IP addresses is not enough
// for 1:1 mapping from public IP to private IP.
@Override
public synchronized IpAddress getAvailablePublicIpAddress(IpAddress privateIpAddress) {
// If there is already a mapping entry for the private IP address,
// then fetch the public IP address in the mapping entry and return it.
IpAddress publicIpAddress = ipAddressMap.get(privateIpAddress);
if (publicIpAddress != null) {
return publicIpAddress;
}
// There is no mapping for the private IP address.
Iterator<Entry<IpPrefix, Boolean>> prefixes = localPublicIpPrefixes.entrySet().iterator();
while (prefixes.hasNext()) {
Entry<IpPrefix, Boolean> prefix = prefixes.next();
if (!prefix.getValue()) {
continue;
}
if (prefix.getKey().prefixLength() == 32) {
updateIpPrefixStatus(prefix.getKey(), false);
publicIpAddress = prefix.getKey().address();
ipAddressMap.put(privateIpAddress, publicIpAddress);
return publicIpAddress;
}
double prefixLen = prefix.getKey().prefixLength();
int availableIpNum = (int) Math.pow(2, IpPrefix.MAX_INET_MASK_LENGTH - prefixLen) - 1;
for (int i = 1; i <= availableIpNum; i++) {
publicIpAddress = increaseIpAddress(prefix.getKey().address(), i);
if (publicIpAddress == null) {
return null;
}
if (ipAddressMap.values().contains(publicIpAddress)) {
continue;
} else if (i == availableIpNum) {
// All the IP addresses are assigned out
// Update this IP prefix status to false
// Note: in this version we do not consider the
// IP recycling issue.
updateIpPrefixStatus(prefix.getKey(), false);
ipAddressMap.put(privateIpAddress, publicIpAddress);
return publicIpAddress;
} else {
ipAddressMap.put(privateIpAddress, publicIpAddress);
return publicIpAddress;
}
}
}
return null;
}
Aggregations