示例#1
0
  @Override
  public net.floodlightcontroller.core.IListener.Command receive(
      IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {

    if (msg.getType() == OFType.PACKET_IN) {
      OFPacketIn pi = (OFPacketIn) msg;
      Ethernet eth =
          IFloodlightProviderService.bcStore.get(
              cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
      Short type = eth.getEtherType();

      if (type == Ethernet.TYPE_IPv4) {
        IPv4 ippacket = (IPv4) eth.getPayload();
        log.info("New IPv4 message found. \n  {} \n", eth.toString());

        // For debugging purposes in mininet only
        if (ippacket.getProtocol() == IPv4.PROTOCOL_ICMP) {

          // ICMP icmp = (ICMP)ippacket.getPayload();
          log.info("New ICMP message found. \n  {} \n", ippacket.toString());

          // TODO: Call doForwardFlow with the calculated weights
          // change doForwardFlow args...
          // doForwardFlow(sw, pi, cntx);
        }
      }
    }
    return Command.CONTINUE;
  }
  protected Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {

    // get the packet-in switch.
    Ethernet eth =
        IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);

    if (eth.getEtherType() == Ethernet.TYPE_BSN) {
      BSN bsn = (BSN) eth.getPayload();
      if (bsn == null) return Command.STOP;
      if (bsn.getPayload() == null) return Command.STOP;

      // It could be a packet other than BSN LLDP, therefore
      // continue with the regular processing.
      if (bsn.getPayload() instanceof LLDP == false) return Command.CONTINUE;

      doFloodBDDP(sw.getId(), pi, cntx);
    } else {
      return dropFilter(sw.getId(), pi, cntx);
    }
    return Command.STOP;
  }
示例#3
0
  protected String getCountersKey(IOFSwitch sw, OFMessage m, Ethernet eth) {
    byte mtype = m.getType().getTypeValue();
    // long swid = sw.getId();
    String swsid = sw.getStringId();
    short port = 0;
    short l3type = 0;
    byte l4type = 0;

    if (eth != null) {
      // Packet in counters
      // Need port and protocol level differentiation
      OFPacketIn packet = (OFPacketIn) m;
      port = packet.getInPort();
      l3type = eth.getEtherType();
      if (l3type == (short) 0x0800) {
        IPv4 ipV4 = (IPv4) eth.getPayload();
        l4type = ipV4.getProtocol();
      }
    }

    /* If possible, find and return counters for this tuple
     *
     * NOTE: this can be converted to a tuple for better performance,
     * for now we are using a string representation as a the key
     */
    String countersKey =
        Byte.toString(mtype)
            + "-"
            + swsid
            + "-"
            + Short.toString(port)
            + "-"
            + Short.toString(l3type)
            + "-"
            + Byte.toString(l4type);
    return countersKey;
  }
示例#4
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);
  }