Search in sources :

Example 41 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackSwitchingHostProviderTest method verifyHostLocationResult.

/**
 * Verifies the HostId and HostLocation.
 *
 * @param hostId        host identifier
 * @param hostLocation  host location
 */
private void verifyHostLocationResult(HostId hostId, HostLocation hostLocation) {
    Host host = hostMap.get(hostId);
    assertTrue(host.locations().stream().anyMatch(location -> location.equals(hostLocation)));
}
Also used : DefaultApplicationId(org.onosproject.core.DefaultApplicationId) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) HostLocation(org.onosproject.net.HostLocation) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Host(org.onosproject.net.Host) DeviceServiceAdapter(org.onosproject.net.device.DeviceServiceAdapter) Network(org.openstack4j.model.network.Network) PortNumber(org.onosproject.net.PortNumber) DefaultDevice(org.onosproject.net.DefaultDevice) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultHost(org.onosproject.net.DefaultHost) HostProviderService(org.onosproject.net.host.HostProviderService) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) NeutronNetwork(org.openstack4j.openstack.networking.domain.NeutronNetwork) After(org.junit.After) TestUtils(org.onlab.junit.TestUtils) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) HostId(org.onosproject.net.HostId) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) Port(org.openstack4j.model.network.Port) ANNOTATION_PORT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_PORT_ID) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) HostProvider(org.onosproject.net.host.HostProvider) HostServiceAdapter(org.onosproject.net.host.HostServiceAdapter) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) NetworkType(org.openstack4j.model.network.NetworkType) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Assert.assertNull(org.junit.Assert.assertNull) DeviceEvent(org.onosproject.net.device.DeviceEvent) MacAddress(org.onlab.packet.MacAddress) CoreServiceAdapter(org.onosproject.core.CoreServiceAdapter) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) DeviceId(org.onosproject.net.DeviceId) HostDescription(org.onosproject.net.host.HostDescription) ANNOTATION_NETWORK_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_NETWORK_ID) Assert.assertEquals(org.junit.Assert.assertEquals) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost)

Example 42 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackSwitchingHostProviderTest method testProcessPortAddedForNewAddition.

/**
 * Tests the process port added method for new addition case.
 */
@Test
public void testProcessPortAddedForNewAddition() {
    org.onosproject.net.Port port = new DefaultPort(DEV2, P1, true, ANNOTATIONS);
    DeviceEvent event = new DeviceEvent(DeviceEvent.Type.PORT_ADDED, DEV2, port);
    target.portAddedHelper(event);
    HostId hostId = HostId.hostId(HOST_MAC2);
    HostDescription hostDesc = new DefaultHostDescription(HOST_MAC2, VlanId.NONE, new HostLocation(CP21, System.currentTimeMillis()), ImmutableSet.of(HOST_IP11), ANNOTATIONS);
    verifyHostResult(hostId, hostDesc);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostLocation(org.onosproject.net.HostLocation) HostId(org.onosproject.net.HostId) DefaultPort(org.onosproject.net.DefaultPort) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) HostDescription(org.onosproject.net.host.HostDescription) Test(org.junit.Test)

Example 43 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class OpenstackVtapManager method updateHostbyType.

/**
 * Updates device list of vtaps with respect to the host changes.
 *
 * @param newHost   new host instance
 * @param oldHost   old host instance
 */
