Exemplo n.º 1
0
  protected List<ICounter> getPktRemoteFMCounters(IOFSwitch sw, OFMessage m) {
    /* If possible, find and return counters for this tuple */
    String countersKey = this.getCountersKey(sw, m, null);
    List<ICounter> counters = this.pktremoteCounters.get(countersKey);
    if (counters != null) {
      return counters;
    }

    /*
     *  Create the required counters
     */
    counters = new ArrayList<ICounter>();

    /* String values for names */
    String switchIdHex = sw.getStringId();
    String packetName = m.getType().toClass().getName();
    packetName = packetName.substring(packetName.lastIndexOf('.') + 1);

    String controllerFMCounterName =
        CounterStore.createCounterName(CONTROLLER_NAME, -1, packetName);
    counters.add(createCounter(controllerFMCounterName, CounterValue.CounterType.LONG));

    String switchFMCounterName = CounterStore.createCounterName(switchIdHex, -1, packetName);
    counters.add(createCounter(switchFMCounterName, CounterValue.CounterType.LONG));

    /* Add to map and return */
    this.pktremoteCounters.putIfAbsent(countersKey, counters);
    return this.pktremoteCounters.get(countersKey);
  }
Exemplo n.º 2
0
  protected List<ICounter> getPacketInCounters(IOFSwitch sw, OFMessage m, Ethernet eth) {
    /* If possible, find and return counters for this tuple */
    String countersKey = this.getCountersKey(sw, m, eth);
    List<ICounter> counters = this.pktinCounters.get(countersKey);
    if (counters != null) {
      return counters;
    }

    /*
     *  Create the required counters
     */
    counters = new ArrayList<ICounter>();

    /* values for names */
    short port = ((OFPacketIn) m).getInPort();
    short l3type = eth.getEtherType();
    String switchIdHex = sw.getStringId();
    String etherType = String.format("%04x", eth.getEtherType());
    String packetName = m.getType().toClass().getName();
    packetName = packetName.substring(packetName.lastIndexOf('.') + 1);

    // L2 Type
    String l2Type = null;
    if (eth.isBroadcast()) {
      l2Type = BROADCAST;
    } else if (eth.isMulticast()) {
      l2Type = MULTICAST;
    } else {
      l2Type = UNICAST;
    }

    /*
     * Use alias for L3 type
     * Valid EtherType must be greater than or equal to 0x0600
     * It is V1 Ethernet Frame if EtherType < 0x0600
     */
    if (l3type < 0x0600) {
      etherType = "0599";
    }
    if (TypeAliases.l3TypeAliasMap != null && TypeAliases.l3TypeAliasMap.containsKey(etherType)) {
      etherType = TypeAliases.l3TypeAliasMap.get(etherType);
    } else {
      etherType = "L3_" + etherType;
    }

    // overall controller packet counter names
    String controllerCounterName = CounterStore.createCounterName(CONTROLLER_NAME, -1, packetName);
    counters.add(createCounter(controllerCounterName, CounterType.LONG));

    String switchCounterName = CounterStore.createCounterName(switchIdHex, -1, packetName);
    counters.add(createCounter(switchCounterName, CounterType.LONG));

    String portCounterName = CounterStore.createCounterName(switchIdHex, port, packetName);
    counters.add(createCounter(portCounterName, CounterType.LONG));

    // L2 counter names
    String controllerL2CategoryCounterName =
        CounterStore.createCounterName(CONTROLLER_NAME, -1, packetName, l2Type, NetworkLayer.L2);
    counters.add(createCounter(controllerL2CategoryCounterName, CounterType.LONG));

    String switchL2CategoryCounterName =
        CounterStore.createCounterName(switchIdHex, -1, packetName, l2Type, NetworkLayer.L2);
    counters.add(createCounter(switchL2CategoryCounterName, CounterType.LONG));

    String portL2CategoryCounterName =
        CounterStore.createCounterName(switchIdHex, port, packetName, l2Type, NetworkLayer.L2);
    counters.add(createCounter(portL2CategoryCounterName, CounterType.LONG));

    // L3 counter names
    String controllerL3CategoryCounterName =
        CounterStore.createCounterName(CONTROLLER_NAME, -1, packetName, etherType, NetworkLayer.L3);
    counters.add(createCounter(controllerL3CategoryCounterName, CounterType.LONG));

    String switchL3CategoryCounterName =
        CounterStore.createCounterName(switchIdHex, -1, packetName, etherType, NetworkLayer.L3);
    counters.add(createCounter(switchL3CategoryCounterName, CounterType.LONG));

    String portL3CategoryCounterName =
        CounterStore.createCounterName(switchIdHex, port, packetName, etherType, NetworkLayer.L3);
    counters.add(createCounter(portL3CategoryCounterName, CounterType.LONG));

    // L4 counters
    if (l3type == (short) 0x0800) {

      // resolve protocol alias
      IPv4 ipV4 = (IPv4) eth.getPayload();
      String l4name = String.format("%02x", ipV4.getProtocol());
      if (TypeAliases.l4TypeAliasMap != null && TypeAliases.l4TypeAliasMap.containsKey(l4name)) {
        l4name = TypeAliases.l4TypeAliasMap.get(l4name);
      } else {
        l4name = "L4_" + l4name;
      }

      // create counters
      String controllerL4CategoryCounterName =
          CounterStore.createCounterName(CONTROLLER_NAME, -1, packetName, l4name, NetworkLayer.L4);
      counters.add(createCounter(controllerL4CategoryCounterName, CounterType.LONG));

      String switchL4CategoryCounterName =
          CounterStore.createCounterName(switchIdHex, -1, packetName, l4name, NetworkLayer.L4);
      counters.add(createCounter(switchL4CategoryCounterName, CounterType.LONG));

      String portL4CategoryCounterName =
          CounterStore.createCounterName(switchIdHex, port, packetName, l4name, NetworkLayer.L4);
      counters.add(createCounter(portL4CategoryCounterName, CounterType.LONG));
    }

    /* Add to map and return */
    this.pktinCounters.putIfAbsent(countersKey, counters);
    return this.pktinCounters.get(countersKey);
  }