Beispiel #1
0
  // Adds any missing device ports.
  private void addMissingPorts(Device device) {
    try {
      List<Port> ports = deviceService.getPorts(device.id());
      Set<ConnectPoint> existing =
          ports
              .stream()
              .map(p -> new ConnectPoint(device.id(), p.number()))
              .collect(Collectors.toSet());
      Set<ConnectPoint> missing =
          connectPoints
              .stream()
              .filter(cp -> cp.deviceId().equals(device.id()))
              .filter(cp -> !existing.contains(cp))
              .collect(Collectors.toSet());

      if (!missing.isEmpty()) {
        List<PortDescription> newPorts =
            Stream.concat(
                    ports.stream().map(this::description), missing.stream().map(this::description))
                .collect(Collectors.toList());
        deviceProviderService.updatePorts(device.id(), newPorts);
      }
    } catch (IllegalArgumentException e) {
      log.warn("Error pushing ports: {}", e.getMessage());
    }
  }
Beispiel #2
0
 // Parses the given node with list of device ports.
 private void parsePorts(DeviceId deviceId, JsonNode nodes) {
   List<PortDescription> ports = new ArrayList<>();
   for (JsonNode node : nodes) {
     ports.add(parsePort(node));
   }
   deviceProviderService.updatePorts(deviceId, ports);
 }
Beispiel #3
0
  private void updateOMSPorts(int numChls, ConnectPoint srcCp, ConnectPoint dstCp) {
    // round down to largest slot that allows numChl channels to fit into C band range
    ChannelSpacing chl = null;
    Frequency perChl = TOTAL.floorDivision(numChls);
    for (int i = 0; i < ChannelSpacing.values().length; i++) {
      Frequency val = ChannelSpacing.values()[i].frequency();
      if (val.isLessThan(perChl)) {
        chl = ChannelSpacing.values()[i];
        break;
      }
    }
    if (chl == null) {
      chl = ChannelSpacing.CHL_6P25GHZ;
    }

    // if true, there was less channels than can be tightly packed.
    Frequency grid = chl.frequency();
    // say Linc's 1st slot starts at CENTER and goes up from there.
    Frequency min = CENTER.add(grid);
    Frequency max = CENTER.add(grid.multiply(numChls));

    PortDescription srcPortDesc = new OmsPortDescription(srcCp.port(), true, min, max, grid);
    PortDescription dstPortDesc = new OmsPortDescription(dstCp.port(), true, min, max, grid);
    descriptions.put(srcCp, srcPortDesc);
    descriptions.put(dstCp, dstPortDesc);
    deviceProviderService.portStatusChanged(srcCp.deviceId(), srcPortDesc);
    deviceProviderService.portStatusChanged(dstCp.deviceId(), dstPortDesc);
  }
Beispiel #4
0
 // uses 'bandwidth' annotation to determine the channel spacing.
 private void updateOchPort(double bw, ConnectPoint srcCp, ConnectPoint dstCp) {
   Device src = deviceService.getDevice(srcCp.deviceId());
   Device dst = deviceService.getDevice(dstCp.deviceId());
   // bandwidth in MHz (assuming Hz - linc is not clear if that or Mb).
   Frequency spacing = Frequency.ofMHz(bw);
   // channel bandwidth is smaller than smallest standard channel spacing.
   ChannelSpacing chsp = null;
   if (spacing.compareTo(ChannelSpacing.CHL_6P25GHZ.frequency()) <= 0) {
     chsp = ChannelSpacing.CHL_6P25GHZ;
   }
   for (int i = 1; i < ChannelSpacing.values().length; i++) {
     Frequency val = ChannelSpacing.values()[i].frequency();
     // pick the next highest or equal channel interval.
     if (val.isLessThan(spacing)) {
       chsp = ChannelSpacing.values()[i - 1];
       break;
     }
   }
   if (chsp == null) {
     log.warn("Invalid channel spacing ({}), can't configure port(s)", spacing);
     return;
   }
   OchSignal signal = new OchSignal(GridType.DWDM, chsp, 1, 1);
   if (src.type() == Device.Type.ROADM) {
     PortDescription portDesc =
         new OchPortDescription(srcCp.port(), true, OduSignalType.ODU4, true, signal);
     descriptions.put(srcCp, portDesc);
     deviceProviderService.portStatusChanged(srcCp.deviceId(), portDesc);
   }
   if (dst.type() == Device.Type.ROADM) {
     PortDescription portDesc =
         new OchPortDescription(dstCp.port(), true, OduSignalType.ODU4, true, signal);
     descriptions.put(dstCp, portDesc);
     deviceProviderService.portStatusChanged(dstCp.deviceId(), portDesc);
   }
 }