private void updateHostbyType(Type type, Host newHost, Host oldHost) {
    getVtaps(type).forEach(vtap -> {
        IpPrefix prefix = (type == Type.VTAP_TX) ? vtap.vtapCriterion().srcIpPrefix() : vtap.vtapCriterion().dstIpPrefix();
        int hostDiff = hostCompareIp(newHost, oldHost, prefix);
        if (hostDiff < 0) {
            oldHost.locations().stream().map(HostLocation::deviceId).forEach(deviceId -> store.removeDeviceFromVtap(vtap.id(), type, deviceId));
        } else if (hostDiff > 0) {
            newHost.locations().stream().map(HostLocation::deviceId).filter(deviceId -> Objects.nonNull(osNodeService.node(deviceId))).forEach(deviceId -> store.addDeviceToVtap(vtap.id(), type, deviceId));
        }
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) OpenstackVtapUtil.getTunnelName(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getTunnelName) COMPLETE(org.onosproject.openstacknode.api.NodeState.COMPLETE) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) VTAP_INBOUND_MIRROR_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_MIRROR_TABLE) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) PROTOCOL_UDP(org.onlab.packet.IPv4.PROTOCOL_UDP) OpenstackVtapUtil.isValidHost(org.onosproject.openstackvtap.util.OpenstackVtapUtil.isValidHost) VTAP_INBOUND_GROUP_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_GROUP_TABLE) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackVtapUtil.getGroupKey(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getGroupKey) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Type(org.onosproject.openstackvtap.api.OpenstackVtap.Type) VTAP_OUTBOUND_MIRROR_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_MIRROR_TABLE) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) Dictionary(java.util.Dictionary) VTAP_OUTBOUND_GROUP_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_GROUP_TABLE) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) ComponentContext(org.osgi.service.component.ComponentContext) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) HostListener(org.onosproject.net.host.HostListener) TUNNEL_NICIRA(org.onosproject.openstackvtap.impl.OsgiPropertyConstants.TUNNEL_NICIRA) HostService(org.onosproject.net.host.HostService) VTAP_INBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_INBOUND_TABLE) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackVtapEvent(org.onosproject.openstackvtap.api.OpenstackVtapEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OpenstackVtapStore(org.onosproject.openstackvtap.api.OpenstackVtapStore) StreamSupport(java.util.stream.StreamSupport) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) DeviceListener(org.onosproject.net.device.DeviceListener) PROTOCOL_ICMP(org.onlab.packet.IPv4.PROTOCOL_ICMP) GroupService(org.onosproject.net.group.GroupService) GroupId(org.onosproject.core.GroupId) LeadershipService(org.onosproject.cluster.LeadershipService) OpenstackVtapUtil.hostCompareIp(org.onosproject.openstackvtap.util.OpenstackVtapUtil.hostCompareIp) HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) VTAP_FLAT_OUTBOUND_GROUP_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_GROUP_TABLE) INTEGRATION_BRIDGE(org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) Mode(org.onosproject.openstackvtap.api.OpenstackVtapNetwork.Mode) OpenstackVtapUtil.dumpStackTrace(org.onosproject.openstackvtap.util.OpenstackVtapUtil.dumpStackTrace) TYPE_IPV4(org.onlab.packet.Ethernet.TYPE_IPV4) TUNNEL_NICRA_DEFAULT(org.onosproject.openstackvtap.impl.OsgiPropertyConstants.TUNNEL_NICRA_DEFAULT) NodeId(org.onosproject.cluster.NodeId) ImmutableSet(com.google.common.collect.ImmutableSet) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Device(org.onosproject.net.Device) DHCP_TABLE(org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NICIRA_RESUBMIT_TABLE(org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE) VTAP_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_OUTBOUND_TABLE) Objects(java.util.Objects) NICIRA_SET_TUNNEL_DST(org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) OpenstackVtapUtil.containsIp(org.onosproject.openstackvtap.util.OpenstackVtapUtil.containsIp) FLAT_TABLE(org.onosproject.openstacknetworking.api.Constants.FLAT_TABLE) FlowRule(org.onosproject.net.flow.FlowRule) ClusterService(org.onosproject.cluster.ClusterService) OpenstackVtapId(org.onosproject.openstackvtap.api.OpenstackVtapId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) IpPrefix(org.onlab.packet.IpPrefix) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) OpenstackVtapListener(org.onosproject.openstackvtap.api.OpenstackVtapListener) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) TunnelKey(org.onosproject.net.behaviour.TunnelKey) GroupBucket(org.onosproject.net.group.GroupBucket) VTAP_FLAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_TABLE) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) OpenstackVtapStoreDelegate(org.onosproject.openstackvtap.api.OpenstackVtapStoreDelegate) ImmutableList(com.google.common.collect.ImmutableList) OpenstackVtapAdminService(org.onosproject.openstackvtap.api.OpenstackVtapAdminService) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) VTAP_FLAT_OUTBOUND_MIRROR_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAP_FLAT_OUTBOUND_MIRROR_TABLE) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FORWARDING_TABLE(org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE) Logger(org.slf4j.Logger) OpenstackVtapService(org.onosproject.openstackvtap.api.OpenstackVtapService) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OpenstackVtapNetwork(org.onosproject.openstackvtap.api.OpenstackVtapNetwork) PROTOCOL_TCP(org.onlab.packet.IPv4.PROTOCOL_TCP) Reference(org.osgi.service.component.annotations.Reference) OpenstackVtapUtil.getTunnelType(org.onosproject.openstackvtap.util.OpenstackVtapUtil.getTunnelType)

