@Override
 public void event(DeviceEvent event) {
   Device device = event.subject();
   switch (event.type()) {
     case DEVICE_ADDED:
       break;
     case DEVICE_AVAILABILITY_CHANGED:
       if (hostRemovalEnabled && !deviceService.isAvailable(device.id())) {
         removeHosts(hostService.getConnectedHosts(device.id()));
       }
       break;
     case DEVICE_SUSPENDED:
     case DEVICE_UPDATED:
       // Nothing to do?
       break;
     case DEVICE_REMOVED:
       if (hostRemovalEnabled) {
         removeHosts(hostService.getConnectedHosts(device.id()));
       }
       break;
     case PORT_ADDED:
       break;
     case PORT_UPDATED:
       if (hostRemovalEnabled) {
         ConnectPoint point = new ConnectPoint(device.id(), event.port().number());
         removeHosts(hostService.getConnectedHosts(point));
       }
       break;
     case PORT_REMOVED:
       // Nothing to do?
       break;
     default:
       break;
   }
 }
示例#2
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());
    }
  }
示例#3
0
 private static void assertDevice(DeviceId id, String swVersion, Device device) {
   assertNotNull(device);
   assertEquals(id, device.id());
   assertEquals(MFR, device.manufacturer());
   assertEquals(HW, device.hwVersion());
   assertEquals(swVersion, device.swVersion());
   assertEquals(SN, device.serialNumber());
 }
示例#4
0
    private void prepareInstallation() {
      Set<ControllerNode> instances = Sets.newHashSet(clusterService.getNodes());
      instances.remove(clusterService.getLocalNode());
      Set<NodeId> acceptableNodes = Sets.newHashSet();
      if (neighbours >= instances.size()) {
        instances.forEach(instance -> acceptableNodes.add(instance.id()));
      } else {
        Iterator<ControllerNode> nodes = instances.iterator();
        for (int i = neighbours; i > 0; i--) {
          acceptableNodes.add(nodes.next().id());
        }
      }
      acceptableNodes.add(clusterService.getLocalNode().id());

      Set<Device> devices = Sets.newHashSet();
      for (Device dev : deviceService.getDevices()) {
        if (acceptableNodes.contains(mastershipService.getMasterFor(dev.id()))) {
          devices.add(dev);
        }
      }

      TrafficTreatment treatment =
          DefaultTrafficTreatment.builder()
              .setOutput(PortNumber.portNumber(RandomUtils.nextInt()))
              .build();
      TrafficSelector.Builder sbuilder;
      FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
      FlowRuleOperations.Builder remove = FlowRuleOperations.builder();

      for (Device d : devices) {
        for (int i = 0; i < this.flowPerDevice; i++) {
          sbuilder = DefaultTrafficSelector.builder();

          sbuilder
              .matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i))
              .matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));

          int randomPriority = RandomUtils.nextInt();
          FlowRule f =
              DefaultFlowRule.builder()
                  .forDevice(d.id())
                  .withSelector(sbuilder.build())
                  .withTreatment(treatment)
                  .withPriority(randomPriority)
                  .fromApp(appId)
                  .makeTemporary(10)
                  .build();
          rules.add(f);
          remove.remove(f);
        }
      }

      this.adds = rules;
      this.removes = remove;
    }
示例#5
0
 public static DeviceDescription descriptionOf(Device device) {
   checkNotNull(device, "Must supply non-null Device");
   return new DefaultDeviceDescription(
       device.id().uri(), device.type(),
       device.manufacturer(), device.hwVersion(),
       device.swVersion(), device.serialNumber(),
       device.chassisId(), (SparseAnnotations) device.annotations());
 }
示例#6
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);
    }
  }
示例#7
0
  @Test
  public final void testGetDevices() {
    assertEquals("initialy empty", 0, Iterables.size(deviceStore.getDevices()));

    putDevice(DID1, SW1);
    putDevice(DID2, SW2);
    putDevice(DID1, SW1);

    assertEquals("expect 2 uniq devices", 2, Iterables.size(deviceStore.getDevices()));

    Map<DeviceId, Device> devices = new HashMap<>();
    for (Device device : deviceStore.getDevices()) {
      devices.put(device.id(), device);
    }

    assertDevice(DID1, SW1, devices.get(DID1));
    assertDevice(DID2, SW2, devices.get(DID2));

    // add case for new node?
  }
  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);
      }
    }
  }
    @Override
    public void run() {

      if (doNotPushFlows) {
        return;
      }

      switch (deviceEvent.type()) {
        case DEVICE_ADDED:
          processDeviceAdded((Device) deviceEvent.subject());
          break;
        case DEVICE_UPDATED:
          Port port = (Port) deviceEvent.subject();
          if (port.isEnabled()) {
            processPortAdded((Device) deviceEvent.subject(), deviceEvent.port());
          }
          break;
        case DEVICE_AVAILABILITY_CHANGED:
          Device device = (Device) deviceEvent.subject();
          if (deviceService.isAvailable(device.id())) {
            processDeviceAdded(device);
          }
          break;
        case PORT_ADDED:
          processPortAdded((Device) deviceEvent.subject(), deviceEvent.port());
          break;
        case PORT_UPDATED:
          processPortAdded((Device) deviceEvent.subject(), deviceEvent.port());
          break;
        case PORT_REMOVED:
          processPortRemoved((Device) deviceEvent.subject(), deviceEvent.port());
          break;
        default:
          break;
      }
    }
示例#10
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);
   }
 }
 private void processDeviceAdded(Device device) {
   log.debug("device {} is added", device.id());
 }