private void processPortAdded(Device device, Port port) {
   if (!port.annotations().value("portName").equals("vxlan")) {
     OpenstackSwitchingRulePopulator rulePopulator =
         new OpenstackSwitchingRulePopulator(
             appId, flowObjectiveService, deviceService, restHandler, driverService);
     rulePopulator.populateSwitchingRules(device, port);
   }
 }
Esempio n. 2
0
 // Creates a port description from the specified port.
 private PortDescription description(Port p) {
   switch (p.type()) {
     case OMS:
       OmsPort op = (OmsPort) p;
       return new OmsPortDescription(
           op.number(), op.isEnabled(), op.minFrequency(), op.maxFrequency(), op.grid());
     case OCH:
       OchPort ochp = (OchPort) p;
       return new OchPortDescription(
           ochp.number(), ochp.isEnabled(), ochp.signalType(), ochp.isTunable(), ochp.lambda());
     case ODUCLT:
       OduCltPort odup = (OduCltPort) p;
       return new OduCltPortDescription(odup.number(), odup.isEnabled(), odup.signalType());
     default:
       return new DefaultPortDescription(p.number(), p.isEnabled(), p.type(), p.portSpeed());
   }
 }
Esempio n. 3
0
  @Test
  public final void testGetPorts() {
    putDevice(DID1, SW1);
    putDevice(DID2, SW1);
    List<PortDescription> pds =
        Arrays.<PortDescription>asList(
            new DefaultPortDescription(P1, true), new DefaultPortDescription(P2, true));
    deviceStore.updatePorts(PID, DID1, pds);

    Set<PortNumber> expectedPorts = Sets.newHashSet(P1, P2);
    List<Port> ports = deviceStore.getPorts(DID1);
    for (Port port : ports) {
      assertTrue("Port is enabled", port.isEnabled());
      assertTrue("PortNumber is one of expected", expectedPorts.remove(port.number()));
    }
    assertTrue("Event for all expectedport appeared", expectedPorts.isEmpty());

    assertTrue("DID2 has no ports", deviceStore.getPorts(DID2).isEmpty());
  }
Esempio n. 4
0
  // Produces a connection point from the specified uri/port text.
  private ConnectPoint connectPoint(String text) {
    int i = text.lastIndexOf("/");
    String portName = text.substring(i + 1);
    DeviceId deviceId = deviceId(text.substring(0, i));

    for (Port port : deviceService.getPorts(deviceId)) {
      PortNumber pn = port.number();
      if (pn.name().equals(portName)) {
        return new ConnectPoint(deviceId, pn);
      }
    }

    long portNum;
    try {
      portNum = Long.parseLong(portName);
    } catch (NumberFormatException e) {
      portNum = 0;
    }

    return new ConnectPoint(deviceId, portNumber(portNum, portName));
  }
    @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;
      }
    }
Esempio n. 6
0
  @Test
  public final void testGetPort() {
    putDevice(DID1, SW1);
    putDevice(DID2, SW1);
    List<PortDescription> pds =
        Arrays.<PortDescription>asList(
            new DefaultPortDescription(P1, true), new DefaultPortDescription(P2, false));
    deviceStore.updatePorts(PID, DID1, pds);

    Port port1 = deviceStore.getPort(DID1, P1);
    assertEquals(P1, port1.number());
    assertTrue("Port is enabled", port1.isEnabled());

    Port port2 = deviceStore.getPort(DID1, P2);
    assertEquals(P2, port2.number());
    assertFalse("Port is disabled", port2.isEnabled());

    Port port3 = deviceStore.getPort(DID1, P3);
    assertNull("P3 not expected", port3);
  }
Esempio n. 7
0
 // Creates a port description from the specified port.
 private PortDescription description(Port p) {
   return new DefaultPortDescription(p.number(), p.isEnabled(), p.type(), p.portSpeed());
 }
 private void processPortRemoved(Device device, Port port) {
   // TODO: Remove flow rules for the VM removed
   log.debug("port {} is removed", port.toString());
 }
 @Override
 public OpenstackPort port(Port port) {
   Collection<OpenstackPort> ports = restHandler.getPorts();
   String uuid = port.annotations().value("portName").substring(3);
   return ports.stream().filter(p -> p.id().startsWith(uuid)).findFirst().orElse(null);
 }
Esempio n. 10
0
 /**
  * Returns port name.
  *
  * @param port port
  * @return port name
  */
 private String getPortName(Port port) {
   return port.annotations().value("portName");
 }
Esempio n. 11
0
 @Override
 public int compare(Port p1, Port p2) {
   long delta = p1.number().toLong() - p2.number().toLong();
   return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
 }
Esempio n. 12
0
 @Override
 public boolean is(Port port) {
   return port != null && port.type() == Port.Type.OCH && super.is(port);
 }
Esempio n. 13
0
  // Parses the given node with port information.
  private PortDescription parsePort(DeviceId deviceId, JsonNode node) {
    Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER"));
    // TL1-based ports have a name
    PortNumber port = null;
    if (node.has("name")) {
      for (Port p : deviceService.getPorts(deviceId)) {
        if (p.number().name().equals(node.get("name").asText())) {
          port = p.number();
          break;
        }
      }
    } else {
      port = portNumber(node.path("port").asLong(0));
    }

    if (port == null) {
      log.error("Cannot find port given in node {}", node);
      return null;
    }

    String portName = Strings.emptyToNull(port.name());
    SparseAnnotations annotations = null;
    if (portName != null) {
      annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portName).build();
    }
    switch (type) {
      case COPPER:
        return new DefaultPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            type,
            node.path("speed").asLong(1_000),
            annotations);
      case FIBER:
        // Currently, assume OMS when FIBER. Provide sane defaults.
        annotations = annotations(node.get("annotations"));
        return new OmsPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            CENTER,
            CENTER.add(TOTAL),
            Frequency.ofGHz(100),
            annotations);
      case ODUCLT:
        annotations = annotations(node.get("annotations"));
        OduCltPort oduCltPort = (OduCltPort) deviceService.getPort(deviceId, port);
        return new OduCltPortDescription(
            port, node.path("enabled").asBoolean(true), oduCltPort.signalType(), annotations);
      case OCH:
        annotations = annotations(node.get("annotations"));
        OchPort ochPort = (OchPort) deviceService.getPort(deviceId, port);
        return new OchPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            ochPort.signalType(),
            ochPort.isTunable(),
            ochPort.lambda(),
            annotations);
      case OMS:
        annotations = annotations(node.get("annotations"));
        OmsPort omsPort = (OmsPort) deviceService.getPort(deviceId, port);
        return new OmsPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            omsPort.minFrequency(),
            omsPort.maxFrequency(),
            omsPort.grid(),
            annotations);
      default:
        log.warn("{}: Unsupported Port Type");
    }
    return new DefaultPortDescription(
        port,
        node.path("enabled").asBoolean(true),
        type,
        node.path("speed").asLong(1_000),
        annotations);
  }