use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method processDhcp6PacketFromClient.
/**
* build the DHCP6 solicit/request packet with gatewayip.
*
* @param context packet context
* @param clientPacket client ethernet packet
* @param clientInterfaces set of client side interfaces
*/
private List<InternalPacket> processDhcp6PacketFromClient(PacketContext context, Ethernet clientPacket, Set<Interface> clientInterfaces) {
ConnectPoint receivedFrom = context.inPacket().receivedFrom();
Ip6Address relayAgentIp = Dhcp6HandlerUtil.getRelayAgentIPv6Address(clientInterfaces);
MacAddress relayAgentMac = clientInterfaces.iterator().next().mac();
if (relayAgentIp == null || relayAgentMac == null) {
log.warn("Missing DHCP relay agent interface Ipv6 addr config for " + "packet from client on port: {}. Aborting packet processing", clientInterfaces.iterator().next().connectPoint());
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
return Lists.newArrayList();
}
IPv6 clientIpv6 = (IPv6) clientPacket.getPayload();
UDP clientUdp = (UDP) clientIpv6.getPayload();
DHCP6 clientDhcp6 = (DHCP6) clientUdp.getPayload();
boolean directConnFlag = Dhcp6HandlerUtil.directlyConnected(clientDhcp6);
ConnectPoint clientConnectionPoint = context.inPacket().receivedFrom();
VlanId vlanIdInUse = VlanId.vlanId(clientPacket.getVlanID());
Interface clientInterface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface -> Dhcp6HandlerUtil.interfaceContainsVlan(iface, vlanIdInUse)).findFirst().orElse(null);
List<InternalPacket> internalPackets = new ArrayList<>();
List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
List<DhcpServerInfo> copyServerInfoList = new ArrayList<DhcpServerInfo>(serverInfoList);
for (DhcpServerInfo serverInfo : copyServerInfoList) {
if (!Dhcp6HandlerUtil.checkDhcpServerConnPt(directConnFlag, serverInfo)) {
log.warn("Can't get server connect point, ignore");
continue;
}
DhcpServerInfo newServerInfo = getHostInfoForServerInfo(serverInfo, serverInfoList);
if (newServerInfo == null) {
log.warn("Can't get server interface with host info resolved, ignore");
continue;
}
Interface serverInterface = getServerInterface(newServerInfo);
if (serverInterface == null) {
log.warn("Can't get server interface, ignore");
continue;
}
Ethernet etherReply = Dhcp6HandlerUtil.buildDhcp6PacketFromClient(context, clientPacket, clientInterfaces, newServerInfo, serverInterface);
removeHostOrRoute(directConnFlag, clientConnectionPoint, clientDhcp6, clientPacket, clientIpv6, clientInterface);
InternalPacket internalPacket = InternalPacket.internalPacket(etherReply, serverInfo.getDhcpServerConnectPoint().get());
internalPackets.add(internalPacket);
}
log.debug("num of client packets to send is{}", internalPackets.size());
return internalPackets;
}
use of org.onosproject.net.intf.Interface in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method processSinglePortFiltersInternal.
private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum, boolean pushVlan, VlanId vlanId, boolean install, boolean update) {
boolean doTMAC = true;
if (!pushVlan) {
// Skip the tagged vlans belonging to an interface without an IP address
Set<Interface> ifaces = srManager.interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, portnum)).stream().filter(intf -> intf.vlanTagged().contains(vlanId) && intf.ipAddressesList().isEmpty()).collect(Collectors.toSet());
if (!ifaces.isEmpty()) {
log.debug("processSinglePortFiltersInternal: skipping TMAC for vlan {} at {}/{} - no IP", vlanId, deviceId, portnum);
doTMAC = false;
}
}
FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId, doTMAC, update);
if (fob == null) {
// error encountered during build
return false;
}
log.debug("{} filtering objectives for dev/port: {}/{}", install ? "Installing" : "Removing", deviceId, portnum);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Filter for {}/{} {}", deviceId, portnum, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}", install ? "install" : "remove", deviceId, portnum, error));
if (install) {
srManager.flowObjectiveService.filter(deviceId, fob.add(context));
} else {
srManager.flowObjectiveService.filter(deviceId, fob.remove(context));
}
return true;
}
use of org.onosproject.net.intf.Interface in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method addSubnetConfig.
private void addSubnetConfig(ConnectPoint cp, Set<InterfaceIpAddress> ipAddressSet) {
Set<IpPrefix> ipPrefixSet = ipAddressSet.stream().map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
Set<InterfaceIpAddress> deviceIntfIpAddrs = interfaceService.getInterfaces().stream().filter(intf -> intf.connectPoint().deviceId().equals(cp.deviceId())).filter(intf -> !intf.connectPoint().equals(cp)).flatMap(intf -> intf.ipAddressesList().stream()).collect(Collectors.toSet());
// 1. Partial subnet population
// Add routing rules for newly added subnet, which does not also exist in
// other interfaces in the same device
Set<IpPrefix> deviceIpPrefixSet = deviceIntfIpAddrs.stream().map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
Set<IpPrefix> subnetsToBePopulated = ipPrefixSet.stream().filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)).collect(Collectors.toSet());
if (!subnetsToBePopulated.isEmpty()) {
log.debug("Adding subnets for connectPoint: {}, subnets: {}", cp, subnetsToBePopulated);
// check if pair-device has the same subnet configured
Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId());
if (pairDevice.isPresent()) {
Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get());
Set<IpPrefix> subnetsToBePopulatedAsDualHomed = subnetsToBePopulated.stream().filter(pairDeviceIpPrefix::contains).collect(Collectors.toSet());
Set<IpPrefix> subnetsToBePopulatedAsSingleHomed = Sets.difference(subnetsToBePopulated, subnetsToBePopulatedAsDualHomed);
if (!subnetsToBePopulatedAsSingleHomed.isEmpty()) {
defaultRoutingHandler.populateSubnet(Collections.singleton(cp), subnetsToBePopulatedAsSingleHomed);
}
if (!subnetsToBePopulatedAsDualHomed.isEmpty()) {
Set<ConnectPoint> cpts = new HashSet<>();
cpts.add(cp);
// As Subnets is DualHomed adding the pairDevice also as ConnectPoint.
// PortNumber of connect point is not relevant in populate subnet and hence providing as ANY.
ConnectPoint pairCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY);
cpts.add(pairCp);
log.debug("Adding DualHomed subnets for connectPoint: {} and its pair device: {}, subnets: {}", cp, pairCp, subnetsToBePopulatedAsDualHomed);
// populating the subnets as DualHomed
defaultRoutingHandler.populateSubnet(cpts, subnetsToBePopulated);
// revoking the subnets populated in the device as it is now Dualhomed.
defaultRoutingHandler.revokeSubnet(Collections.singleton(cp.deviceId()), subnetsToBePopulatedAsDualHomed);
}
} else {
defaultRoutingHandler.populateSubnet(Collections.singleton(cp), subnetsToBePopulated);
}
}
// 2. Interface IP punts
// Add IP punts for new Intf address
Set<IpAddress> deviceIpAddrs = deviceIntfIpAddrs.stream().map(InterfaceIpAddress::ipAddress).collect(Collectors.toSet());
ipAddressSet.stream().map(InterfaceIpAddress::ipAddress).filter(interfaceIpAddress -> !deviceIpAddrs.contains(interfaceIpAddress)).forEach(interfaceIpAddress -> routingRulePopulator.populateSingleIpPunts(cp.deviceId(), interfaceIpAddress));
// 3. Host unicast routing rule
// Add unicast routing rule
hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, true));
}
use of org.onosproject.net.intf.Interface in project trellis-control by opennetworkinglab.
the class DeviceConfiguration method getRouterIpAddressForASubnetHost.
/**
* Returns the router ipv6 address of segment router that has the
* specified ip address in its subnets.
*
* @param destIpAddress target ip address
* @return router ip address
*/
public Ip6Address getRouterIpAddressForASubnetHost(Ip6Address destIpAddress) {
Interface matchIntf = srManager.interfaceService.getMatchingInterface(destIpAddress);
if (matchIntf == null) {
log.debug("No router was found for {}", destIpAddress);
return null;
}
DeviceId routerDeviceId = matchIntf.connectPoint().deviceId();
SegmentRouterInfo srInfo = deviceConfigMap.get(routerDeviceId);
if (srInfo == null) {
log.debug("No device config was found for {}", routerDeviceId);
return null;
}
return srInfo.ipv6Loopback;
}
use of org.onosproject.net.intf.Interface in project trellis-control by opennetworkinglab.
the class DeviceConfiguration method getRouterIpAddressForASubnetHost.
/**
* Returns the router ip address of segment router that has the
* specified ip address in its subnets.
*
* @param destIpAddress target ip address
* @return router ip address
*/
public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) {
Interface matchIntf = srManager.interfaceService.getMatchingInterface(destIpAddress);
if (matchIntf == null) {
log.debug("No router was found for {}", destIpAddress);
return null;
}
DeviceId routerDeviceId = matchIntf.connectPoint().deviceId();
SegmentRouterInfo srInfo = deviceConfigMap.get(routerDeviceId);
if (srInfo == null) {
log.debug("No device config was found for {}", routerDeviceId);
return null;
}
return srInfo.ipv4Loopback;
}
Aggregations