Beispiel #5
0
  // Adds any missing device ports.
  private void addMissingPorts(Device device) {
    List<Port> ports = deviceService.getPorts(device.id());
    Set<ConnectPoint> existing =
        ports
            .stream()
            .map(p -> new ConnectPoint(device.id(), p.number()))
            .collect(Collectors.toSet());
    Set<ConnectPoint> missing =
        connectPoints.stream().filter(cp -> !existing.contains(cp)).collect(Collectors.toSet());

    if (!missing.isEmpty()) {
      List<PortDescription> newPorts = Lists.newArrayList();
      ports.forEach(p -> newPorts.add(description(p)));
      missing.forEach(cp -> newPorts.add(description(cp)));
      deviceProviderService.updatePorts(device.id(), newPorts);
    }
  }
Beispiel #6
0
  // Parses the given node with device data and supplies the device.
  private void parseDevice(JsonNode node) {
    URI uri = URI.create(get(node, "uri"));
    Device.Type type = Device.Type.valueOf(get(node, "type", "SWITCH"));
    String mfr = get(node, "mfr", UNKNOWN);
    String hw = get(node, "hw", UNKNOWN);
    String sw = get(node, "sw", UNKNOWN);
    String serial = get(node, "serial", UNKNOWN);
    ChassisId cid = new ChassisId(get(node, "mac", "000000000000"));
    SparseAnnotations annotations = annotations(node.get("annotations"));

    DeviceDescription desc =
        new DefaultDeviceDescription(uri, type, mfr, hw, sw, serial, cid, annotations);
    DeviceId deviceId = deviceId(uri);
    deviceProviderService.deviceConnected(deviceId, desc);

    JsonNode ports = node.get("ports");
    if (ports != null) {
      parsePorts(deviceId, ports);
    }
  }
Beispiel #7
0
 private void deviceAdded(RestSBDevice nodeId) {
   Preconditions.checkNotNull(nodeId, ISNOTNULL);
   DeviceId deviceId = nodeId.deviceId();
   ChassisId cid = new ChassisId();
   String ipAddress = nodeId.ip().toString();
   SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).build();
   DeviceDescription deviceDescription =
       new DefaultDeviceDescription(
           deviceId.uri(),
           Device.Type.SWITCH,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           cid,
           annotations);
   providerService.deviceConnected(deviceId, deviceDescription);
   nodeId.setActive(true);
   controller.addDevice(nodeId);
 }
  private void connectDevices() {
    NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class);
    if (cfg != null) {
      try {
        cfg.getDevicesAddresses()
            .stream()
            .forEach(
                addr -> {
                  try {
                    NetconfDeviceInfo netconf =
                        new NetconfDeviceInfo(addr.name(), addr.password(), addr.ip(), addr.port());
                    controller.connectDevice(netconf);
                    Device device = deviceService.getDevice(netconf.getDeviceId());
                    if (device.is(PortDiscovery.class)) {
                      PortDiscovery portConfig = device.as(PortDiscovery.class);
                      if (portConfig != null) {
                        providerService.updatePorts(netconf.getDeviceId(), portConfig.getPorts());
                      }
                    } else {
                      log.warn("No portGetter behaviour for device {}", netconf.getDeviceId());
                    }

                  } catch (IOException e) {
                    throw new RuntimeException(
                        new NetconfException(
                            "Can't connect to NETCONF "
                                + "device on "
                                + addr.ip()
                                + ":"
                                + addr.port(),
                            e));
                  }
                });

      } catch (ConfigException e) {
        log.error("Cannot read config error " + e);
      }
    }
  }
Beispiel #9
0
 private void connectDevices() {
   RestProviderConfig cfg = cfgService.getConfig(appId, RestProviderConfig.class);
   try {
     if (cfg != null && cfg.getDevicesAddresses() != null) {
       // Precomputing the devices to be removed
       Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values());
       toBeRemoved.removeAll(cfg.getDevicesAddresses());
       // Adding new devices
       cfg.getDevicesAddresses()
           .stream()
           .filter(device -> testDeviceConnection(device))
           .forEach(
               device -> {
                 deviceAdded(device);
               });
       // Removing devices not wanted anymore
       toBeRemoved.stream().forEach(device -> deviceRemoved(device));
     }
   } catch (ConfigException e) {
     log.error("Configuration error {}", e);
   }
   log.info("REST Devices {}", controller.getDevices());
   controller
       .getDevices()
       .keySet()
       .forEach(
           deviceId -> {
             DriverHandler h = driverService.createHandler(deviceId);
             PortDiscovery portConfig = h.behaviour(PortDiscovery.class);
             if (portConfig != null) {
               providerService.updatePorts(deviceId, portConfig.getPorts());
             } else {
               log.warn("No portGetter behaviour for device {}", deviceId);
             }
           });
 }
Beispiel #10
0
 @Override
 public void roleChanged(DeviceId device, MastershipRole newRole) {
   deviceProviderService.receivedRoleReply(device, newRole, newRole);
 }
Beispiel #11
0
 // when do I call it ?
 public void deviceRemoved(RestSBDevice nodeId) {
   Preconditions.checkNotNull(nodeId, ISNOTNULL);
   DeviceId deviceId = nodeId.deviceId();
   providerService.deviceDisconnected(deviceId);
   controller.removeDevice(nodeId);
 }