Beispiel #1
0
  @Activate
  protected void activate() {
    appId = coreService.registerApplication("org.onosproject.cordvtn");
    ruleInstaller =
        new CordVtnRuleInstaller(
            appId,
            flowRuleService,
            deviceService,
            driverService,
            groupService,
            mastershipService,
            DEFAULT_TUNNEL);

    arpProxy = new CordVtnArpProxy(appId, packetService);
    packetService.addProcessor(packetProcessor, PacketProcessor.director(0));
    arpProxy.requestPacket();

    hostService.addListener(hostListener);
    hostProvider = hostProviderRegistry.register(this);

    configRegistry.registerConfigFactory(configFactory);
    configService.addListener(configListener);
    readConfiguration();

    log.info("Started");
  }
Beispiel #2
0
 @Deactivate
 public void deactivate() {
   topologyService.removeListener(listener);
   resourceManager.removeListener(linkResourceListener);
   deviceService.removeListener(deviceListener);
   hostService.removeListener(hostListener);
   partitionService.removeListener(partitionListener);
   log.info("Stopped");
 }
Beispiel #3
0
 @Activate
 public void activate() {
   topologyService.addListener(listener);
   resourceManager.addListener(linkResourceListener);
   deviceService.addListener(deviceListener);
   hostService.addListener(hostListener);
   partitionService.addListener(partitionListener);
   log.info("Started");
 }
  private void handle(Ethernet eth) {
    checkNotNull(eth);

    if (!(eth.getEtherType() == EthType.EtherType.IPV4.ethType().toShort())) {
      return;
    }

    IPv4 ipv4 = (IPv4) eth.getPayload().clone();

    Ip4Address dstIp = Ip4Address.valueOf(ipv4.getDestinationAddress());

    Interface egressInterface = interfaceService.getMatchingInterface(dstIp);

    if (egressInterface == null) {
      log.info("No egress interface found for {}", dstIp);
      return;
    }

    Optional<Host> host =
        hostService
            .getHostsByIp(dstIp)
            .stream()
            .filter(h -> h.location().equals(egressInterface.connectPoint()))
            .filter(h -> h.vlan().equals(egressInterface.vlan()))
            .findAny();

    if (host.isPresent()) {
      transformAndSend(ipv4, egressInterface, host.get().mac());
    } else {
      hostService.startMonitoringIp(dstIp);
      ipPacketCache
          .asMap()
          .compute(
              dstIp,
              (ip, queue) -> {
                if (queue == null) {
                  queue = new ConcurrentLinkedQueue();
                }
                queue.add(ipv4);
                return queue;
              });
    }
  }
  private void disable() {
    packetService.removeProcessor(packetProcessor);
    hostService.removeListener(hostListener);

    TrafficSelector selector =
        DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
            .build();
    packetService.cancelPackets(selector, PacketPriority.REACTIVE, appId, Optional.empty());
  }
  private void enable() {
    hostService.addListener(hostListener);
    packetService.addProcessor(packetProcessor, PacketProcessor.director(3));

    TrafficSelector selector =
        DefaultTrafficSelector.builder()
            .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
            .build();
    packetService.requestPackets(selector, PacketPriority.REACTIVE, appId, Optional.empty());
  }
Beispiel #7
0
  @Override
  public void removeServiceVm(ConnectPoint connectPoint) {
    Host host = hostService.getConnectedHosts(connectPoint).stream().findFirst().orElse(null);

    if (host == null) {
      log.debug("No host is connected on {}", connectPoint.toString());
      return;
    }

    hostProvider.hostVanished(host.id());
  }
Beispiel #8
0
 // Finds the host edge link if the element ID is a host id of an existing
 // host. Otherwise, if the host does not exist, it returns null and if
 // the element ID is not a host ID, returns NOT_HOST edge link.
 private EdgeLink getEdgeLink(ElementId elementId, boolean isIngress) {
   if (elementId instanceof HostId) {
     // Resolve the host, return null.
     Host host = hostService.getHost((HostId) elementId);
     if (host == null) {
       return null;
     }
     return new DefaultEdgeLink(PID, new ConnectPoint(elementId, P0), host.location(), isIngress);
   }
   return NOT_HOST;
 }
