Ejemplo n.º 1
0
 private void stopDevice(NetconfDeviceInfo deviceInfo) {
   netconfDeviceMap.get(deviceInfo.getDeviceId()).disconnect();
   netconfDeviceMap.remove(deviceInfo.getDeviceId());
   for (NetconfDeviceListener l : netconfDeviceListeners) {
     l.deviceRemoved(deviceInfo);
   }
 }
Ejemplo n.º 2
0
 @Override
 public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws NetconfException {
   if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
     log.info("Device {} is already present", deviceInfo);
     return netconfDeviceMap.get(deviceInfo.getDeviceId());
   } else {
     log.info("Creating NETCONF device {}", deviceInfo);
     NetconfDevice device = createDevice(deviceInfo);
     device.getSession().addDeviceOutputListener(downListener);
     return device;
   }
 }
Ejemplo n.º 3
0
 private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws NetconfException {
   NetconfDevice netconfDevice = deviceFactory.createNetconfDevice(deviceInfo);
   for (NetconfDeviceListener l : netconfDeviceListeners) {
     l.deviceAdded(deviceInfo);
   }
   netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
   return netconfDevice;
 }
Ejemplo n.º 4
0
 @Override
 public void removeDevice(NetconfDeviceInfo deviceInfo) {
   if (!netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
     log.warn("Device {} is not present", deviceInfo);
   } else {
     stopDevice(deviceInfo);
   }
 }
Ejemplo n.º 5
0
  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);
      }
    }
  }
Ejemplo n.º 6
0
 @Override
 public void deviceAdded(NetconfDeviceInfo nodeId) {
   Preconditions.checkNotNull(nodeId, ISNULL);
   DeviceId deviceId = nodeId.getDeviceId();
   // Netconf configuration object
   ChassisId cid = new ChassisId();
   String ipAddress = nodeId.ip().toString();
   SparseAnnotations annotations =
       DefaultAnnotations.builder()
           .set(IPADDRESS, ipAddress)
           .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase())
           .build();
   DeviceDescription deviceDescription =
       new DefaultDeviceDescription(
           deviceId.uri(),
           Device.Type.SWITCH,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           UNKNOWN,
           cid,
           annotations);
   providerService.deviceConnected(deviceId, deviceDescription);
 }
Ejemplo n.º 7
0
 @Override
 public void deviceRemoved(NetconfDeviceInfo nodeId) {
   Preconditions.checkNotNull(nodeId, ISNULL);
   DeviceId deviceId = nodeId.getDeviceId();
   providerService.deviceDisconnected(deviceId);
 }