use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class HostHandlerTest method testDualHomedHostAddedOneByOne.
@Test
public void testDualHomedHostAddedOneByOne() {
Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31), Sets.newHashSet(HOST_IP11), false);
Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC31, HOST_LOC41), Sets.newHashSet(HOST_IP11), false);
// Add a dual-homed host with one location
// Expect: the pair link is utilized temporarily before the second location is discovered
hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, host1));
assertEquals(2, ROUTING_TABLE.size());
assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
assertEquals(P9, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
assertEquals(2, BRIDGING_TABLE.size());
assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
assertEquals(P9, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
// Expect probe to be sent out on pair device
assertTrue(mockLocationProbingService.verifyProbe(host1, CP41, ProbeMode.DISCOVER));
// Add the second location of dual-homed host
// Expect: no longer use the pair link
hostHandler.processHostMovedEvent(new HostEvent(HostEvent.Type.HOST_MOVED, host2, host1));
assertEquals(2, ROUTING_TABLE.size());
assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV3, HOST_IP11.toIpPrefix())).portNumber);
assertEquals(P1, ROUTING_TABLE.get(new MockRoutingTableKey(DEV4, HOST_IP11.toIpPrefix())).portNumber);
assertEquals(2, BRIDGING_TABLE.size());
assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV3, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
assertEquals(P1, BRIDGING_TABLE.get(new MockBridgingTableKey(DEV4, HOST_MAC, INTF_VLAN_UNTAGGED)).portNumber);
}
use of org.onosproject.net.Host in project trellis-control by opennetworkinglab.
the class HostHandlerTest method testEffectiveLocations.
@Test
public void testEffectiveLocations() {
Host regularHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_IP11), false);
Host auxHost = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_TAGGED, Sets.newHashSet(HOST_LOC11, HOST_LOC12), Sets.newHashSet(HOST_LOC21, HOST_LOC22), Sets.newHashSet(HOST_IP11), VlanId.NONE, EthType.EtherType.UNKNOWN.ethType(), false, false);
assertEquals(Sets.newHashSet(HOST_LOC11, HOST_LOC12), hostHandler.effectiveLocations(regularHost));
assertEquals(Sets.newHashSet(HOST_LOC21, HOST_LOC22), hostHandler.effectiveLocations(auxHost));
}
use of org.onosproject.net.Host in project TFG by mattinelorza.
the class Ipv6RoutingComponent method setUpHostRules.
/**
* Sets up the given device with the necessary rules to route packets to the
* given host.
*
* @param deviceId deviceId the device ID
* @param host the host
*/
private void setUpHostRules(DeviceId deviceId, Host host) {
// Get all IPv6 addresses associated to this host. In this tutorial we
// use hosts with only 1 IPv6 address.
final Collection<Ip6Address> hostIpv6Addrs = host.ipAddresses().stream().filter(IpAddress::isIp6).map(IpAddress::getIp6Address).collect(Collectors.toSet());
if (hostIpv6Addrs.isEmpty()) {
// Ignore.
log.debug("No IPv6 addresses for host {}, ignore", host.id());
return;
} else {
log.info("Adding routes on {} for host {} [{}]", deviceId, host.id(), hostIpv6Addrs);
}
// Create an ECMP group with only one member, where the group ID is
// derived from the host MAC.
final MacAddress hostMac = host.mac();
int groupId = macToGroupId(hostMac);
final GroupDescription group = createNextHopGroup(groupId, Collections.singleton(hostMac), deviceId);
// Map each host IPV6 address to corresponding /128 prefix and obtain a
// flow rule that points to the group ID. In this tutorial we expect
// only one flow rule per host.
final List<FlowRule> flowRules = hostIpv6Addrs.stream().map(IpAddress::toIpPrefix).filter(IpPrefix::isIp6).map(IpPrefix::getIp6Prefix).map(prefix -> createRoutingRule(deviceId, prefix, groupId)).collect(Collectors.toList());
// Helper function to install flows after groups, since here flows
// points to the group and P4Runtime enforces this dependency during
// write operations.
insertInOrder(group, flowRules);
}
use of org.onosproject.net.Host in project TFG by mattinelorza.
the class Ipv6SimpleRoutingComponent method setUpPath.
private void setUpPath(HostId srcId, HostId dstId) {
Host src = hostService.getHost(srcId);
Host dst = hostService.getHost(dstId);
// Check if hosts are located at the same switch
log.info("Src switch id={} and Dst switch id={}", src.location().deviceId(), dst.location().deviceId());
if (src.location().deviceId().toString().equals(dst.location().deviceId().toString())) {
PortNumber outPort = dst.location().port();
DeviceId devId = dst.location().deviceId();
FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
flowRuleService.applyFlowRules(nextHopRule);
log.info("Hosts in the same switch");
return;
}
// Get all the available paths between two given hosts
// A path is a collection of links
Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), src.location().deviceId(), dst.location().deviceId());
if (paths.isEmpty()) {
// If there are no paths, display a warn and exit
log.warn("No path found");
return;
}
// Pick a path that does not lead back to where we
// came from; if no such path,display a warn and exit
Path path = pickForwardPathIfPossible(paths, src.location().port());
if (path == null) {
log.warn("Don't know where to go from here {} for {} -> {}", src.location(), srcId, dstId);
return;
}
// Install rules in the path
List<Link> pathLinks = path.links();
for (Link l : pathLinks) {
PortNumber outPort = l.src().port();
DeviceId devId = l.src().deviceId();
FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
flowRuleService.applyFlowRules(nextHopRule);
}
// Install rule in the last device (where dst is located)
PortNumber outPort = dst.location().port();
DeviceId devId = dst.location().deviceId();
FlowRule nextHopRule = createL2NextHopRule(devId, dst.mac(), outPort);
flowRuleService.applyFlowRules(nextHopRule);
}
use of org.onosproject.net.Host in project onos by opennetworkinglab.
the class NodeSelection method findHosts.
private Set<String> findHosts(Set<String> ids) {
Set<String> unmatched = new HashSet<>();
Host host;
for (String id : ids) {
try {
host = hostService.getHost(hostId(id));
if (host != null) {
hosts.add(host);
} else {
unmatched.add(id);
}
} catch (Exception e) {
unmatched.add(id);
}
}
return unmatched;
}
Aggregations