示例#1
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;
 }
示例#2
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;
    }
  }