コード例 #1
0
ファイル: VideoFilter.java プロジェクト: sandervrijders/ODS
  @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;
  }
コード例 #2
0
 private void displayBellmanFord(
     Host src,
     HashMap<String, String> predecessors,
     HashMap<String, Integer> fwdingToSrcPorts,
     HashMap<String, Integer> distances) {
   try {
     System.out.println(
         "\nBELLMAN FORD : src : "
             + src.getName()
             + " "
             + IPv4.fromIPv4Address(src.getIPv4Address()));
     System.out.print("Predecessors : ");
     for (Entry<String, String> predMapEntry : predecessors.entrySet()) {
       System.out.print("(" + predMapEntry.getKey() + "," + predMapEntry.getValue() + ") ");
     }
     System.out.println();
     System.out.print("FwdPorts : ");
     for (Entry<String, Integer> mapEntry : fwdingToSrcPorts.entrySet()) {
       System.out.print("(" + mapEntry.getKey() + "," + mapEntry.getValue() + ") ");
     }
     System.out.println();
     System.out.print("Distances : ");
     for (Entry<String, Integer> mapEntry : distances.entrySet()) {
       System.out.print("(" + mapEntry.getKey() + "," + mapEntry.getValue() + ") ");
     }
     System.out.println();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
ファイル: CounterStore.java プロジェクト: leihnwong/lazyctrl
  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;
  }
  @Override
  public void startUp(FloodlightModuleContext context) {
    floodlightProvider.addOFSwitchListener(this);
    Map<String, String> configOptions = context.getConfigParams(this);

    try {
      ROOT_NODE_ROOT_OVS_DPID = configOptions.get("root-node-root-ovs-dpid");
      ROOT_NODE_WIFI_OVS_DPID = configOptions.get("root-node-wifi-ovs-dpid");

      ROOT_NODE_WIMAX_OVS_DPID = configOptions.get("root-node-wimax-ovs-dpid");
      WIFI_NODE_WIFI_OVS_DPID = configOptions.get("wifi-node-wifi-ovs-dpid");
      WIFI_NODE_TUNNEL_OVS_DPID = configOptions.get("wifi-node-tunnel-ovs-dpid");
      ROOT_NODE_ROOT_OVS_IP = IPv4.toIPv4Address(configOptions.get("root-node-root-ovs-ip"));
      ROOT_NODE_WIFI_OVS_PATCH =
          Short.parseShort(configOptions.get("root-node-wifi-ovs-patch-port"));
      ROOT_NODE_WIFI_OVS_TUNNEL =
          Short.parseShort(configOptions.get("root-node-wifi-ovs-tunnel-port"));
      ROOT_NODE_WIMAX_OVS_PATCH =
          Short.parseShort(configOptions.get("root-node-wimax-ovs-patch-port"));
      ROOT_NODE_WIMAX_OVS_VLAN =
          Short.parseShort(configOptions.get("root-node-wimax-ovs-vlan-port"));
      ROOT_NODE_ROOT_OVS_WIFI_PATCH =
          Short.parseShort(configOptions.get("root-node-root-ovs-wifi-patch-port"));
      ROOT_NODE_ROOT_OVS_WIMAX_PATCH =
          Short.parseShort(configOptions.get("root-node-root-ovs-wimax-patch-port"));
      WIFI_NODE_WIFI_OVS_PATCH =
          Short.parseShort(configOptions.get("wifi-node-wifi-ovs-patch-port"));
      WIFI_NODE_TUNNEL_OVS_TUNNEL =
          Short.parseShort(configOptions.get("wifi-node-tunnel-ovs-tunnel-port"));
      WIFI_NODE_TUNNEL_OVS_PATCH =
          Short.parseShort(configOptions.get("wifi-node-tunnel-ovs-patch-port"));
    } catch (IllegalArgumentException ex) {
      log.error("Incorrect DHCP Switch Flow Setter configuration options (illegal arg)", ex);
      throw ex;
    } catch (NullPointerException ex) {
      log.error("Incorrect DHCP Switch Flow Setter configuration options (null ptr)", ex);
      throw ex;
    }
  }
コード例 #5
0
  public void doSetUp(HARole role) throws Exception {
    super.setUp();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    FloodlightProvider cm = new FloodlightProvider();

    fmc.addConfigParam(cm, "role", role.toString());
    controller = (Controller) cm.getServiceImpls().get(IFloodlightProviderService.class);
    fmc.addService(IFloodlightProviderService.class, controller);

    MemoryStorageSource memstorage = new MemoryStorageSource();
    fmc.addService(IStorageSourceService.class, memstorage);

    RestApiServer restApi = new RestApiServer();
    fmc.addService(IRestApiService.class, restApi);

    ThreadPool threadPool = new ThreadPool();
    fmc.addService(IThreadPoolService.class, threadPool);

    MockSwitchManager switchService = new MockSwitchManager();
    fmc.addService(IOFSwitchService.class, switchService);

    PktInProcessingTime ppt = new PktInProcessingTime();
    fmc.addService(IPktInProcessingTimeService.class, ppt);

    // TODO: should mock IDebugCounterService and make sure
    // the expected counters are updated.
    DebugCounterServiceImpl debugCounterService = new DebugCounterServiceImpl();
    fmc.addService(IDebugCounterService.class, debugCounterService);

    DebugEventService debugEventService = new DebugEventService();
    fmc.addService(IDebugEventService.class, debugEventService);

    IShutdownService shutdownService = createMock(IShutdownService.class);
    shutdownService.registerShutdownListener(anyObject(IShutdownListener.class));
    expectLastCall().anyTimes();
    replay(shutdownService);
    fmc.addService(IShutdownService.class, shutdownService);
    verify(shutdownService);

    tp = new MockThreadPoolService();
    fmc.addService(IThreadPoolService.class, tp);

    syncService = new MockSyncService();
    fmc.addService(ISyncService.class, syncService);

    ppt.init(fmc);
    restApi.init(fmc);
    threadPool.init(fmc);
    memstorage.init(fmc);
    tp.init(fmc);
    debugCounterService.init(fmc);
    debugEventService.init(fmc);
    syncService.init(fmc);
    cm.init(fmc);

    ppt.startUp(fmc);
    restApi.startUp(fmc);
    threadPool.startUp(fmc);
    memstorage.startUp(fmc);
    tp.startUp(fmc);
    debugCounterService.startUp(fmc);
    debugEventService.startUp(fmc);
    syncService.startUp(fmc);
    cm.startUp(fmc);

    testPacket =
        new Ethernet()
            .setSourceMACAddress("00:44:33:22:11:00")
            .setDestinationMACAddress("00:11:22:33:44:55")
            .setEtherType(EthType.ARP)
            .setPayload(
                new ARP()
                    .setHardwareType(ARP.HW_TYPE_ETHERNET)
                    .setProtocolType(ARP.PROTO_TYPE_IP)
                    .setHardwareAddressLength((byte) 6)
                    .setProtocolAddressLength((byte) 4)
                    .setOpCode(ARP.OP_REPLY)
                    .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:00"))
                    .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))
                    .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))
                    .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));
    byte[] testPacketSerialized = testPacket.serialize();

    // The specific factory can be obtained from the switch, but we don't have one
    pi =
        (OFPacketIn)
            factory
                .buildPacketIn()
                .setBufferId(OFBufferId.NO_BUFFER)
                .setInPort(OFPort.of(1))
                .setData(testPacketSerialized)
                .setReason(OFPacketInReason.NO_MATCH)
                .setTotalLen(testPacketSerialized.length)
                .build();
  }
コード例 #6
0
ファイル: CounterStore.java プロジェクト: leihnwong/lazyctrl
  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);
  }