use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class HostHandler method processIntfVlanUpdatedEvent.
/**
* Update forwarding objective for unicast bridging and unicast routing.
* Also check the validity of updated interface configuration on VLAN.
*
* @param deviceId device ID that host attaches to
* @param portNum port number that host attaches to
* @param vlanId Vlan ID configured on the switch port
* @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise
* @param install true to populate the objective, false to revoke
*/
// TODO Current implementation does not handle dual-homed hosts with auxiliary locations.
void processIntfVlanUpdatedEvent(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan, boolean install) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNum);
Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
if (hosts == null || hosts.size() == 0) {
log.debug("processIntfVlanUpdatedEvent: No hosts connected to {}", connectPoint);
return;
}
List<CompletableFuture<Void>> hostFutures = Lists.newArrayList();
hosts.forEach(host -> hostFutures.add(hostWorkers.submit(() -> processIntfVlanUpdatedEventInternal(host, deviceId, portNum, vlanId, popVlan, install), host.id().hashCode())));
// Let's wait for the completion of all hosts
try {
CompletableFuture.allOf(hostFutures.toArray(new CompletableFuture[0])).thenApply(objectives -> hostFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
} catch (InterruptedException | ExecutionException e) {
log.warn("Exception caught when executing processIntfVlanUpdatedEvent futures");
hostFutures.forEach(future -> future.cancel(false));
}
}
use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method anyDoubleTaggedHost.
/**
* Checks if there is any double tagged host attached to given location.
* This method will match on the effective location of a host.
* That is, it will match on auxLocations when auxLocations is not null. Otherwise, it will match on locations.
*
* @param deviceId device ID
* @param portNum port number
* @return true if there is any host attached to given location.
*/
private boolean anyDoubleTaggedHost(DeviceId deviceId, PortNumber portNum) {
ConnectPoint cp = new ConnectPoint(deviceId, portNum);
Set<Host> connectedHosts = srManager.hostService.getConnectedHosts(cp, false);
Set<Host> auxConnectedHosts = srManager.hostService.getConnectedHosts(cp, true);
return !auxConnectedHosts.isEmpty() || connectedHosts.stream().anyMatch(host -> host.auxLocations() == null);
}
use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method modified.
@Modified
private void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
if (properties == null) {
return;
}
String strActiveProbing = Tools.get(properties, PROP_ACTIVE_PROBING);
boolean expectActiveProbing = Boolean.parseBoolean(strActiveProbing);
if (expectActiveProbing != activeProbing) {
activeProbing = expectActiveProbing;
log.info("{} active probing", activeProbing ? "Enabling" : "Disabling");
}
String strSymmetricProbing = Tools.get(properties, PROP_SYMMETRIC_PROBING);
boolean expectSymmetricProbing = Boolean.parseBoolean(strSymmetricProbing);
if (expectSymmetricProbing != symmetricProbing) {
symmetricProbing = expectSymmetricProbing;
log.info("{} symmetric probing", symmetricProbing ? "Enabling" : "Disabling");
}
String strSingleHomedDown = Tools.get(properties, PROP_SINGLE_HOMED_DOWN);
boolean expectSingleHomedDown = Boolean.parseBoolean(strSingleHomedDown);
if (expectSingleHomedDown != singleHomedDown) {
singleHomedDown = expectSingleHomedDown;
log.info("{} downing of single homed hosts for lost uplinks", singleHomedDown ? "Enabling" : "Disabling");
if (singleHomedDown && linkHandler != null) {
hostService.getHosts().forEach(host -> host.locations().forEach(loc -> {
if (interfaceService.isConfigured(loc)) {
linkHandler.checkUplinksForHost(loc);
}
}));
} else {
log.warn("Disabling singleHomedDown does not re-enable already " + "downed ports for single-homed hosts");
}
}
String strRespondToUnknownHosts = Tools.get(properties, PROP_RESPOND_TO_UNKNOWN_HOSTS);
boolean expectRespondToUnknownHosts = Boolean.parseBoolean(strRespondToUnknownHosts);
if (expectRespondToUnknownHosts != respondToUnknownHosts) {
respondToUnknownHosts = expectRespondToUnknownHosts;
log.info("{} responding to ARPs/NDPs from unknown hosts", respondToUnknownHosts ? "Enabling" : "Disabling");
}
String strRouteDoubleTaggedHosts = Tools.get(properties, PROP_ROUTE_DOUBLE_TAGGED_HOSTS);
boolean expectRouteDoubleTaggedHosts = Boolean.parseBoolean(strRouteDoubleTaggedHosts);
if (expectRouteDoubleTaggedHosts != routeDoubleTaggedHosts) {
routeDoubleTaggedHosts = expectRouteDoubleTaggedHosts;
log.info("{} routing for double tagged hosts", routeDoubleTaggedHosts ? "Enabling" : "Disabling");
if (routeDoubleTaggedHosts) {
hostHandler.populateAllDoubleTaggedHost();
} else {
hostHandler.revokeAllDoubleTaggedHost();
}
}
String strDefaultInternalVlan = Tools.get(properties, PROP_DEFAULT_INTERNAL_VLAN);
int defIntVlan = Integer.parseInt(strDefaultInternalVlan);
if (defIntVlan != defaultInternalVlan) {
if (canUseVlanId(defIntVlan)) {
log.warn("Default internal vlan value changed from {} to {}.. " + "re-programming filtering rules, but NOT any groups already " + "created with the former value", defaultInternalVlan, defIntVlan);
VlanId oldDefIntVlan = VlanId.vlanId((short) defaultInternalVlan);
defaultInternalVlan = defIntVlan;
routingRulePopulator.updateSpecialVlanFilteringRules(true, oldDefIntVlan, VlanId.vlanId((short) defIntVlan));
} else {
log.warn("Cannot change default internal vlan to unusable " + "value {}", defIntVlan);
}
}
String strPwTxpVlan = Tools.get(properties, PROP_PW_TRANSPORT_VLAN);
int pwTxpVlan = Integer.parseInt(strPwTxpVlan);
if (pwTxpVlan != pwTransportVlan) {
if (canUseVlanId(pwTxpVlan)) {
log.warn("Pseudowire transport vlan value changed from {} to {}.. " + "re-programming filtering rules, but NOT any groups already " + "created with the former value", pwTransportVlan, pwTxpVlan);
VlanId oldPwTxpVlan = VlanId.vlanId((short) pwTransportVlan);
pwTransportVlan = pwTxpVlan;
routingRulePopulator.updateSpecialVlanFilteringRules(false, oldPwTxpVlan, VlanId.vlanId((short) pwTxpVlan));
} else {
log.warn("Cannot change pseudowire transport vlan to unusable " + "value {}", pwTxpVlan);
}
}
String strRouteSimplification = Tools.get(properties, PROP_ROUTE_SIMPLIFICATION);
boolean expectRouteSimplification = Boolean.parseBoolean(strRouteSimplification);
if (expectRouteSimplification != routeSimplification) {
routeSimplification = expectRouteSimplification;
log.info("{} route simplification", routeSimplification ? "Enabling" : "Disabling");
}
}
use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class SegmentRoutingManager method removeSubnetConfig.
private void removeSubnetConfig(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
// Remove routing rules for removed subnet from previous configuration,
// 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> subnetsToBeRevoked = ipPrefixSet.stream().filter(ipPrefix -> !deviceIpPrefixSet.contains(ipPrefix)).collect(Collectors.toSet());
// Check if any of the subnets to be revoked is configured in the pairDevice.
// If any, repopulate the subnet with pairDevice connectPoint instead of revoking.
Optional<DeviceId> pairDevice = getPairDeviceId(cp.deviceId());
if (pairDevice.isPresent()) {
Set<IpPrefix> pairDeviceIpPrefix = getDeviceSubnetMap().get(pairDevice.get());
Set<IpPrefix> subnetsExistingInPairDevice = subnetsToBeRevoked.stream().filter(ipPrefix -> pairDeviceIpPrefix.contains(ipPrefix)).collect(Collectors.toSet());
// Update the subnets existing in pair device with pair device connect point.
if (!subnetsExistingInPairDevice.isEmpty()) {
// PortNumber of connect point is not relevant in populate subnet and hence providing as ANY.
ConnectPoint pairDeviceCp = new ConnectPoint(pairDevice.get(), PortNumber.ANY);
log.debug("Updating the subnets: {} with pairDevice connectPoint as it exists in the Pair device: {}", subnetsExistingInPairDevice, pairDeviceCp);
defaultRoutingHandler.populateSubnet(Collections.singleton(pairDeviceCp), subnetsExistingInPairDevice);
}
// Remove only the subnets that are not configured in the pairDevice.
subnetsToBeRevoked = Sets.difference(subnetsToBeRevoked, subnetsExistingInPairDevice);
}
if (!subnetsToBeRevoked.isEmpty()) {
log.debug("Removing subnets for connectPoint: {}, subnets: {}", cp, subnetsToBeRevoked);
defaultRoutingHandler.revokeSubnet(subnetsToBeRevoked, cp.deviceId());
}
// 2. Interface IP punts
// Remove IP punts for old 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.revokeSingleIpPunts(cp.deviceId(), interfaceIpAddress));
// 3. Host unicast routing rule
// Remove unicast routing rule
hostEventExecutor.execute(() -> hostHandler.processIntfIpUpdatedEvent(cp, ipPrefixSet, false));
}
use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class SegmentRoutingNeighbourHandler method sendResponse.
/**
* Utility to send a ND reply using the supplied information.
*
* @param pkt the request
* @param targetMac the target mac
* @param hostService the host service
* @param isRouter true if this reply is sent on behalf of a router
*/
protected void sendResponse(NeighbourMessageContext pkt, MacAddress targetMac, HostService hostService, boolean isRouter) {
// if this is false, check if host exists in the store
if (!respondToUnknownHosts()) {
short vlanId = pkt.packet().getQinQVID();
HostId dstId = HostId.hostId(pkt.srcMac(), vlanId == Ethernet.VLAN_UNTAGGED ? pkt.vlan() : VlanId.vlanId(vlanId));
Host dst = hostService.getHost(dstId);
if (dst == null) {
log.warn("Cannot send {} response to host {} - does not exist in the store", pkt.protocol(), dstId);
return;
}
}
pkt.setIsRouter(isRouter);
pkt.reply(targetMac);
}
Aggregations