Search in sources :

Example 21 with Host

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);
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 22 with Host

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));
}
Also used : DefaultHost(org.onosproject.net.DefaultHost) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) Test(org.junit.Test)

Example 23 with Host

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);
}
Also used : GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Link(org.onosproject.net.Link) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) Set(java.util.Set) ItemNotFoundException(org.onlab.util.ItemNotFoundException) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) LinkEvent(org.onosproject.net.link.LinkEvent) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) Ip6Prefix(org.onlab.packet.Ip6Prefix) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Streams.stream(com.google.common.collect.Streams.stream) PiAction(org.onosproject.net.pi.runtime.PiAction) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) Ip6Address(org.onlab.packet.Ip6Address) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress)

Example 24 with Host

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);
}
Also used : Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) Link(org.onosproject.net.Link)

Example 25 with Host

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;
}
Also used : Host(org.onosproject.net.Host) ConnectPoint.fromString(org.onosproject.net.ConnectPoint.fromString) HashSet(java.util.HashSet)

Aggregations

Host (org.onosproject.net.Host)144 MacAddress (org.onlab.packet.MacAddress)55 IpAddress (org.onlab.packet.IpAddress)54 HostEvent (org.onosproject.net.host.HostEvent)50 ConnectPoint (org.onosproject.net.ConnectPoint)47 Test (org.junit.Test)45 DefaultHost (org.onosproject.net.DefaultHost)45 HostService (org.onosproject.net.host.HostService)45 Set (java.util.Set)43 VlanId (org.onlab.packet.VlanId)43 DeviceId (org.onosproject.net.DeviceId)39 Logger (org.slf4j.Logger)39 HostLocation (org.onosproject.net.HostLocation)38 LoggerFactory (org.slf4j.LoggerFactory)37 List (java.util.List)34 HostId (org.onosproject.net.HostId)33 Interface (org.onosproject.net.intf.Interface)32 Sets (com.google.common.collect.Sets)31 Optional (java.util.Optional)30 Lists (com.google.common.collect.Lists)29