Example 44 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method writeRequestDhcpRecord.

/**
 * Writes DHCP record to the store according to the request DHCP packet (Discover, Request).
 *
 * @param location the location which DHCP packet comes from
 * @param ethernet the DHCP packet
 * @param dhcpPayload the DHCP payload
 */
private void writeRequestDhcpRecord(ConnectPoint location, Ethernet ethernet, DHCP dhcpPayload) {
    VlanId vlanId = VlanId.vlanId(ethernet.getVlanID());
    MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
    HostId hostId = HostId.hostId(macAddress, vlanId);
    DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
    if (record == null) {
        record = new DhcpRecord(HostId.hostId(macAddress, vlanId));
    } else {
        record = record.clone();
    }
    record.addLocation(new HostLocation(location, System.currentTimeMillis()));
    record.ip4Status(dhcpPayload.getPacketType());
    record.setDirectlyConnected(directlyConnected(dhcpPayload));
    if (!directlyConnected(dhcpPayload)) {
        // Update gateway mac address if the host is not directly connected
        record.nextHop(ethernet.getSourceMAC());
    }
    record.updateLastSeen();
    dhcpRelayStore.updateDhcpRecord(HostId.hostId(macAddress, vlanId), record);
}
Also used : HostLocation(org.onosproject.net.HostLocation) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) VlanId(org.onlab.packet.VlanId)

Example 45 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class Dhcp4HandlerImpl method writeResponseDhcpRecord.

/**
 * Writes DHCP record to the store according to the response DHCP packet (Offer, Ack).
 *
 * @param ethernet the DHCP packet
 * @param dhcpPayload the DHCP payload
 */
private void writeResponseDhcpRecord(Ethernet ethernet, DHCP dhcpPayload) {
    Optional<Interface> outInterface = getClientInterface(ethernet, dhcpPayload);
    if (!outInterface.isPresent()) {
        log.warn("Failed to determine where to send {}", dhcpPayload.getPacketType());
        return;
    }
    Interface outIface = outInterface.get();
    ConnectPoint location = outIface.connectPoint();
    if (!location.port().hasName()) {
        location = translateSwitchPort(location);
    }
    VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
    if (vlanId == null) {
        vlanId = outIface.vlan();
    }
    MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
    HostId hostId = HostId.hostId(macAddress, vlanId);
    DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
    if (record == null) {
        record = new DhcpRecord(HostId.hostId(macAddress, vlanId));
    } else {
        record = record.clone();
    }
    record.addLocation(new HostLocation(location, System.currentTimeMillis()));
    if (dhcpPayload.getPacketType() == DHCP.MsgType.DHCPACK) {
        record.ip4Address(Ip4Address.valueOf(dhcpPayload.getYourIPAddress()));
    }
    record.ip4Status(dhcpPayload.getPacketType());
    record.setDirectlyConnected(directlyConnected(dhcpPayload));
    record.updateLastSeen();
    dhcpRelayStore.updateDhcpRecord(HostId.hostId(macAddress, vlanId), record);
}
Also used : HostLocation(org.onosproject.net.HostLocation) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) VlanId(org.onlab.packet.VlanId)

Aggregations

HostLocation (org.onosproject.net.HostLocation)52 IpAddress (org.onlab.packet.IpAddress)29 MacAddress (org.onlab.packet.MacAddress)25 VlanId (org.onlab.packet.VlanId)22 HostId (org.onosproject.net.HostId)22 Host (org.onosproject.net.Host)19 ConnectPoint (org.onosproject.net.ConnectPoint)15 Test (org.junit.Test)14 DefaultHost (org.onosproject.net.DefaultHost)14 DeviceId (org.onosproject.net.DeviceId)12 HostDescription (org.onosproject.net.host.HostDescription)11 ProviderId (org.onosproject.net.provider.ProviderId)11 Set (java.util.Set)10 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)10 Logger (org.slf4j.Logger)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)7 PortNumber (org.onosproject.net.PortNumber)7 DeviceEvent (org.onosproject.net.device.DeviceEvent)7 HostService (org.onosproject.net.host.HostService)7