Beispiel #9
0
  @Deactivate
  protected void deactivate() {
    hostProviderRegistry.unregister(this);
    hostService.removeListener(hostListener);

    packetService.removeProcessor(packetProcessor);

    configRegistry.unregisterConfigFactory(configFactory);
    configService.removeListener(configListener);

    eventExecutor.shutdown();
    log.info("Stopped");
  }
Beispiel #10
0
  /**
   * Returns hosts associated with a given OpenStack network.
   *
   * @param vNet openstack network
   * @return set of hosts
   */
  private Set<Host> getHostsWithOpenstackNetwork(OpenstackNetwork vNet) {
    checkNotNull(vNet);

    Set<Host> hosts =
        openstackService
            .ports(vNet.id())
            .stream()
            .filter(port -> port.deviceOwner().contains("compute"))
            .map(
                port ->
                    hostService.getHostsByMac(port.macAddress()).stream().findFirst().orElse(null))
            .collect(Collectors.toSet());

    hosts.remove(null);
    return hosts;
  }
Beispiel #11
0
  /**
   * Sets service network gateway MAC address and sends out gratuitous ARP to all VMs to update the
   * gateway MAC address.
   *
   * @param mac mac address
   */
  private void setServiceGatewayMac(MacAddress mac) {
    if (mac != null && !mac.equals(gatewayMac)) {
      gatewayMac = mac;
      log.debug("Set service gateway MAC address to {}", gatewayMac.toString());
    }

    // TODO get existing service list from XOS and replace the loop below
    Set<String> vNets = Sets.newHashSet();
    hostService.getHosts().forEach(host -> vNets.add(host.annotations().value(SERVICE_ID)));
    vNets.remove(null);

    vNets
        .stream()
        .forEach(
            vNet -> {
              CordService service = getCordService(CordServiceId.of(vNet));
              if (service != null) {
                arpProxy.sendGratuitousArp(
                    service.serviceIp(), gatewayMac, service.hosts().keySet());
              }
            });
  }
Beispiel #12
0
  @Override
  public void addServiceVm(CordVtnNode node, ConnectPoint connectPoint) {
    Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
    OpenstackPort vPort = openstackService.port(port);
    if (vPort == null) {
      log.warn("Failed to get OpenstackPort for {}", getPortName(port));
      return;
    }

    MacAddress mac = vPort.macAddress();
    HostId hostId = HostId.hostId(mac);

    Host host = hostService.getHost(hostId);
    if (host != null) {
      // Host is already known to the system, no HOST_ADDED event is triggered in this case.
      // It happens when the application is restarted.
      // TODO check host description if it has all the information
      serviceVmAdded(host);
      return;
    }

    Set<IpAddress> ip = Sets.newHashSet(vPort.fixedIps().values());
    SparseAnnotations annotations =
        DefaultAnnotations.builder()
            .set(OPENSTACK_VM_ID, vPort.deviceId())
            .set(SERVICE_ID, vPort.networkId())
            .set(LOCATION_IP, node.localIp().toString())
            .build();

    HostDescription hostDesc =
        new DefaultHostDescription(
            mac,
            VlanId.NONE,
            new HostLocation(connectPoint, System.currentTimeMillis()),
            ip,
            annotations);

    hostProvider.hostDetected(hostId, hostDesc, false);
  }
  private void updateForMode(String id) {
    log.debug("host service: {}", hostService);
    log.debug("device service: {}", deviceService);

    try {
      HostId hid = HostId.hostId(id);
      log.debug("host id {}", hid);
      elementOfNote = hostService.getHost(hid);
      log.debug("host element {}", elementOfNote);

    } catch (Exception e) {
      try {
        DeviceId did = DeviceId.deviceId(id);
        log.debug("device id {}", did);
        elementOfNote = deviceService.getDevice(did);
        log.debug("device element {}", elementOfNote);

      } catch (Exception e2) {
        log.debug("Unable to process ID [{}]", id);
        elementOfNote = null;
      }
    }

    switch (currentMode) {
      case MOUSE:
        sendMouseData();
        break;

      case LINK:
        sendLinkData();
        break;

      default:
        break;
    }
  }