From 99f9ca3ba7ed73625376c03f99344eeb7aa71a07 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 13:19:16 -0500 Subject: [PATCH 001/171] add csi_sep element --- elements/ip/csisep.cc | 63 ++++++++++++++++++++++++++++++ elements/ip/csisep.hh | 91 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100755 elements/ip/csisep.cc create mode 100755 elements/ip/csisep.hh diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc new file mode 100755 index 0000000000..7166e814d3 --- /dev/null +++ b/elements/ip/csisep.cc @@ -0,0 +1,63 @@ +// -*- c-basic-offset: 4 -*- +/* + * ipfragmenter.{cc,hh} -- element fragments IP packets + * Robert Morris, Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2002 International Computer Science Institute + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "csisep.hh" +#include +#include +#include +#include +CLICK_DECLS + +CSISep::CSISep() +{ +} + +CSISep::~CSISep() +{ +} + + +void +CSISep::fragment(Packet *p_in) +{ + Packet *first_fragment = p_in->clone(); + WritablePacket *p_master = first_fragment->uniqueify(); + p_master->take(CSI_LEN); + output(0).push(p_master); + + WritablePacket *p_csi = Packet::make(CSI_LEN); + memcpy(p_csi, p_in+(p_in->length()-CSI_LEN), CSI_LEN); + + if (noutputs() == 2) + output(1).push(p_csi); + else + p_csi->kill(); +} + +void +CSISep::push(int, Packet *p) +{ + fragment(p); +} + + +CLICK_ENDDECLS +EXPORT_ELEMENT(CSISep) +ELEMENT_MT_SAFE(CSISep) diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh new file mode 100755 index 0000000000..bc3dee21a6 --- /dev/null +++ b/elements/ip/csisep.hh @@ -0,0 +1,91 @@ +#ifndef CLICK_CSISEP_HH +#define CLICK_CSISEP_HH +#include +#include +#include +CLICK_DECLS + +/* + * =c + * IPFragmenter(MTU, [I HONOR_DF, VERBOSE]) + * =s ip + * fragments large IP packets + * =d + * + * Expects IP packets as input. If the IP packet size is <= MTU, just emits + * the packet on output 0. If the size is greater than MTU and the + * don't-fragment bit (DF) isn't set, IPFragmenter splits the packet into + * fragments emitted on output 0. If DF is set and the packet size is greater + * than MTU, sends the packet to output 1 (but see HONOR_DF below). Ordinarily + * output 1 is connected to an ICMPError element with type 3 (UNREACH) and + * code 4 (NEEDFRAG). + * + * Copies all annotations to the fragments. + * + * Sends the fragments in order, starting with the first. + * + * It is best to Strip() the MAC header from a packet before sending it to + * IPFragmenter, since any MAC header is not copied to second and subsequent + * fragments. + * + * Keyword arguments are: + * + * =over 8 + * + * =item HONOR_DF + * + * Boolean. If HONOR_DF is false, IPFragmenter will ignore the don't-fragment + * (DF) bit and fragment every packet larger than MTU. Default is true. + * + * =item VERBOSE + * + * Boolean. If true, IPFragmenter will print a message every time it sees a + * packet with DF; otherwise, it will print a message only the first 5 times. + * Default is false. + * + * =item HEADROOM + * + * Unsigned. Sets the headroom on the output packets to an explicit value, + * rather than the default (which is usually about 28 bytes). + * + * =e + * ... -> fr::IPFragmenter(1024) -> Queue(20) -> ... + * fr[1] -> ICMPError(18.26.4.24, 3, 4) -> ... + * + * =a ICMPError, CheckLength + */ + +class CSISep : public Element { public: + + CSISep() CLICK_COLD; + ~CSISep() CLICK_COLD; + + const char *class_name() const { return "CSISep"; } + const char *port_count() const { return PORTS_1_1X2; } + const char *processing() const { return PUSH; } + // int configure(Vector &, ErrorHandler *) CLICK_COLD; + + //uint32_t drops() const { return _drops; } + //uint32_t fragments() const { return _fragments; } + + // void add_handlers() CLICK_COLD; + + void push(int, Packet *); + + private: + + // bool _honor_df; + // bool _verbose; + // unsigned _mtu; + // unsigned _headroom; + // atomic_uint32_t _drops; + // atomic_uint32_t _fragments; + static const uint32_t CSI_LEN = 280; + + void fragment(Packet *); + // int optcopy(const click_ip *ip1, click_ip *ip2); + +}; + +CLICK_ENDDECLS +#endif From c05a6209e454f379b0bc7075d4b93c3169d8bc37 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 14:50:55 -0500 Subject: [PATCH 002/171] finish csi_sep function --- elements/ip/csisep.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 7166e814d3..2fea2a6c78 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -37,18 +37,16 @@ CSISep::~CSISep() void CSISep::fragment(Packet *p_in) { - Packet *first_fragment = p_in->clone(); - WritablePacket *p_master = first_fragment->uniqueify(); + WritablePacket *p_csi = Packet::make(CSI_LEN); + memcpy(p_csi->data(), p_in->end_data()-CSI_LEN, CSI_LEN); + WritablePacket *p_master = p_in->uniqueify(); p_master->take(CSI_LEN); output(0).push(p_master); - - WritablePacket *p_csi = Packet::make(CSI_LEN); - memcpy(p_csi, p_in+(p_in->length()-CSI_LEN), CSI_LEN); - + if (noutputs() == 2) - output(1).push(p_csi); - else - p_csi->kill(); + output(1).push(p_csi); + else + p_csi->kill(); } void From 9c221c801dbeb349dcfa012d10a863413cf95146 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 14:55:48 -0500 Subject: [PATCH 003/171] refine csi_sep --- elements/ip/csisep.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 2fea2a6c78..264b9b7bd0 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -19,7 +19,6 @@ #include #include "csisep.hh" -#include #include #include #include From 3e1545bd1c423a8c2fcaeba190b969554b960399 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 17:00:17 -0500 Subject: [PATCH 004/171] refine deduce and csi_sep --- elements/ip/csisep.hh | 63 -------------- elements/tcpudp/deduptcppacket.cc | 139 +++++++----------------------- elements/tcpudp/deduptcppacket.hh | 51 ++--------- elements/tcpudp/udpipencaptun.cc | 7 +- elements/tcpudp/udpipencaptun.hh | 0 5 files changed, 43 insertions(+), 217 deletions(-) mode change 100644 => 100755 elements/tcpudp/deduptcppacket.cc mode change 100644 => 100755 elements/tcpudp/deduptcppacket.hh mode change 100644 => 100755 elements/tcpudp/udpipencaptun.cc mode change 100644 => 100755 elements/tcpudp/udpipencaptun.hh diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index bc3dee21a6..e78791ba79 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -5,56 +5,6 @@ #include CLICK_DECLS -/* - * =c - * IPFragmenter(MTU, [I HONOR_DF, VERBOSE]) - * =s ip - * fragments large IP packets - * =d - * - * Expects IP packets as input. If the IP packet size is <= MTU, just emits - * the packet on output 0. If the size is greater than MTU and the - * don't-fragment bit (DF) isn't set, IPFragmenter splits the packet into - * fragments emitted on output 0. If DF is set and the packet size is greater - * than MTU, sends the packet to output 1 (but see HONOR_DF below). Ordinarily - * output 1 is connected to an ICMPError element with type 3 (UNREACH) and - * code 4 (NEEDFRAG). - * - * Copies all annotations to the fragments. - * - * Sends the fragments in order, starting with the first. - * - * It is best to Strip() the MAC header from a packet before sending it to - * IPFragmenter, since any MAC header is not copied to second and subsequent - * fragments. - * - * Keyword arguments are: - * - * =over 8 - * - * =item HONOR_DF - * - * Boolean. If HONOR_DF is false, IPFragmenter will ignore the don't-fragment - * (DF) bit and fragment every packet larger than MTU. Default is true. - * - * =item VERBOSE - * - * Boolean. If true, IPFragmenter will print a message every time it sees a - * packet with DF; otherwise, it will print a message only the first 5 times. - * Default is false. - * - * =item HEADROOM - * - * Unsigned. Sets the headroom on the output packets to an explicit value, - * rather than the default (which is usually about 28 bytes). - * - * =e - * ... -> fr::IPFragmenter(1024) -> Queue(20) -> ... - * fr[1] -> ICMPError(18.26.4.24, 3, 4) -> ... - * - * =a ICMPError, CheckLength - */ - class CSISep : public Element { public: CSISep() CLICK_COLD; @@ -63,27 +13,14 @@ class CSISep : public Element { public: const char *class_name() const { return "CSISep"; } const char *port_count() const { return PORTS_1_1X2; } const char *processing() const { return PUSH; } - // int configure(Vector &, ErrorHandler *) CLICK_COLD; - - //uint32_t drops() const { return _drops; } - //uint32_t fragments() const { return _fragments; } - - // void add_handlers() CLICK_COLD; void push(int, Packet *); private: - // bool _honor_df; - // bool _verbose; - // unsigned _mtu; - // unsigned _headroom; - // atomic_uint32_t _drops; - // atomic_uint32_t _fragments; static const uint32_t CSI_LEN = 280; void fragment(Packet *); - // int optcopy(const click_ip *ip1, click_ip *ip2); }; diff --git a/elements/tcpudp/deduptcppacket.cc b/elements/tcpudp/deduptcppacket.cc old mode 100644 new mode 100755 index 973cd95a49..382e0da42d --- a/elements/tcpudp/deduptcppacket.cc +++ b/elements/tcpudp/deduptcppacket.cc @@ -26,9 +26,10 @@ CLICK_DECLS DeDupTCPPacket::DeDupTCPPacket() - : _set(0, 512), _timer(this) { - // sets _timer to call this->run_timer(&_timer) when it fires. + _set.clear(); + while (!_queue.empty()) + _queue.pop(); } DeDupTCPPacket::~DeDupTCPPacket() @@ -36,40 +37,12 @@ DeDupTCPPacket::~DeDupTCPPacket() // Does something need to be here? } -int -DeDupTCPPacket::configure(Vector &conf, ErrorHandler *errh) -{ - return 0; -} -int -DeDupTCPPacket::initialize(ErrorHandler *) -{ - _timer.initialize(this); - _timer.schedule_now(); - return 0; -} - -void -DeDupTCPPacket::cleanup(CleanupStage) -{ - -} - -void -DeDupTCPPacket::run_timer(Timer *timer) -{ - assert(timer == &_timer); - if (_set.size() > 0) { - _set.clear(); - } - _timer.reschedule_after_sec(2); -} Packet * DeDupTCPPacket::drop(Packet *p) { -// click_chatter("TCP: duplicate, dropping"); + //click_chatter("TCP: duplicate, dropping"); if (noutputs() == 2) output(1).push(p); else @@ -78,92 +51,40 @@ DeDupTCPPacket::drop(Packet *p) return 0; } -Packet * -DeDupTCPPacket::simple_action(Packet *p_in) +void +DeDupTCPPacket::push(int port, Packet *p_in) { + // construct link_key WritablePacket *p = p_in->uniqueify(); struct click_ip *iph = p->ip_header(); - struct click_tcp *tcph = p->tcp_header(); - uint64_t key; - unsigned len, iph_len, tcph_len, plen; - click_tcp temp_tcph; - - memcpy(&temp_tcph, tcph, sizeof(struct click_tcp)); - - plen = ntohs(iph->ip_len) - (iph->ip_hl << 2); - if (!p->has_network_header() || iph->ip_p != IP_PROTO_TCP - || !p->has_transport_header() || plen < sizeof(click_tcp) - || plen > (unsigned)p->transport_length()) { - return drop(p); - } - iph_len = iph->ip_hl << 2; - len = ntohs(iph->ip_len) - iph_len; - tcph_len = tcph->th_off << 2; - if (tcph_len < sizeof(click_tcp) || len < tcph_len - || p->length() < len + iph_len + p->network_header_offset()) { - return drop(p); + uint64_t tmp_link_key = ((((uint64_t)(iph->ip_id))&0x000000000000ffff)<<32)+ + (((uint64_t)((iph->ip_src).s_addr))&0x00000000ffffffff); + // printf("key: %lx\n", tmp_link_key); + std::set::iterator it; + it = _set.find(tmp_link_key); + if( it != _set.end()) + { + drop(p); } - - // Deduplication Code here: - - key = build_key(iph, tcph, plen); - - if (_set.get(key) != _set.default_value()) { - // In the table - return drop(p); + else + { + //if (_set.size() >= max_elem_num) + if (_queue.size() >= max_elem_num) + { + // printf("exceed the max size\n"); + uint64_t & link_key_tobe_delete = _queue.front(); + _queue.pop(); + it = _set.find(link_key_tobe_delete); + _set.erase(it); + // delete link_key_tobe_delete; + } + _set.insert(tmp_link_key); + _queue.push(tmp_link_key); } -// click_chatter("TCP: successful"); - - _set.set(key, 1); - // Cleared every 2 seconds by the timer. - - return p; + output(0).push(p); } -uint64_t -DeDupTCPPacket::build_key(struct click_ip *iph, struct click_tcp *tcph, unsigned plen) -{ - uint16_t csum, th_sum; - uint64_t key; - uint16_t temp_sport, temp_sum; - struct in_addr temp_src; - - // Save - memcpy(&temp_src, &(iph->ip_src), sizeof(struct in_addr)); - temp_sport = tcph->th_sport; - temp_sum = tcph->th_sum; - - // Replace - inet_pton(AF_INET, "127.0.0.1", &(iph->ip_src)); - tcph->th_sport = 1234; - tcph->th_sum = 0; - - // Calculate - csum = click_in_cksum((unsigned char *)tcph, plen); - th_sum = click_in_cksum_pseudohdr(csum, iph, plen); - - // Restore - memcpy(&(iph->ip_src), &temp_src, sizeof(struct in_addr)); - tcph->th_sport = temp_sport; - tcph->th_sum = temp_sum; - - key = tcph->th_seq; - key = key << 32; - - key = key | (uint64_t) tcph->th_dport; - key = key << 16; - - key = key | (uint64_t) th_sum; - - return key; -} - -void -DeDupTCPPacket::add_handlers() -{ - -} CLICK_ENDDECLS EXPORT_ELEMENT(DeDupTCPPacket) diff --git a/elements/tcpudp/deduptcppacket.hh b/elements/tcpudp/deduptcppacket.hh old mode 100644 new mode 100755 index 2b31408fb9..2047e71316 --- a/elements/tcpudp/deduptcppacket.hh +++ b/elements/tcpudp/deduptcppacket.hh @@ -2,69 +2,34 @@ #define CLICK_DEDUPTCPPACKET_HH #include #include -#include -#include -CLICK_DECLS - -/* -=c - -DeDupTCPPacket() - -=s tcp - -drops duplicate TCP packets - -=d -Deduplicates TCP packets, if the same one is seen multiple times. +#include +#include -Expects TCP/IP packets as input. Checks that the TCP header length is valid. -Keys each packet on the TCP sequence number, destination port, and -checksum (ignoring source IP or source Port). If the key has been seen before, -the packet is dropped. -Otherwise, the packet is allowed through, and the key is stored for a maximum -of two seconds. The memory usage is reset every two seconds to prevent -memory usage. - -Install with +CLICK_DECLS - make elemlist - make install -=a DedupIPPacket, DedupUDPPacket, CheckTCPHeader, CheckIPHeader, -CheckUDPHeader, MarkIPHeader */ class DeDupTCPPacket : public Element { public: - typedef HashTable Set; - DeDupTCPPacket(); ~DeDupTCPPacket(); const char *class_name() const { return "DeDupTCPPacket"; } const char *port_count() const { return PORTS_1_1X2; } - const char *processing() const { return AGNOSTIC; } + const char *processing() const { return PUSH; } - int configure(Vector &, ErrorHandler *); - void add_handlers(); + void push(int, Packet *); - Packet *simple_action(Packet *); - - int initialize(ErrorHandler *); - void cleanup(CleanupStage); - - void run_timer(Timer *); private: - Set _set; - Timer _timer; + std::set _set; + std::queue _queue; + static const uint16_t max_elem_num = 1000; Packet *drop(Packet *); - uint64_t build_key(struct click_ip *, struct click_tcp *, unsigned); - }; CLICK_ENDDECLS diff --git a/elements/tcpudp/udpipencaptun.cc b/elements/tcpudp/udpipencaptun.cc old mode 100644 new mode 100755 index bb3338f39d..bde25fbace --- a/elements/tcpudp/udpipencaptun.cc +++ b/elements/tcpudp/udpipencaptun.cc @@ -79,7 +79,7 @@ UDPIPEncapTun::run_timer(Timer *timer) inet_ntop(AF_INET, &_daddr, strbuf, INET6_ADDRSTRLEN); - click_chatter("============================== Changing Tunnel Destination: %s", strbuf); + click_chatter("Tunneling through AP address: %s", strbuf); _timer.reschedule_after_sec(1.5); } @@ -190,7 +190,6 @@ UDPIPEncapTun::push(int port, Packet *p_in) if (cmpres != 0) { // If this comes from a different AP _counter++; - // Only change _daddr after we've seen 5 packets that confirm the new // _daddr is closer if (_counter >= 10) { @@ -216,6 +215,7 @@ UDPIPEncapTun::simple_action(Packet *p_in) WritablePacket *p = p_in->push(sizeof(click_udp) + sizeof(click_ip)); struct click_ip *ip = reinterpret_cast(p->data()); struct click_udp *udp = reinterpret_cast(ip + 1); + char strbuf[INET6_ADDRSTRLEN]; #if !HAVE_INDIFFERENT_ALIGNMENT assert((uintptr_t)ip % 4 == 0); @@ -237,6 +237,9 @@ UDPIPEncapTun::simple_action(Packet *p_in) ip->ip_off = 0; ip->ip_ttl = 250; + inet_ntop(AF_INET, &ip->ip_dst, strbuf, INET6_ADDRSTRLEN); + //click_chatter("============================== transmitting to: %s", strbuf); + ip->ip_sum = 0; #if HAVE_FAST_CHECKSUM && FAST_CHECKSUM_ALIGNED if (_aligned) diff --git a/elements/tcpudp/udpipencaptun.hh b/elements/tcpudp/udpipencaptun.hh old mode 100644 new mode 100755 From 0517485b53566b176fc9448b308fbb05e0c68485 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 23:31:39 -0500 Subject: [PATCH 005/171] finish packet selection --- elements/tcpudp/packetselection.cc | 185 +++++++++++++++++++++++++++++ elements/tcpudp/packetselection.hh | 39 ++++++ 2 files changed, 224 insertions(+) create mode 100755 elements/tcpudp/packetselection.cc create mode 100755 elements/tcpudp/packetselection.hh diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc new file mode 100755 index 0000000000..53c7ce2d9a --- /dev/null +++ b/elements/tcpudp/packetselection.cc @@ -0,0 +1,185 @@ +/* + * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header + * Benjie Chen, Eddie Kohler, Hansen Qian + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2007 Regents of the University of California + * Copyright (c) 2016 Princeton University + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "packetselection.hh" +#include +#include +#include +#include + CLICK_DECLS + +PacketSelection::PacketSelection() +{ + int i; + score = new double[n_outport]; + early_counter = new int[n_outport]; + for(i=0; i &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("ALPHA", DoubleArg(), alpha) + .complete() < 0) + return -1; + + return 0; +} + +void +PacketSelection::push(int port, Packet *p_in) +{ + if(port==0) + state_change(p_in); + else + destination_change(p_in); + +} + +int +PacketSelection::bit_convert(int data, int maxbit) +{ + if ( data & (1 << (maxbit - 1))) + { + /* negative */ + data -= (1 << maxbit); + } + return data; +} + +double +PacketSelection::csi_get_score(Packet *p_in) +{ +// ---------- + uint8_t bits_left; + uint32_t bitmask, idx, current_data, h_data; + int real,imag; + uint8_t* csi_addr = (unsigned char *)p_in->data(); + /* init bits_left + * we process 16 bits at a time*/ + bits_left = 16; + + /* according to the h/w, we have 10 bit resolution + * for each real and imag value of the csi matrix H + */ + bitmask = (1 << 10) - 1; + idx = 0; + /* get 16 bits for processing */ + h_data = csi_addr[idx++]; + h_data += (csi_addr[idx++] << 8); + current_data = h_data & ((1 << 16) -1); + + /* bits number less than 10, get next 16 bits */ + if((bits_left - 10) < 0){ + h_data = csi_addr[idx++]; + h_data += (csi_addr[idx++] << 8); + current_data += h_data << bits_left; + bits_left += 16; + } + + imag = current_data & bitmask; + imag = bit_convert(imag, 10); + + bits_left -= 10; + current_data = current_data >> 10; + + /* bits number less than 10, get next 16 bits */ + if((bits_left - 10) < 0){ + h_data = csi_addr[idx++]; + h_data += (csi_addr[idx++] << 8); + current_data += h_data << bits_left; + bits_left += 16; + } + + real = current_data & bitmask; + real = bit_convert(real,10); + return (real^2+imag^2); +} + + + + +void +PacketSelection::state_change(Packet *p_in) +{ + WritablePacket *p = p_in->uniqueify(); + struct click_ip *iph = p->ip_header(); + int router_id; + switch((iph->ip_src).s_addr) + { + case 0x0201a8c0: router_id = 0;break; + case 0x0401a8c0: router_id = 1;break; + case 0x0501a8c0: router_id = 2;break; + } + + + double csi_score = csi_get_score(p); + + + if(early_counter[router_id] kill(); + +} + +void +PacketSelection::destination_change(Packet *p_in) +{ + double tmp_score[n_outport]; + int i, max_id; + double max = -99; + + // mask score before fresh time + for(i=0;imax) + { + max = tmp_score[i]; + max_id = i; + } + } + + output(max_id).push(p_in); +} + +CLICK_ENDDECLS +EXPORT_ELEMENT(PacketSelection) +ELEMENT_MT_SAFE(PacketSelection) diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh new file mode 100755 index 0000000000..f42068ea3d --- /dev/null +++ b/elements/tcpudp/packetselection.hh @@ -0,0 +1,39 @@ +#ifndef CLICK_PACKETSELECTION_HH +#define CLICK_PACKETSELECTION_HH +#include +#include +#include +CLICK_DECLS + + +class PacketSelection : public Element { public: + + + PacketSelection() CLICK_COLD; + ~PacketSelection() CLICK_COLD; + + const char *class_name() const { return "PacketSelection"; } + const char *port_count() const { return "2/3"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *p_in); + + void state_change(Packet *); + void destination_change(Packet *); + double csi_get_score(Packet *); + int bit_convert(int, int); + + private: + double alpha; + double *score; + int *early_counter; + static const int n_outport = 3; + static const int fresh_time = 1000; + + +}; + +CLICK_ENDDECLS +#endif From 389b65dfc6e9518124158fc4af5b0775014a7cfc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 12 Nov 2016 23:36:32 -0500 Subject: [PATCH 006/171] update algorithm --- elements/tcpudp/packetselection.cc | 19 ++++++------------- elements/tcpudp/packetselection.hh | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index 53c7ce2d9a..f8b563ab3d 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -58,8 +58,8 @@ PacketSelection::configure(Vector &conf, ErrorHandler *errh) void PacketSelection::push(int port, Packet *p_in) { - if(port==0) - state_change(p_in); + if(portuniqueify(); struct click_ip *iph = p->ip_header(); - int router_id; - switch((iph->ip_src).s_addr) - { - case 0x0201a8c0: router_id = 0;break; - case 0x0401a8c0: router_id = 1;break; - case 0x0501a8c0: router_id = 2;break; - } double csi_score = csi_get_score(p); - if(early_counter[router_id] kill(); } diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh index f42068ea3d..2c588ecdd8 100755 --- a/elements/tcpudp/packetselection.hh +++ b/elements/tcpudp/packetselection.hh @@ -13,14 +13,14 @@ class PacketSelection : public Element { public: ~PacketSelection() CLICK_COLD; const char *class_name() const { return "PacketSelection"; } - const char *port_count() const { return "2/3"; } + const char *port_count() const { return "4/3"; } const char *flags() const { return "A"; } int configure(Vector &, ErrorHandler *) CLICK_COLD; void push(int port, Packet *p_in); - void state_change(Packet *); + void state_change(int, Packet *); void destination_change(Packet *); double csi_get_score(Packet *); int bit_convert(int, int); From 1ada3d7f299fdd43bc0705c3b6649befc617068a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 13 Nov 2016 16:19:22 -0500 Subject: [PATCH 007/171] use rssi for selection --- elements/ip/csisep.cc | 77 ++++++++++++++++++++++++++---- elements/ip/csisep.hh | 35 ++++++++++++++ elements/tcpudp/packetselection.cc | 22 +++++++-- elements/tcpudp/packetselection.hh | 3 +- 4 files changed, 123 insertions(+), 14 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 264b9b7bd0..af5231c5fb 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -25,27 +25,88 @@ CLICK_DECLS CSISep::CSISep() -{ +{ + csi_status = (csi_struct*)malloc(sizeof(csi_struct)); + + fd = open_csi_device(); + if (fd < 0) + printf("Failed to open the device..."); + else + printf("#Receiving data!\n"); + total_msg_cnt = 0; + } CSISep::~CSISep() { + close_csi_device(fd); + free(csi_status); } + +int CSISep::open_csi_device(){ + int fd; + fd = open("/dev/CSI_dev",O_RDWR); + return fd; +} + +void CSISep::close_csi_device(int fd){ + close(fd); + //remove("/dev/CSI_dev"); +} + + +int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ + int cnt; + /* listen to the port + * read when 1, a csi is reported from kernel + * 2, time out + */ + cnt = read(fd,buf_addr,BUFSIZE); + if(cnt) + return cnt; + else + return 0; +} +void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status){ + csi_status->rssi_0 = buf_addr[20]; + csi_status->rssi_1 = buf_addr[21]; + csi_status->rssi_2 = buf_addr[22]; +} + + + void CSISep::fragment(Packet *p_in) { - WritablePacket *p_csi = Packet::make(CSI_LEN); - memcpy(p_csi->data(), p_in->end_data()-CSI_LEN, CSI_LEN); + + int cnt; + /* keep listening to the kernel and waiting for the csi report */ + cnt = read_csi_buf(buf_addr,fd,4096); + + if (cnt){ + total_msg_cnt += 1; + + /* fill the status struct with information about the rx packet */ + record_status(buf_addr, cnt, csi_status); + + if(total_msg_cnt%100 == 0) + { + printf("rssi : %u %u %u\n", csi_status->rssi_0, csi_status->rssi_1, csi_status->rssi_2); + } + WritablePacket *p_csi = Packet::make(1); + memcpy(p_csi->data(), &(csi_status->rssi_0), 1); + if (noutputs() == 2) + output(1).push(p_csi); + else + p_csi->kill(); + } + WritablePacket *p_master = p_in->uniqueify(); p_master->take(CSI_LEN); output(0).push(p_master); - - if (noutputs() == 2) - output(1).push(p_csi); - else - p_csi->kill(); + } void diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index e78791ba79..2a501e43ff 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -3,8 +3,34 @@ #include #include #include +#include +#include CLICK_DECLS + +typedef struct +{ + int real; + int imag; +}COMPLEX; + +typedef struct +{ + uint64_t tstamp; /* h/w assigned time stamp */ + + uint8_t rssi; /* rx frame RSSI */ + uint8_t rssi_0; /* rx frame RSSI [ctl, chain 0] */ + uint8_t rssi_1; /* rx frame RSSI [ctl, chain 1] */ + uint8_t rssi_2; /* rx frame RSSI [ctl, chain 2] */ + + uint16_t payload_len; /* payload length (bytes) */ + uint16_t csi_len; /* csi data length (bytes) */ + uint16_t buf_len; /* data length in buffer */ +}csi_struct; + + + + class CSISep : public Element { public: CSISep() CLICK_COLD; @@ -15,11 +41,20 @@ class CSISep : public Element { public: const char *processing() const { return PUSH; } void push(int, Packet *); + int open_csi_device(); + void close_csi_device(int fd); + int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); + void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); + private: static const uint32_t CSI_LEN = 280; + csi_struct* csi_status; + int fd; + int total_msg_cnt; + unsigned char buf_addr[4096]; void fragment(Packet *); }; diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index f8b563ab3d..729699adfd 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -23,6 +23,7 @@ #include #include #include +#include CLICK_DECLS PacketSelection::PacketSelection() @@ -35,6 +36,7 @@ PacketSelection::PacketSelection() score[i] = 0; early_counter[i] = 0; } + print_counter = 0; } PacketSelection::~PacketSelection() @@ -76,7 +78,7 @@ PacketSelection::bit_convert(int data, int maxbit) return data; } -double +int PacketSelection::csi_get_score(Packet *p_in) { // ---------- @@ -122,7 +124,7 @@ PacketSelection::csi_get_score(Packet *p_in) real = current_data & bitmask; real = bit_convert(real,10); - return (real^2+imag^2); + return (real*real+imag*imag); } @@ -132,14 +134,21 @@ void PacketSelection::state_change(int port, Packet *p_in) { WritablePacket *p = p_in->uniqueify(); - struct click_ip *iph = p->ip_header(); - double csi_score = csi_get_score(p); - + double csi_score = sqrt(csi_get_score(p)); + print_counter ++; + if(print_counter%100==0) + printf("port: %d, csi_score: %d\n", port, csi_score); if(early_counter[port] kill(); @@ -169,6 +178,9 @@ PacketSelection::destination_change(Packet *p_in) max_id = i; } } + print_counter ++; + if(print_counter%100==0) + printf("choose router id: %d\n", max_id); output(max_id).push(p_in); } diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh index 2c588ecdd8..e5daa2260c 100755 --- a/elements/tcpudp/packetselection.hh +++ b/elements/tcpudp/packetselection.hh @@ -22,12 +22,13 @@ class PacketSelection : public Element { public: void state_change(int, Packet *); void destination_change(Packet *); - double csi_get_score(Packet *); + int csi_get_score(Packet *); int bit_convert(int, int); private: double alpha; double *score; + int print_counter; int *early_counter; static const int n_outport = 3; static const int fresh_time = 1000; From fbbeead41eda63ebf3121da22694c32c0dc66c1d Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 13 Nov 2016 16:59:00 -0500 Subject: [PATCH 008/171] decrease buff size to 25 --- elements/ip/csisep.cc | 2 +- elements/ip/csisep.hh | 2 +- elements/tcpudp/packetselection.cc | 19 +++++++++++-------- elements/tcpudp/packetselection.hh | 1 + 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index af5231c5fb..adaae9ed17 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -83,7 +83,7 @@ CSISep::fragment(Packet *p_in) int cnt; /* keep listening to the kernel and waiting for the csi report */ - cnt = read_csi_buf(buf_addr,fd,4096); + cnt = read_csi_buf(buf_addr,fd,24); if (cnt){ total_msg_cnt += 1; diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 2a501e43ff..eb4ba26403 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -54,7 +54,7 @@ class CSISep : public Element { public: int fd; int total_msg_cnt; - unsigned char buf_addr[4096]; + unsigned char buf_addr[24]; void fragment(Packet *); }; diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index 729699adfd..64520e7970 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -24,6 +24,7 @@ #include #include #include + CLICK_DECLS PacketSelection::PacketSelection() @@ -136,19 +137,21 @@ PacketSelection::state_change(int port, Packet *p_in) WritablePacket *p = p_in->uniqueify(); - double csi_score = sqrt(csi_get_score(p)); + //double csi_score = sqrt(csi_get_score(p)); + uint8_t csi_score; + memcpy(&csi_score, p_in->data(), 1); print_counter ++; - if(print_counter%100==0) + if(print_counter%20==0) printf("port: %d, csi_score: %d\n", port, csi_score); if(early_counter[port] kill(); diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh index e5daa2260c..957e7d43d0 100755 --- a/elements/tcpudp/packetselection.hh +++ b/elements/tcpudp/packetselection.hh @@ -3,6 +3,7 @@ #include #include #include + CLICK_DECLS From eb69d6bc00517d46d14553998de6fe74ebc25eb9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 15:32:30 -0500 Subject: [PATCH 009/171] update packet selection --- elements/tcpudp/packetselection.cc | 79 ++++++++++++++++-------------- elements/tcpudp/packetselection.hh | 12 +++-- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index 64520e7970..db8975665c 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -31,13 +31,17 @@ PacketSelection::PacketSelection() { int i; score = new double[n_outport]; - early_counter = new int[n_outport]; + fresh_counter = 0; + bigger_counter = 0; for(i=0; i &conf, ErrorHandler *errh) { if (Args(conf, this, errh) .read_p("ALPHA", DoubleArg(), alpha) + .read_p("FRESHTIME", IntArg(), fresh_time) + .read_p("BIGGERTIME", IntArg(), bigger_time) + .read_p("FIX", IntArg(), fix) .complete() < 0) return -1; + if(fix >= 0) + { + lock = true; + output_port = fix; + } + return 0; } @@ -141,18 +154,31 @@ PacketSelection::state_change(int port, Packet *p_in) uint8_t csi_score; memcpy(&csi_score, p_in->data(), 1); print_counter ++; - if(print_counter%20==0) - printf("port: %d, csi_score: %d\n", port, csi_score); - - if(early_counter[port] score[0]) + { + if(bigger_counter kill(); } @@ -160,32 +186,11 @@ PacketSelection::state_change(int port, Packet *p_in) void PacketSelection::destination_change(Packet *p_in) { - double tmp_score[n_outport]; - int i, max_id; - double max = -99; - - // mask score before fresh time - for(i=0;imax) - { - max = tmp_score[i]; - max_id = i; - } - } - print_counter ++; - if(print_counter%100==0) - printf("choose router id: %d\n", max_id); + if(print_counter%10==0) + printf("choose router id: %d\n", output_port); - output(max_id).push(p_in); + output(output_port).push(p_in); } CLICK_ENDDECLS diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh index 957e7d43d0..4b5d93890a 100755 --- a/elements/tcpudp/packetselection.hh +++ b/elements/tcpudp/packetselection.hh @@ -30,9 +30,15 @@ class PacketSelection : public Element { public: double alpha; double *score; int print_counter; - int *early_counter; - static const int n_outport = 3; - static const int fresh_time = 1000; + + int n_outport = 3; + int fresh_time; + int fresh_counter; + int bigger_time; + int bigger_counter; + int output_port; + bool lock; + int fix; }; From 39b72c9b4fce0feb77102e92a3201249eca9cf5b Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 19:28:22 -0500 Subject: [PATCH 010/171] csi sep no longer cut packets --- elements/ip/csisep.cc | 24 +++++++++++------------- elements/ip/csisep.hh | 2 +- elements/tcpudp/packetselection.cc | 4 ++-- make.sh | 5 +++++ 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 make.sh diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index adaae9ed17..c9528b884d 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -33,7 +33,7 @@ CSISep::CSISep() printf("Failed to open the device..."); else printf("#Receiving data!\n"); - total_msg_cnt = 0; + // total_msg_cnt = 0; } @@ -83,28 +83,26 @@ CSISep::fragment(Packet *p_in) int cnt; /* keep listening to the kernel and waiting for the csi report */ - cnt = read_csi_buf(buf_addr,fd,24); + cnt = read_csi_buf(buf_addr,fd,23); - if (cnt){ - total_msg_cnt += 1; + if (cnt && noutputs() == 2){ + // total_msg_cnt += 1; /* fill the status struct with information about the rx packet */ record_status(buf_addr, cnt, csi_status); - if(total_msg_cnt%100 == 0) - { - printf("rssi : %u %u %u\n", csi_status->rssi_0, csi_status->rssi_1, csi_status->rssi_2); - } + // if(total_msg_cnt%100 == 0) + // { + // printf("rssi : %u %u %u\n", csi_status->rssi_0, csi_status->rssi_1, csi_status->rssi_2); + // } + WritablePacket *p_csi = Packet::make(1); memcpy(p_csi->data(), &(csi_status->rssi_0), 1); - if (noutputs() == 2) - output(1).push(p_csi); - else - p_csi->kill(); + output(1).push(p_csi); } WritablePacket *p_master = p_in->uniqueify(); - p_master->take(CSI_LEN); + //p_master->take(CSI_LEN); output(0).push(p_master); } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index eb4ba26403..faaab03988 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -52,7 +52,7 @@ class CSISep : public Element { public: static const uint32_t CSI_LEN = 280; csi_struct* csi_status; int fd; - int total_msg_cnt; + // int total_msg_cnt; unsigned char buf_addr[24]; void fragment(Packet *); diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index db8975665c..d8d002febf 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -187,10 +187,10 @@ void PacketSelection::destination_change(Packet *p_in) { + WritablePacket *p_master = p_in->uniqueify(); if(print_counter%10==0) printf("choose router id: %d\n", output_port); - - output(output_port).push(p_in); + output(output_port).push(p_master); } CLICK_ENDDECLS diff --git a/make.sh b/make.sh new file mode 100644 index 0000000000..1f2308a919 --- /dev/null +++ b/make.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo rm ./bin/click +sudo make +sudo make install From 3380ba3b420a893cbae41ee1954a7ea988bf25ef Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 21:18:16 -0500 Subject: [PATCH 011/171] finish & test autocut crisp --- elements/ip/csisep.cc | 40 +++++++++++++++++++++++++++++++++------- elements/ip/csisep.hh | 3 ++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index c9528b884d..367ee687b6 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -33,6 +33,7 @@ CSISep::CSISep() printf("Failed to open the device..."); else printf("#Receiving data!\n"); + // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; } @@ -56,6 +57,16 @@ void CSISep::close_csi_device(int fd){ //remove("/dev/CSI_dev"); } +// bool CSISep::is_big_endian() +// { +// unsigned int a = 0x1; +// unsigned char b = *(unsigned char *)&a; +// if ( b == 0) +// { +// return true; +// } +// return false; +// } int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ int cnt; @@ -86,15 +97,9 @@ CSISep::fragment(Packet *p_in) cnt = read_csi_buf(buf_addr,fd,23); if (cnt && noutputs() == 2){ - // total_msg_cnt += 1; /* fill the status struct with information about the rx packet */ record_status(buf_addr, cnt, csi_status); - - // if(total_msg_cnt%100 == 0) - // { - // printf("rssi : %u %u %u\n", csi_status->rssi_0, csi_status->rssi_1, csi_status->rssi_2); - // } WritablePacket *p_csi = Packet::make(1); memcpy(p_csi->data(), &(csi_status->rssi_0), 1); @@ -102,7 +107,28 @@ CSISep::fragment(Packet *p_in) } WritablePacket *p_master = p_in->uniqueify(); - //p_master->take(CSI_LEN); + struct click_ip *iph = p_master->ip_header(); + //arp + if(!iph) + { + printf("This is an arp pkt.\n"); + printf("Arp len: %d\n", p_master->length()); + if(p_master->length()>CSI_LEN)//if contain CSI + { + p_master->take(CSI_LEN); + } + } + else//ip + { + uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); + printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); + if(ipLenth < p_master->length()-14) + { + printf("CSI appended ip\n"); + p_master->take(CSI_LEN); + } + + } output(0).push(p_master); } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index faaab03988..1675bf9715 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -45,7 +45,7 @@ class CSISep : public Element { public: void close_csi_device(int fd); int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); - + // bool is_big_endian(); private: @@ -56,6 +56,7 @@ class CSISep : public Element { public: unsigned char buf_addr[24]; void fragment(Packet *); + // bool big_endian_flag; }; From 095acca0cc357e5a3f372ac415af397bcff1f661 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 21:27:46 -0500 Subject: [PATCH 012/171] add auto_print --- elements/ip/csisep.cc | 33 +++++++++++++++++++++++++-------- elements/ip/csisep.hh | 3 +++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 367ee687b6..c220b7a3dc 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -30,9 +30,11 @@ CSISep::CSISep() fd = open_csi_device(); if (fd < 0) - printf("Failed to open the device..."); - else - printf("#Receiving data!\n"); + if(print_flag) + printf("Failed to open the device..."); + else + if(print_flag) + printf("#Receiving data!\n"); // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; @@ -44,6 +46,16 @@ CSISep::~CSISep() free(csi_status); } +int +CSISep::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("PRINTFLAG", BoolArg(), print_flag) + .complete() < 0) + return -1; + + return 0; +} int CSISep::open_csi_device(){ @@ -111,8 +123,11 @@ CSISep::fragment(Packet *p_in) //arp if(!iph) { - printf("This is an arp pkt.\n"); - printf("Arp len: %d\n", p_master->length()); + if(print_flag) + { + printf("This is an arp pkt.\n"); + printf("Arp len: %d\n", p_master->length()); + } if(p_master->length()>CSI_LEN)//if contain CSI { p_master->take(CSI_LEN); @@ -121,10 +136,12 @@ CSISep::fragment(Packet *p_in) else//ip { uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); - printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); + if(print_flag) + printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); if(ipLenth < p_master->length()-14) - { - printf("CSI appended ip\n"); + { + if(print_flag) + printf("CSI appended ip\n"); p_master->take(CSI_LEN); } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 1675bf9715..498221a13d 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -40,6 +40,8 @@ class CSISep : public Element { public: const char *port_count() const { return PORTS_1_1X2; } const char *processing() const { return PUSH; } + int configure(Vector &, ErrorHandler *) CLICK_COLD; + void push(int, Packet *); int open_csi_device(); void close_csi_device(int fd); @@ -56,6 +58,7 @@ class CSISep : public Element { public: unsigned char buf_addr[24]; void fragment(Packet *); + bool print_flag; // bool big_endian_flag; }; From 37b2f8faf1e10ebfdbbe6e1d28921e7b68bea42a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 21:55:58 -0500 Subject: [PATCH 013/171] delete the first print and add more --- elements/ip/csisep.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index c220b7a3dc..090e1b18cd 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -30,11 +30,9 @@ CSISep::CSISep() fd = open_csi_device(); if (fd < 0) - if(print_flag) - printf("Failed to open the device..."); + printf("Failed to open the device..."); else - if(print_flag) - printf("#Receiving data!\n"); + printf("#Receiving data!\n"); // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; @@ -103,7 +101,11 @@ void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_sta void CSISep::fragment(Packet *p_in) { - + + if(print_flag) + { + printf("Enter fragment.\n"); + } int cnt; /* keep listening to the kernel and waiting for the csi report */ cnt = read_csi_buf(buf_addr,fd,23); @@ -117,6 +119,10 @@ CSISep::fragment(Packet *p_in) memcpy(p_csi->data(), &(csi_status->rssi_0), 1); output(1).push(p_csi); } + if(print_flag) + { + printf("finish output 1.\n"); + } WritablePacket *p_master = p_in->uniqueify(); struct click_ip *iph = p_master->ip_header(); @@ -132,6 +138,10 @@ CSISep::fragment(Packet *p_in) { p_master->take(CSI_LEN); } + if(print_flag) + { + printf("Finish up.\n"); + } } else//ip { @@ -146,6 +156,10 @@ CSISep::fragment(Packet *p_in) } } + if(print_flag) + { + printf("Finish ip.\n"); + } output(0).push(p_master); } From 4e6089d9f34b2aa788a75584d898d569c2a1d6ec Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 22:18:54 -0500 Subject: [PATCH 014/171] add more print --- elements/ip/csisep.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 090e1b18cd..990d42daf5 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -109,14 +109,32 @@ CSISep::fragment(Packet *p_in) int cnt; /* keep listening to the kernel and waiting for the csi report */ cnt = read_csi_buf(buf_addr,fd,23); - - if (cnt && noutputs() == 2){ + if(print_flag) + { + printf("READ CSI.\n"); + } + if (cnt){ /* fill the status struct with information about the rx packet */ + if(print_flag) + { + printf("before record.\n"); + } record_status(buf_addr, cnt, csi_status); - + if(print_flag) + { + printf("before create.\n"); + } WritablePacket *p_csi = Packet::make(1); + if(print_flag) + { + printf("before copy.\n"); + } memcpy(p_csi->data(), &(csi_status->rssi_0), 1); + if(print_flag) + { + printf("before output 1.\n"); + } output(1).push(p_csi); } if(print_flag) From bd1ac7690c1ffb6d22bcbc50c5f358ce36611e22 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 22:47:09 -0500 Subject: [PATCH 015/171] reduce ip check --- elements/ip/csisep.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 990d42daf5..29082cd319 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -161,19 +161,20 @@ CSISep::fragment(Packet *p_in) printf("Finish up.\n"); } } - else//ip - { - uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); - if(print_flag) - printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); - if(ipLenth < p_master->length()-14) - { - if(print_flag) - printf("CSI appended ip\n"); - p_master->take(CSI_LEN); - } - - } + // no wonder about ip because ip check will do it for you + // else//ip + // { + // uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); + // if(print_flag) + // printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); + // if(ipLenth < p_master->length()-14) + // { + // if(print_flag) + // printf("CSI appended ip\n"); + // p_master->take(CSI_LEN); + // } + + // } if(print_flag) { printf("Finish ip.\n"); From 0baedb27894a40b4e6588d199baf17bfc6e938a9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 23:05:34 -0500 Subject: [PATCH 016/171] comment all print --- elements/ip/csisep.cc | 86 +++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 29082cd319..d6b91f31b5 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -30,9 +30,9 @@ CSISep::CSISep() fd = open_csi_device(); if (fd < 0) - printf("Failed to open the device..."); + // printf("Failed to open the device..."); else - printf("#Receiving data!\n"); + // printf("#Receiving data!\n"); // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; @@ -102,64 +102,64 @@ void CSISep::fragment(Packet *p_in) { - if(print_flag) - { - printf("Enter fragment.\n"); - } + // if(print_flag) + // { + // printf("Enter fragment.\n"); + // } int cnt; /* keep listening to the kernel and waiting for the csi report */ cnt = read_csi_buf(buf_addr,fd,23); - if(print_flag) - { - printf("READ CSI.\n"); - } + // if(print_flag) + // { + // printf("READ CSI.\n"); + // } if (cnt){ /* fill the status struct with information about the rx packet */ - if(print_flag) - { - printf("before record.\n"); - } + // if(print_flag) + // { + // printf("before record.\n"); + // } record_status(buf_addr, cnt, csi_status); - if(print_flag) - { - printf("before create.\n"); - } + // if(print_flag) + // { + // printf("before create.\n"); + // } WritablePacket *p_csi = Packet::make(1); - if(print_flag) - { - printf("before copy.\n"); - } + // if(print_flag) + // { + // printf("before copy.\n"); + // } memcpy(p_csi->data(), &(csi_status->rssi_0), 1); - if(print_flag) - { - printf("before output 1.\n"); - } + // if(print_flag) + // { + // printf("before output 1.\n"); + // } output(1).push(p_csi); } - if(print_flag) - { - printf("finish output 1.\n"); - } + // if(print_flag) + // { + // printf("finish output 1.\n"); + // } WritablePacket *p_master = p_in->uniqueify(); struct click_ip *iph = p_master->ip_header(); //arp if(!iph) { - if(print_flag) - { - printf("This is an arp pkt.\n"); - printf("Arp len: %d\n", p_master->length()); - } + // if(print_flag) + // { + // printf("This is an arp pkt.\n"); + // printf("Arp len: %d\n", p_master->length()); + // } if(p_master->length()>CSI_LEN)//if contain CSI { p_master->take(CSI_LEN); } - if(print_flag) - { - printf("Finish up.\n"); - } + // if(print_flag) + // { + // printf("Finish up.\n"); + // } } // no wonder about ip because ip check will do it for you // else//ip @@ -175,10 +175,10 @@ CSISep::fragment(Packet *p_in) // } // } - if(print_flag) - { - printf("Finish ip.\n"); - } + // if(print_flag) + // { + // printf("Finish ip.\n"); + // } output(0).push(p_master); } From 820232ac4755cbb62a57891b32ad455fbdbd2a78 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 23:12:35 -0500 Subject: [PATCH 017/171] fix a bug --- elements/ip/csisep.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index d6b91f31b5..c425380808 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,9 +29,9 @@ CSISep::CSISep() csi_status = (csi_struct*)malloc(sizeof(csi_struct)); fd = open_csi_device(); - if (fd < 0) + // if (fd < 0) // printf("Failed to open the device..."); - else + // else // printf("#Receiving data!\n"); // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; From 2059ee36f3b64dbe7ecb3b80e8bbfd4029841d77 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 14 Nov 2016 23:28:43 -0500 Subject: [PATCH 018/171] comment refer to iph --- elements/ip/csisep.cc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index c425380808..180f366c51 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -143,24 +143,24 @@ CSISep::fragment(Packet *p_in) // } WritablePacket *p_master = p_in->uniqueify(); - struct click_ip *iph = p_master->ip_header(); - //arp - if(!iph) - { - // if(print_flag) - // { - // printf("This is an arp pkt.\n"); - // printf("Arp len: %d\n", p_master->length()); - // } - if(p_master->length()>CSI_LEN)//if contain CSI - { - p_master->take(CSI_LEN); - } - // if(print_flag) - // { - // printf("Finish up.\n"); - // } - } + // struct click_ip *iph = p_master->ip_header(); + // //arp + // if(!iph) + // { + // // if(print_flag) + // // { + // // printf("This is an arp pkt.\n"); + // // printf("Arp len: %d\n", p_master->length()); + // // } + // if(p_master->length()>CSI_LEN)//if contain CSI + // { + // p_master->take(CSI_LEN); + // } + // // if(print_flag) + // // { + // // printf("Finish up.\n"); + // // } + // } // no wonder about ip because ip check will do it for you // else//ip // { From 77157d0d361484a10438fe1996754dc97092d16e Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 08:49:12 -0500 Subject: [PATCH 019/171] use no mph information --- elements/ip/csisep.cc | 95 ++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 180f366c51..9036a78f8a 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -27,12 +27,12 @@ CLICK_DECLS CSISep::CSISep() { csi_status = (csi_struct*)malloc(sizeof(csi_struct)); - + print_flag = true; fd = open_csi_device(); - // if (fd < 0) - // printf("Failed to open the device..."); - // else - // printf("#Receiving data!\n"); + if (fd < 0) + printf("Failed to open the device..."); + else + printf("#Receiving data!\n"); // big_endian_flag = is_big_endian(); // total_msg_cnt = 0; @@ -137,42 +137,61 @@ CSISep::fragment(Packet *p_in) // } output(1).push(p_csi); } - // if(print_flag) - // { - // printf("finish output 1.\n"); - // } + if(print_flag) + { + printf("finish output 1.\n"); + } WritablePacket *p_master = p_in->uniqueify(); - // struct click_ip *iph = p_master->ip_header(); - // //arp - // if(!iph) - // { - // // if(print_flag) - // // { - // // printf("This is an arp pkt.\n"); - // // printf("Arp len: %d\n", p_master->length()); - // // } - // if(p_master->length()>CSI_LEN)//if contain CSI - // { - // p_master->take(CSI_LEN); - // } - // // if(print_flag) - // // { - // // printf("Finish up.\n"); - // // } - // } + //struct click_ip *iph = p_master->ip_header(); + uint16_t ether_code = *((uint16_t*)(p_master -> data()+12)); + ether_code = (((ether_code)&0xff00)>>8)+(((ether_code)&0x00ff)<<8); + if(print_flag) + { + printf("ether_code: %X.\n", ether_code); + } + + uint16_t ip_length = *((uint16_t*)(p_master -> data()+16)); + ip_length = (((ip_length)&0xff00)>>8)+(((ip_length)&0x00ff)<<8); + if(print_flag) + { + printf("ip_length: %X.\n", ip_length); + } + //arp + if(ether_code == 0x0806) + { + if(print_flag) + { + printf("This is an arp pkt.\n"); + printf("Arp len: %d\n", p_master->length()); + } + if(p_master->length()>CSI_LEN)//if contain CSI + { + p_master->take(CSI_LEN); + } + // if(print_flag) + // { + // printf("Finish up.\n"); + // } + } // no wonder about ip because ip check will do it for you - // else//ip - // { - // uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); - // if(print_flag) - // printf("IP len: %d, real_len: %d\n", ipLenth,p_master->length()-14); - // if(ipLenth < p_master->length()-14) - // { - // if(print_flag) - // printf("CSI appended ip\n"); - // p_master->take(CSI_LEN); - // } + else//ip + { + if(print_flag) + { + printf("This is an ip pkt.\n"); + // printf("IP len: %d\n", p_master->length()); + } + //uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); + if(print_flag) + printf("IP len: %d, real_len: %d\n", ip_length,p_master->length()-14); + if(ip_length < p_master->length()-14) + { + if(print_flag) + printf("CSI appended ip\n"); + p_master->take(CSI_LEN); + } + } // } // if(print_flag) From ad5e8504edbb376a546dad065a54b05589791b7e Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 09:10:10 -0500 Subject: [PATCH 020/171] always print --- elements/ip/csisep.cc | 11 ++++++----- elements/tcpudp/packetselection.cc | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 9036a78f8a..894e8702cf 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,6 +29,7 @@ CSISep::CSISep() csi_status = (csi_struct*)malloc(sizeof(csi_struct)); print_flag = true; fd = open_csi_device(); + prinf("This is a new version"); if (fd < 0) printf("Failed to open the device..."); else @@ -47,10 +48,10 @@ CSISep::~CSISep() int CSISep::configure(Vector &conf, ErrorHandler *errh) { - if (Args(conf, this, errh) - .read_p("PRINTFLAG", BoolArg(), print_flag) - .complete() < 0) - return -1; + // if (Args(conf, this, errh) + // .read_p("PRINTFLAG", BoolArg(), print_flag) + // .complete() < 0) + // return -1; return 0; } @@ -101,7 +102,7 @@ void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_sta void CSISep::fragment(Packet *p_in) { - + print_flag = true; // if(print_flag) // { // printf("Enter fragment.\n"); diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index d8d002febf..412c7ac27e 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -174,7 +174,10 @@ PacketSelection::state_change(int port, Packet *p_in) lock = true; printf("Switching to port 1\n"); } - + } + else + { + bigger_counter = 0; } } From e859fbe35b9ad37c64ed185acb7a74b4350f1271 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 09:11:00 -0500 Subject: [PATCH 021/171] fix a bug --- elements/ip/csisep.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 894e8702cf..2a844baf8e 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,7 +29,7 @@ CSISep::CSISep() csi_status = (csi_struct*)malloc(sizeof(csi_struct)); print_flag = true; fd = open_csi_device(); - prinf("This is a new version"); + printf("This is a new version"); if (fd < 0) printf("Failed to open the device..."); else From 33b51365c3ac904e9347edea4c161b117d24f5bb Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 09:37:36 -0500 Subject: [PATCH 022/171] add support for big/little endian --- elements/ip/csisep.cc | 53 ++++++++++++++++++++++++++----------------- elements/ip/csisep.hh | 4 ++-- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 2a844baf8e..b565911f23 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,12 +29,16 @@ CSISep::CSISep() csi_status = (csi_struct*)malloc(sizeof(csi_struct)); print_flag = true; fd = open_csi_device(); - printf("This is a new version"); + printf("This is a new version\n"); if (fd < 0) - printf("Failed to open the device..."); + printf("Failed to open the device...\n"); else printf("#Receiving data!\n"); - // big_endian_flag = is_big_endian(); + big_endian_flag = is_big_endian(); + if(big_endian_flag) + printf("big endian\n"); + else + printf("little endian\n"); // total_msg_cnt = 0; } @@ -68,16 +72,16 @@ void CSISep::close_csi_device(int fd){ //remove("/dev/CSI_dev"); } -// bool CSISep::is_big_endian() -// { -// unsigned int a = 0x1; -// unsigned char b = *(unsigned char *)&a; -// if ( b == 0) -// { -// return true; -// } -// return false; -// } +bool CSISep::is_big_endian() +{ + unsigned int a = 0x1; + unsigned char b = *(unsigned char *)&a; + if ( b == 0) + { + return true; + } + return false; +} int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ int cnt; @@ -145,19 +149,26 @@ CSISep::fragment(Packet *p_in) WritablePacket *p_master = p_in->uniqueify(); //struct click_ip *iph = p_master->ip_header(); - uint16_t ether_code = *((uint16_t*)(p_master -> data()+12)); - ether_code = (((ether_code)&0xff00)>>8)+(((ether_code)&0x00ff)<<8); - if(print_flag) + uint16_t ether_code, ip_length; + if(big_endian_flag) { - printf("ether_code: %X.\n", ether_code); - } - - uint16_t ip_length = *((uint16_t*)(p_master -> data()+16)); - ip_length = (((ip_length)&0xff00)>>8)+(((ip_length)&0x00ff)<<8); + ether_code= *((uint16_t*)(p_master -> data()+12)); + ip_length = *((uint16_t*)(p_master -> data()+16)); + } + else + { + ether_code= *((uint16_t*)(p_master -> data()+12)); + ether_code = (((ether_code)&0xff00)>>8)+(((ether_code)&0x00ff)<<8); + ip_length = *((uint16_t*)(p_master -> data()+16)); + ip_length = (((ip_length)&0xff00)>>8)+(((ip_length)&0x00ff)<<8); + } if(print_flag) { + printf("ether_code: %X.\n", ether_code); printf("ip_length: %X.\n", ip_length); } + + //arp if(ether_code == 0x0806) { diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 498221a13d..10dd23d3e8 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -47,7 +47,7 @@ class CSISep : public Element { public: void close_csi_device(int fd); int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); - // bool is_big_endian(); + bool is_big_endian(); private: @@ -59,7 +59,7 @@ class CSISep : public Element { public: unsigned char buf_addr[24]; void fragment(Packet *); bool print_flag; - // bool big_endian_flag; + bool big_endian_flag; }; From 30c091feb1fec00c6d0d76d2e2e3ff071f6ec7ff Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 17:37:15 -0500 Subject: [PATCH 023/171] get rssi from iwinfo --- elements/ip/csisep.cc | 116 ++++++++---------------------------------- elements/ip/csisep.hh | 3 ++ 2 files changed, 23 insertions(+), 96 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index b565911f23..e1ec4e39e3 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -39,6 +39,8 @@ CSISep::CSISep() printf("big endian\n"); else printf("little endian\n"); + sprintf(shellcmd,"iwinfo wlan0 info | grep 'Signal'"); + // total_msg_cnt = 0; } @@ -106,110 +108,32 @@ void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_sta void CSISep::fragment(Packet *p_in) { - print_flag = true; - // if(print_flag) - // { - // printf("Enter fragment.\n"); - // } - int cnt; - /* keep listening to the kernel and waiting for the csi report */ - cnt = read_csi_buf(buf_addr,fd,23); - // if(print_flag) - // { - // printf("READ CSI.\n"); - // } - if (cnt){ - - /* fill the status struct with information about the rx packet */ - // if(print_flag) - // { - // printf("before record.\n"); - // } - record_status(buf_addr, cnt, csi_status); - // if(print_flag) - // { - // printf("before create.\n"); - // } - WritablePacket *p_csi = Packet::make(1); - // if(print_flag) - // { - // printf("before copy.\n"); - // } - memcpy(p_csi->data(), &(csi_status->rssi_0), 1); - // if(print_flag) - // { - // printf("before output 1.\n"); - // } - output(1).push(p_csi); - } - if(print_flag) - { - printf("finish output 1.\n"); - } - WritablePacket *p_master = p_in->uniqueify(); - //struct click_ip *iph = p_master->ip_header(); - uint16_t ether_code, ip_length; - if(big_endian_flag) - { - ether_code= *((uint16_t*)(p_master -> data()+12)); - ip_length = *((uint16_t*)(p_master -> data()+16)); + if(NULL == (file = popen(shellcmd,"r"))) + { + printf("execute command failed!"); } else { - ether_code= *((uint16_t*)(p_master -> data()+12)); - ether_code = (((ether_code)&0xff00)>>8)+(((ether_code)&0x00ff)<<8); - ip_length = *((uint16_t*)(p_master -> data()+16)); - ip_length = (((ip_length)&0xff00)>>8)+(((ip_length)&0x00ff)<<8); - } - if(print_flag) - { - printf("ether_code: %X.\n", ether_code); - printf("ip_length: %X.\n", ip_length); - } - - - //arp - if(ether_code == 0x0806) - { - if(print_flag) - { - printf("This is an arp pkt.\n"); - printf("Arp len: %d\n", p_master->length()); - } - if(p_master->length()>CSI_LEN)//if contain CSI - { - p_master->take(CSI_LEN); - } - // if(print_flag) - // { - // printf("Finish up.\n"); - // } - } - // no wonder about ip because ip check will do it for you - else//ip - { - if(print_flag) + fgets(buffer, 100, file); + char * p = strchr(buffer, ':'); + printf("the string buffer: %s\n", p+3); + //char q[50] = "Signal: -54 dBm Link"; + uint16_t length = atoi(p+3); + printf("The Signal length %hu\n", length); + if(length>0) { - printf("This is an ip pkt.\n"); - // printf("IP len: %d\n", p_master->length()); - } - //uint16_t ipLenth = (((iph->ip_len)&0xff00)>>8)+(((iph->ip_len)&0x00ff)<<8); - if(print_flag) - printf("IP len: %d, real_len: %d\n", ip_length,p_master->length()-14); - if(ip_length < p_master->length()-14) - { - if(print_flag) - printf("CSI appended ip\n"); - p_master->take(CSI_LEN); + WritablePacket *p_csi = Packet::make(2); + memcpy(p_csi->data(), &length, 2); + output(1).push(p_csi); } + + } + - // } - // if(print_flag) - // { - // printf("Finish ip.\n"); - // } + WritablePacket *p_master = p_in->uniqueify(); + output(0).push(p_master); } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 10dd23d3e8..1753ef2c43 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -60,6 +60,9 @@ class CSISep : public Element { public: void fragment(Packet *); bool print_flag; bool big_endian_flag; + char shellcmd[64]; + char buffer[100]; + FILE *file; }; From eefd6d58b3bb130d83332b8081ff59af7da19307 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 17:44:56 -0500 Subject: [PATCH 024/171] uint8 data -> uint16 data --- elements/tcpudp/packetselection.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index 412c7ac27e..bea3cbe656 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -151,8 +151,8 @@ PacketSelection::state_change(int port, Packet *p_in) //double csi_score = sqrt(csi_get_score(p)); - uint8_t csi_score; - memcpy(&csi_score, p_in->data(), 1); + uint16_t csi_score; + memcpy(&csi_score, p_in->data(), 2); print_counter ++; if(print_counter%10==0) printf("port: %d, csi_score: %d, output_port: %d\n", port, csi_score, output_port); From 7671e953c5e386197c2c50c4f6d74bc58485a7b3 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 15 Nov 2016 18:07:53 -0500 Subject: [PATCH 025/171] remove print --- elements/ip/csisep.cc | 150 ++++++++++++++++++++---------------------- elements/ip/csisep.hh | 59 +++++++++-------- 2 files changed, 103 insertions(+), 106 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index e1ec4e39e3..ca657eb0ed 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -26,19 +26,19 @@ CLICK_DECLS CSISep::CSISep() { - csi_status = (csi_struct*)malloc(sizeof(csi_struct)); - print_flag = true; - fd = open_csi_device(); - printf("This is a new version\n"); - if (fd < 0) - printf("Failed to open the device...\n"); - else - printf("#Receiving data!\n"); - big_endian_flag = is_big_endian(); - if(big_endian_flag) - printf("big endian\n"); - else - printf("little endian\n"); + // csi_status = (csi_struct*)malloc(sizeof(csi_struct)); + // print_flag = true; + // fd = open_csi_device(); + // printf("This is a new version\n"); + // if (fd < 0) + // printf("Failed to open the device...\n"); + // else + // printf("#Receiving data!\n"); + // big_endian_flag = is_big_endian(); + // if(big_endian_flag) + // printf("big endian\n"); + // else + // printf("little endian\n"); sprintf(shellcmd,"iwinfo wlan0 info | grep 'Signal'"); // total_msg_cnt = 0; @@ -47,61 +47,61 @@ CSISep::CSISep() CSISep::~CSISep() { - close_csi_device(fd); - free(csi_status); + // close_csi_device(fd); + // free(csi_status); } -int -CSISep::configure(Vector &conf, ErrorHandler *errh) -{ - // if (Args(conf, this, errh) - // .read_p("PRINTFLAG", BoolArg(), print_flag) - // .complete() < 0) - // return -1; - - return 0; -} - - -int CSISep::open_csi_device(){ - int fd; - fd = open("/dev/CSI_dev",O_RDWR); - return fd; -} - -void CSISep::close_csi_device(int fd){ - close(fd); - //remove("/dev/CSI_dev"); -} - -bool CSISep::is_big_endian() -{ - unsigned int a = 0x1; - unsigned char b = *(unsigned char *)&a; - if ( b == 0) - { - return true; - } - return false; -} - -int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ - int cnt; - /* listen to the port - * read when 1, a csi is reported from kernel - * 2, time out - */ - cnt = read(fd,buf_addr,BUFSIZE); - if(cnt) - return cnt; - else - return 0; -} -void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status){ - csi_status->rssi_0 = buf_addr[20]; - csi_status->rssi_1 = buf_addr[21]; - csi_status->rssi_2 = buf_addr[22]; -} +// int +// CSISep::configure(Vector &conf, ErrorHandler *errh) +// { +// // if (Args(conf, this, errh) +// // .read_p("PRINTFLAG", BoolArg(), print_flag) +// // .complete() < 0) +// // return -1; + +// return 0; +// } + + +// int CSISep::open_csi_device(){ +// int fd; +// fd = open("/dev/CSI_dev",O_RDWR); +// return fd; +// } + +// void CSISep::close_csi_device(int fd){ +// close(fd); +// //remove("/dev/CSI_dev"); +// } + +// bool CSISep::is_big_endian() +// { +// unsigned int a = 0x1; +// unsigned char b = *(unsigned char *)&a; +// if ( b == 0) +// { +// return true; +// } +// return false; +// } + +// int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ +// int cnt; +// /* listen to the port +// * read when 1, a csi is reported from kernel +// * 2, time out +// */ +// cnt = read(fd,buf_addr,BUFSIZE); +// if(cnt) +// return cnt; +// else +// return 0; +// } +// void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status){ +// csi_status->rssi_0 = buf_addr[20]; +// csi_status->rssi_1 = buf_addr[21]; +// csi_status->rssi_2 = buf_addr[22]; +// } @@ -111,30 +111,26 @@ CSISep::fragment(Packet *p_in) if(NULL == (file = popen(shellcmd,"r"))) { - printf("execute command failed!"); + // printf("execute command failed!"); } else { fgets(buffer, 100, file); char * p = strchr(buffer, ':'); - printf("the string buffer: %s\n", p+3); - //char q[50] = "Signal: -54 dBm Link"; - uint16_t length = atoi(p+3); - printf("The Signal length %hu\n", length); + // printf("the string buffer: %s\n", p+3); + uint8_t length = atoi(p+3); + // printf("The Signal length %hu\n", length); if(length>0) { - WritablePacket *p_csi = Packet::make(2); - memcpy(p_csi->data(), &length, 2); + WritablePacket *p_csi = Packet::make(1); + memcpy(p_csi->data(), &length, 1); output(1).push(p_csi); } } - - WritablePacket *p_master = p_in->uniqueify(); - - output(0).push(p_master); + output(0).push(p_in); } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 1753ef2c43..93dd1137de 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -8,25 +8,25 @@ CLICK_DECLS -typedef struct -{ - int real; - int imag; -}COMPLEX; +// typedef struct +// { +// int real; +// int imag; +// }COMPLEX; -typedef struct -{ - uint64_t tstamp; /* h/w assigned time stamp */ +// typedef struct +// { +// uint64_t tstamp; /* h/w assigned time stamp */ - uint8_t rssi; /* rx frame RSSI */ - uint8_t rssi_0; /* rx frame RSSI [ctl, chain 0] */ - uint8_t rssi_1; /* rx frame RSSI [ctl, chain 1] */ - uint8_t rssi_2; /* rx frame RSSI [ctl, chain 2] */ +// uint8_t rssi; /* rx frame RSSI */ +// uint8_t rssi_0; /* rx frame RSSI [ctl, chain 0] */ +// uint8_t rssi_1; rx frame RSSI [ctl, chain 1] +// uint8_t rssi_2; /* rx frame RSSI [ctl, chain 2] */ - uint16_t payload_len; /* payload length (bytes) */ - uint16_t csi_len; /* csi data length (bytes) */ - uint16_t buf_len; /* data length in buffer */ -}csi_struct; +// uint16_t payload_len; /* payload length (bytes) */ +// uint16_t csi_len; /* csi data length (bytes) */ +// uint16_t buf_len; /* data length in buffer */ +// }csi_struct; @@ -40,26 +40,27 @@ class CSISep : public Element { public: const char *port_count() const { return PORTS_1_1X2; } const char *processing() const { return PUSH; } - int configure(Vector &, ErrorHandler *) CLICK_COLD; + // int configure(Vector &, ErrorHandler *) CLICK_COLD; void push(int, Packet *); - int open_csi_device(); - void close_csi_device(int fd); - int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); - void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); - bool is_big_endian(); + void fragment(Packet *); + // int open_csi_device(); + // void close_csi_device(int fd); + // int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); + // void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); + // bool is_big_endian(); private: - static const uint32_t CSI_LEN = 280; - csi_struct* csi_status; - int fd; + // static const uint32_t CSI_LEN = 280; + // csi_struct* csi_status; + // int fd; // int total_msg_cnt; - unsigned char buf_addr[24]; - void fragment(Packet *); - bool print_flag; - bool big_endian_flag; + // unsigned char buf_addr[24]; + + // bool print_flag; + // bool big_endian_flag; char shellcmd[64]; char buffer[100]; FILE *file; From 11a749497c50fa1d9ee41c641fde1709686fe3f9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 16 Nov 2016 09:53:20 -0500 Subject: [PATCH 026/171] add a sample rate --- elements/ip/csisep.cc | 26 ++++++++++++++++---------- elements/ip/csisep.hh | 4 +++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index ca657eb0ed..fa6e6bf777 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -40,7 +40,7 @@ CSISep::CSISep() // else // printf("little endian\n"); sprintf(shellcmd,"iwinfo wlan0 info | grep 'Signal'"); - + sample_counter = 0; // total_msg_cnt = 0; } @@ -51,16 +51,16 @@ CSISep::~CSISep() // free(csi_status); } -// int -// CSISep::configure(Vector &conf, ErrorHandler *errh) -// { -// // if (Args(conf, this, errh) -// // .read_p("PRINTFLAG", BoolArg(), print_flag) -// // .complete() < 0) -// // return -1; +int +CSISep::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("SAMPLERATE", IntArg(), sample_rate) + .complete() < 0) + return -1; -// return 0; -// } + return 0; +} // int CSISep::open_csi_device(){ @@ -108,6 +108,10 @@ CSISep::~CSISep() void CSISep::fragment(Packet *p_in) { + sample_counter ++; + if(sample_counter>sample_rate) + { + sample_counter = 0; if(NULL == (file = popen(shellcmd,"r"))) { @@ -126,8 +130,10 @@ CSISep::fragment(Packet *p_in) memcpy(p_csi->data(), &length, 1); output(1).push(p_csi); } + pclose(file); + } } output(0).push(p_in); diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 93dd1137de..984b0f13b5 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -40,7 +40,7 @@ class CSISep : public Element { public: const char *port_count() const { return PORTS_1_1X2; } const char *processing() const { return PUSH; } - // int configure(Vector &, ErrorHandler *) CLICK_COLD; + int configure(Vector &, ErrorHandler *) CLICK_COLD; void push(int, Packet *); void fragment(Packet *); @@ -64,6 +64,8 @@ class CSISep : public Element { public: char shellcmd[64]; char buffer[100]; FILE *file; + int sample_rate; + int sample_counter; }; From e1fd7b10f150caa124bc569f10210701feb42fcf Mon Sep 17 00:00:00 2001 From: Zhenyu Date: Thu, 17 Nov 2016 08:43:55 -0500 Subject: [PATCH 027/171] successful rssi --- elements/tcpudp/deduptcppacket.cc | 40 ++++++++++++++++++------------ elements/tcpudp/packetselection.cc | 20 ++++++++++----- elements/tcpudp/packetselection.hh | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/elements/tcpudp/deduptcppacket.cc b/elements/tcpudp/deduptcppacket.cc index 382e0da42d..1a194df383 100755 --- a/elements/tcpudp/deduptcppacket.cc +++ b/elements/tcpudp/deduptcppacket.cc @@ -54,34 +54,42 @@ DeDupTCPPacket::drop(Packet *p) void DeDupTCPPacket::push(int port, Packet *p_in) { + // printf("Packet in\n"); // construct link_key WritablePacket *p = p_in->uniqueify(); struct click_ip *iph = p->ip_header(); + // printf("IP id: %x", iph->ip_id); uint64_t tmp_link_key = ((((uint64_t)(iph->ip_id))&0x000000000000ffff)<<32)+ (((uint64_t)((iph->ip_src).s_addr))&0x00000000ffffffff); - // printf("key: %lx\n", tmp_link_key); + // printf("key: %lx\n", tmp_link_key); std::set::iterator it; it = _set.find(tmp_link_key); - if( it != _set.end()) + if((iph -> ip_id) != 0) { - drop(p); - } - else - { - //if (_set.size() >= max_elem_num) - if (_queue.size() >= max_elem_num) + if( it != _set.end()) + { + // printf("Packet out.drop\n"); + drop(p); + return; + } + else { - // printf("exceed the max size\n"); - uint64_t & link_key_tobe_delete = _queue.front(); - _queue.pop(); - it = _set.find(link_key_tobe_delete); - _set.erase(it); - // delete link_key_tobe_delete; + //if (_set.size() >= max_elem_num) + if (_queue.size() >= max_elem_num) + { + // printf("exceed the max size\n"); + uint64_t & link_key_tobe_delete = _queue.front(); + _queue.pop(); + it = _set.find(link_key_tobe_delete); + _set.erase(it); + // delete link_key_tobe_delete; + } + _set.insert(tmp_link_key); + _queue.push(tmp_link_key); } - _set.insert(tmp_link_key); - _queue.push(tmp_link_key); } + // printf("Packet out.push\n"); output(0).push(p); } diff --git a/elements/tcpudp/packetselection.cc b/elements/tcpudp/packetselection.cc index bea3cbe656..caad8bf629 100755 --- a/elements/tcpudp/packetselection.cc +++ b/elements/tcpudp/packetselection.cc @@ -35,7 +35,7 @@ PacketSelection::PacketSelection() bigger_counter = 0; for(i=0; iuniqueify(); - //double csi_score = sqrt(csi_get_score(p)); + uint16_t csi_score; memcpy(&csi_score, p_in->data(), 2); + //csi_score = ((csi_score&0x00ff)<<8)+((csi_score&0xff00)>>8); print_counter ++; if(print_counter%10==0) - printf("port: %d, csi_score: %d, output_port: %d\n", port, csi_score, output_port); + { + //printf("port: %d, csi_score: %u, output_port: %d\n", port, csi_score, output_port); + //printf("port: %d, csi_score1: %u, output_port: %d\n", port, csi_score1, output_port); + //printf("port: %d, csi_score2: %x, output_port: %d\n", port, csi_score2, output_port); + printf("port: %d, csi_score: %u, hex: %x, output_port: %d\n", port, csi_score, csi_score, output_port); + + + } score[port] = alpha*csi_score + (1-alpha)*score[port]; @@ -164,7 +172,7 @@ PacketSelection::state_change(int port, Packet *p_in) fresh_counter++; else { - if(score[1] > score[0]) + if(score[1] < score[0]) { if(bigger_counteruniqueify(); - if(print_counter%10==0) - printf("choose router id: %d\n", output_port); + //if(print_counter%1000==0) + //printf("choose router id: %d\n", output_port); output(output_port).push(p_master); } diff --git a/elements/tcpudp/packetselection.hh b/elements/tcpudp/packetselection.hh index 4b5d93890a..d9bf0f13fc 100755 --- a/elements/tcpudp/packetselection.hh +++ b/elements/tcpudp/packetselection.hh @@ -31,7 +31,7 @@ class PacketSelection : public Element { public: double *score; int print_counter; - int n_outport = 3; + static const int n_outport = 3; int fresh_time; int fresh_counter; int bigger_time; From 27fb0dbb160b57e05281938f3cdd4defa8017a37 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 19 Nov 2016 20:27:35 -0500 Subject: [PATCH 028/171] the WGTTQueue is ready --- elements/standard/wgttqueue.cc | 231 ++++++++++++++++++++++++++++++++ elements/standard/wgttqueue.hh | 237 +++++++++++++++++++++++++++++++++ 2 files changed, 468 insertions(+) create mode 100644 elements/standard/wgttqueue.cc create mode 100644 elements/standard/wgttqueue.hh diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc new file mode 100644 index 0000000000..f8e175d646 --- /dev/null +++ b/elements/standard/wgttqueue.cc @@ -0,0 +1,231 @@ +// -*- c-basic-offset: 4 -*- +/* + * simplequeue.{cc,hh} -- queue element + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "wgttqueue.hh" +#include +#include +CLICK_DECLS + +WGTTQueue::WGTTQueue() + : _q(0), dequeue_counter(0) +{ +} + +void * +WGTTQueue::cast(const char *n) +{ + if (strcmp(n, "WGTTQueue") == 0) + return (Element *)this; + else + return 0; +} + +int +WGTTQueue::configure(Vector &conf, ErrorHandler *errh) +{ + unsigned new_capacity = 1000; + int tmp_dequeue_time; + if (Args(conf, this, errh) + .read_p("CAPACITY", new_capacity) + .read_p("DEQUEUETIME", tmp_dequeue_time) + .complete() < 0) + return -1; + dequeue_time = tmp_dequeue_time; + _capacity = new_capacity; + return 0; +} + +int +WGTTQueue::initialize(ErrorHandler *errh) +{ + assert(!_q && head() == 0 && tail() == 0); + _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * (_capacity + 1)); + if (_q == 0) + return errh->error("out of memory"); + _drops = 0; + _highwater_length = 0; + return 0; +} + +int +WGTTQueue::live_reconfigure(Vector &conf, ErrorHandler *errh) +{ + // change the maximum queue length at runtime + Storage::index_type old_capacity = _capacity; + // NB: do not call children! + if (WGTTQueue::configure(conf, errh) < 0) + return -1; + if (_capacity == old_capacity || !_q) + return 0; + Storage::index_type new_capacity = _capacity; + _capacity = old_capacity; + + Packet **new_q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * (new_capacity + 1)); + if (new_q == 0) + return errh->error("out of memory"); + + Storage::index_type i, j; + for (i = head(), j = 0; i != tail() && j != new_capacity; i = next_i(i)) + new_q[j++] = _q[i]; + for (; i != tail(); i = next_i(i)) + _q[i]->kill(); + + CLICK_LFREE(_q, sizeof(Packet *) * (_capacity + 1)); + _q = new_q; + set_head(0); + set_tail(j); + _capacity = new_capacity; + return 0; +} + +void +WGTTQueue::take_state(Element *e, ErrorHandler *errh) +{ + WGTTQueue *q = (WGTTQueue *)e->cast("WGTTQueue"); + if (!q) + return; + + if (tail() != head() || head() != 0) { + errh->error("already have packets enqueued, can%,t take state"); + return; + } + + set_head(0); + Storage::index_type i = 0, j = q->head(); + while (i < _capacity && j != q->tail()) { + _q[i] = q->_q[j]; + i++; + j = q->next_i(j); + } + set_tail(i); + _highwater_length = size(); + + if (j != q->tail()) + errh->warning("some packets lost (old length %d, new capacity %d)", + q->size(), _capacity); + while (j != q->tail()) { + q->_q[j]->kill(); + j = q->next_i(j); + } + q->set_head(0); + q->set_tail(0); +} + +void +WGTTQueue::cleanup(CleanupStage) +{ + for (Storage::index_type i = head(); i != tail(); i = next_i(i)) + _q[i]->kill(); + CLICK_LFREE(_q, sizeof(Packet *) * (_capacity + 1)); + _q = 0; +} + +void +WGTTQueue::push(int, Packet *p) +{ + // If you change this code, also change NotifierQueue::push() + // and FullNoteQueue::push(). + Storage::index_type h = head(), t = tail(), nt = next_i(t); + + // should this stuff be in SimpleQueue::enq? + if (nt != h) { + _q[t] = p; + set_tail(nt); + + int s = size(h, nt); + if (s > _highwater_length) + _highwater_length = s; + printf("enque\n"); + + } else { + // if (!(_drops % 100)) + if (_drops == 0 && _capacity > 0) + click_chatter("%p{element}: overflow", this); + _drops++; + printf("overflow\n"); + checked_output_push(1, p); + } +} + +Packet * +WGTTQueue::pull(int) +{ + return deq(); +} + + +String +WGTTQueue::read_handler(Element *e, void *thunk) +{ + WGTTQueue *q = static_cast(e); + int which = reinterpret_cast(thunk); + switch (which) { + case 0: + return String(q->size()); + case 1: + return String(q->highwater_length()); + case 2: + return String(q->capacity()); + case 3: + return String(q->_drops); + default: + return ""; + } +} + +void +WGTTQueue::reset() +{ + while (Packet *p = pull(0)) + checked_output_push(1, p); +} + +int +WGTTQueue::write_handler(const String &, Element *e, void *thunk, ErrorHandler *errh) +{ + WGTTQueue *q = static_cast(e); + int which = reinterpret_cast(thunk); + switch (which) { + case 0: + q->_drops = 0; + q->_highwater_length = q->size(); + return 0; + case 1: + q->reset(); + return 0; + default: + return errh->error("internal error"); + } +} + +void +WGTTQueue::add_handlers() +{ + add_read_handler("length", read_handler, 0); + add_read_handler("highwater_length", read_handler, 1); + add_read_handler("capacity", read_handler, 2, Handler::h_calm); + add_read_handler("drops", read_handler, 3); + add_write_handler("capacity", reconfigure_keyword_handler, "0 CAPACITY"); + add_write_handler("reset_counts", write_handler, 0, Handler::h_button | Handler::h_nonexclusive); + add_write_handler("reset", write_handler, 1, Handler::h_button); +} + +CLICK_ENDDECLS +ELEMENT_PROVIDES(Storage) +EXPORT_ELEMENT(WGTTQueue) diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh new file mode 100644 index 0000000000..9a51eacb16 --- /dev/null +++ b/elements/standard/wgttqueue.hh @@ -0,0 +1,237 @@ +// -*- c-basic-offset: 4 -*- +#ifndef CLICK_WGTTQUEUE_HH +#define CLICK_WGTTQUEUE_HH +#include +#include +CLICK_DECLS + +/* +=c + +SimpleQueue +SimpleQueue(CAPACITY) + +=s storage + +stores packets in a FIFO queue + +=d + +Stores incoming packets in a first-in-first-out queue. +Drops incoming packets if the queue already holds CAPACITY packets. +The default for CAPACITY is 1000. + +B SimpleQueue is designed to be used in an +environment with at most one concurrent pusher and at most one concurrent +puller. Thus, at most one thread pushes to the SimpleQueue at a time and at +most one thread pulls from the SimpleQueue at a time. Different threads can +push to and pull from the SimpleQueue concurrently, however. See +ThreadSafeQueue for a queue that can support multiple concurrent pushers and +pullers. + +=n + +The Queue and NotifierQueue elements act like SimpleQueue, but additionally +notify interested parties when they change state (from nonempty to empty or +vice versa, and/or from nonfull to full or vice versa). + +=h length read-only + +Returns the current number of packets in the queue. + +=h highwater_length read-only + +Returns the maximum number of packets that have ever been in the queue at once. + +=h capacity read/write + +Returns or sets the queue's capacity. + +=h drops read-only + +Returns the number of packets dropped by the queue so far. Dropped packets +are emitted on output 1 if output 1 exists. + +=h reset_counts write-only + +When written, resets the C and C counters. + +=h reset write-only + +When written, drops all packets in the queue. + +=a Queue, NotifierQueue, MixedQueue, RED, FrontDropQueue, ThreadSafeQueue */ + +class WGTTQueue : public Element, public Storage { public: + + WGTTQueue() CLICK_COLD; + + int drops() const { return _drops; } + int highwater_length() const { return _highwater_length; } + + inline bool enq(Packet*); + inline void lifo_enq(Packet*); + inline Packet* deq(); + + // to be used with care + Packet* packet(int i) const { return _q[i]; } + void reset(); // NB: does not do notification + + template Packet* yank1(Filter); + template Packet* yank1_peek(Filter); + template int yank(Filter, Vector &); + + const char *class_name() const { return "WGTTQueue"; } + const char *port_count() const { return PORTS_1_1X2; } + const char *processing() const { return "h/lh"; } + void* cast(const char*); + + int configure(Vector&, ErrorHandler*) CLICK_COLD; + int initialize(ErrorHandler*) CLICK_COLD; + void cleanup(CleanupStage) CLICK_COLD; + bool can_live_reconfigure() const { return true; } + int live_reconfigure(Vector&, ErrorHandler*); + void take_state(Element*, ErrorHandler*); + void add_handlers() CLICK_COLD; + + void push(int port, Packet*); + Packet* pull(int port); + + protected: + + Packet* volatile * _q; + volatile int dequeue_time; + volatile int dequeue_counter; + volatile int _drops; + int _highwater_length; + + friend class MixedQueue; + friend class TokenQueue; + friend class InOrderQueue; + friend class ECNQueue; + + static String read_handler(Element*, void*) CLICK_COLD; + static int write_handler(const String&, Element*, void*, ErrorHandler*) CLICK_COLD; + +}; + + +inline bool +WGTTQueue::enq(Packet *p) +{ + assert(p); + Storage::index_type h = head(), t = tail(), nt = next_i(t); + if (nt != h) { + _q[t] = p; + set_tail(nt); + int s = size(h, nt); + if (s > _highwater_length) + _highwater_length = s; + return true; + } else { + p->kill(); + _drops++; + return false; + } +} + +inline void +WGTTQueue::lifo_enq(Packet *p) +{ + // XXX NB: significantly more dangerous in a multithreaded environment + // than plain (FIFO) enq(). + assert(p); + Storage::index_type h = head(), t = tail(), ph = prev_i(h); + if (ph == t) { + t = prev_i(t); + _q[t]->kill(); + set_tail(t); + } + _q[ph] = p; + set_head_release(ph); +} + +inline Packet * +WGTTQueue::deq() +{ + if(dequeue_counter >= dequeue_time) + return 0; + Storage::index_type h = head(), t = tail(); + if (h != t) { + Packet *p = _q[h]; + set_head(next_i(h)); + assert(p); + dequeue_counter ++; + printf("dequeue success!\n"); + return p; + } else + { + printf("deque function\n"); + return 0; + } +} + +template +Packet * +WGTTQueue::yank1(Filter filter) + /* Remove from the queue and return the first packet that matches + 'filter(Packet *)'. The returned packet must be deallocated by the + caller. */ +{ + for (Storage::index_type trav = head(); trav != tail(); trav = next_i(trav)) + if (filter(_q[trav])) { + Packet *p = _q[trav]; + int prev = prev_i(trav); + while (trav != head()) { + _q[trav] = _q[prev]; + trav = prev; + prev = prev_i(prev); + } + set_head(next_i(head())); + return p; + } + return 0; +} + +template +Packet * +WGTTQueue::yank1_peek(Filter filter) + /* return the first packet that matches + 'filter(Packet *)'. The returned packet must *NOT* be deallocated by the + caller. */ +{ + for (Storage::index_type trav = head(); trav != tail(); trav = next_i(trav)) + if (filter(_q[trav])) { + Packet *p = _q[trav]; + return p; + } + return 0; +} + +template +int +WGTTQueue::yank(Filter filter, Vector &yank_vec) + /* Removes from the queue and adds to 'yank_vec' all packets in the queue + that match 'filter(Packet *)'. Packets are added to 'yank_vec' in LIFO + order, so 'yank_vec.back()' will equal the first packet in the queue + that matched 'filter()'. Caller should deallocate any packets returned + in 'yank_vec'. Returns the number of packets yanked. */ +{ + Storage::index_type write_ptr = tail(); + int nyanked = 0; + for (Storage::index_type trav = tail(); trav != head(); ) { + trav = prev_i(trav); + if (filter(_q[trav])) { + yank_vec.push_back(_q[trav]); + nyanked++; + } else { + write_ptr = prev_i(write_ptr); + _q[write_ptr] = _q[trav]; + } + } + set_head(write_ptr); + return nyanked; +} + +CLICK_ENDDECLS +#endif From 4f0187a4ae595fc9ddd4c9b673a9a940708a1e3f Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 19 Nov 2016 20:38:43 -0500 Subject: [PATCH 029/171] wgttqueue add log --- elements/standard/wgttqueue.cc | 5 +++-- elements/standard/wgttqueue.hh | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index f8e175d646..f09a680191 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -25,6 +25,7 @@ CLICK_DECLS WGTTQueue::WGTTQueue() : _q(0), dequeue_counter(0) { + openlog("MYLOG", LOG_CONS| LOG_NDELAY| LOG_NOWAIT, LOG_KERN); } void * @@ -151,14 +152,14 @@ WGTTQueue::push(int, Packet *p) int s = size(h, nt); if (s > _highwater_length) _highwater_length = s; - printf("enque\n"); + // printf("enque\n"); } else { // if (!(_drops % 100)) if (_drops == 0 && _capacity > 0) click_chatter("%p{element}: overflow", this); _drops++; - printf("overflow\n"); + // printf("overflow\n"); checked_output_push(1, p); } } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 9a51eacb16..ac267c075e 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -3,6 +3,7 @@ #define CLICK_WGTTQUEUE_HH #include #include +#include CLICK_DECLS /* @@ -161,12 +162,17 @@ WGTTQueue::deq() Packet *p = _q[h]; set_head(next_i(h)); assert(p); + if (dequeue_counter = dequeue_time - 1) + { + syslog(LOG_DEBUG, "DEQUEUE DISABLE\n"); + closelog(); + } dequeue_counter ++; - printf("dequeue success!\n"); + return p; } else { - printf("deque function\n"); + // printf("deque function\n"); return 0; } } From 6abc74dc91b777c1201d461ff9c32cc918af792d Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 19 Nov 2016 22:06:03 -0500 Subject: [PATCH 030/171] add log for dequeue threshold --- elements/standard/wgttqueue.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index f09a680191..6308b53556 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -48,6 +48,7 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) .complete() < 0) return -1; dequeue_time = tmp_dequeue_time; + syslog(LOG_DEBUG, "dequeue time: %d\n", dequeue_time); _capacity = new_capacity; return 0; } From 4f92f2261791b5b418cd8f7e487961312c7a0ee9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 19 Nov 2016 22:15:13 -0500 Subject: [PATCH 031/171] debug == --- elements/standard/wgttqueue.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index ac267c075e..602ac35238 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -162,7 +162,7 @@ WGTTQueue::deq() Packet *p = _q[h]; set_head(next_i(h)); assert(p); - if (dequeue_counter = dequeue_time - 1) + if (dequeue_counter == dequeue_time - 1) { syslog(LOG_DEBUG, "DEQUEUE DISABLE\n"); closelog(); From e469843d40b8d2dc700d4ea29800b0276ffd7ae0 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 21 Nov 2016 22:22:13 -0500 Subject: [PATCH 032/171] from wlan0 to wlan1 --- elements/ip/csisep.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index fa6e6bf777..d077246623 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -39,7 +39,7 @@ CSISep::CSISep() // printf("big endian\n"); // else // printf("little endian\n"); - sprintf(shellcmd,"iwinfo wlan0 info | grep 'Signal'"); + sprintf(shellcmd,"iwinfo wlan1 info | grep 'Signal'"); sample_counter = 0; // total_msg_cnt = 0; From 10b3a419a79c6e80f156f4efbc94643f0e0a86ec Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 23 Nov 2016 11:02:27 -0500 Subject: [PATCH 033/171] add a periodic switch --- .../tcpudp/packetselectionPeriodicSwitch.cc | 88 +++++++++++++++++++ .../tcpudp/packetselectionPeriodicSwitch.hh | 39 ++++++++ make.sh | 0 3 files changed, 127 insertions(+) create mode 100755 elements/tcpudp/packetselectionPeriodicSwitch.cc create mode 100755 elements/tcpudp/packetselectionPeriodicSwitch.hh mode change 100644 => 100755 make.sh diff --git a/elements/tcpudp/packetselectionPeriodicSwitch.cc b/elements/tcpudp/packetselectionPeriodicSwitch.cc new file mode 100755 index 0000000000..7aed5aaab8 --- /dev/null +++ b/elements/tcpudp/packetselectionPeriodicSwitch.cc @@ -0,0 +1,88 @@ +/* + * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header + * Benjie Chen, Eddie Kohler, Hansen Qian + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2007 Regents of the University of California + * Copyright (c) 2016 Princeton University + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "packetselectionPeriodicSwitch.hh" +#include +#include +#include +#include +#include + + CLICK_DECLS + +PacketSelectionPeriodicSwitch::PacketSelectionPeriodicSwitch() +{ + output_port = 0; + switch_counter = 0; + switch_flag = 0xff; + +} + +PacketSelectionPeriodicSwitch::~PacketSelectionPeriodicSwitch() +{ + +} + + + +int +PacketSelectionPeriodicSwitch::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("SWITCHTIME", IntArg(), switch_time) + .complete() < 0) + return -1; + + return 0; +} + +void +PacketSelectionPeriodicSwitch::push(int port, Packet *p_in) +{ + if(port kill(); + else + destination_change(p_in); + +} + + +void +PacketSelectionPeriodicSwitch::destination_change(Packet *p_in) +{ + + WritablePacket *p_master = p_in->uniqueify(); + switch_counter ++; + if(switch_counter >= switch_time) + { + switch_counter = 0; + output_port = (output_port + 1)%n_outport; + } + output(output_port).push(p_master); + + WritablePacket *p_switch_flag = Packet::make(1); + memcpy(p_switch_flag->data(), &switch_flag, 1); + output(output_port).push(p_switch_flag); + +} + +CLICK_ENDDECLS +EXPORT_ELEMENT(PacketSelectionPeriodicSwitch) +ELEMENT_MT_SAFE(PacketSelectionPeriodicSwitch) diff --git a/elements/tcpudp/packetselectionPeriodicSwitch.hh b/elements/tcpudp/packetselectionPeriodicSwitch.hh new file mode 100755 index 0000000000..64d77e9671 --- /dev/null +++ b/elements/tcpudp/packetselectionPeriodicSwitch.hh @@ -0,0 +1,39 @@ +#ifndef CLICK_PACKETSELECTIONPERIODICSWITCH_HH +#define CLICK_PACKETSELECTIONPERIODICSWITCH_HH +#include +#include +#include + +CLICK_DECLS + + +class PacketSelectionPeriodicSwitch : public Element { public: + + + PacketSelectionPeriodicSwitch() CLICK_COLD; + ~PacketSelectionPeriodicSwitch() CLICK_COLD; + + const char *class_name() const { return "PacketSelectionPeriodicSwitch"; } + const char *port_count() const { return "4/3"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *p_in); + + void destination_change(Packet *); + + + private: + + static const int n_outport = 2; + int output_port; + int switch_time; + int switch_counter; + unsigned char switch_flag; + + +}; + +CLICK_ENDDECLS +#endif diff --git a/make.sh b/make.sh old mode 100644 new mode 100755 From 48c07516c747f1673991d211e53c6358df418967 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 26 Nov 2016 20:24:09 -0500 Subject: [PATCH 034/171] finish ap_switch --- elements/standard/apswitchserial.cc | 175 ++++++++++++++++++++ elements/standard/apswitchserial.hh | 124 ++++++++++++++ elements/tcpudp/idadder.cc | 61 +++++++ elements/tcpudp/idadder.hh | 53 ++++++ elements/tcpudp/packetselectionSerial.cc | 195 +++++++++++++++++++++++ elements/tcpudp/packetselectionSerial.hh | 73 +++++++++ tcpudp | 1 + 7 files changed, 682 insertions(+) create mode 100644 elements/standard/apswitchserial.cc create mode 100644 elements/standard/apswitchserial.hh create mode 100755 elements/tcpudp/idadder.cc create mode 100755 elements/tcpudp/idadder.hh create mode 100755 elements/tcpudp/packetselectionSerial.cc create mode 100755 elements/tcpudp/packetselectionSerial.hh create mode 120000 tcpudp diff --git a/elements/standard/apswitchserial.cc b/elements/standard/apswitchserial.cc new file mode 100644 index 0000000000..cf4406a97f --- /dev/null +++ b/elements/standard/apswitchserial.cc @@ -0,0 +1,175 @@ +// -*- c-basic-offset: 4 -*- +/* + * simplequeue.{cc,hh} -- queue element + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "apswitchserial.hh" +#include +#include +CLICK_DECLS + +APSwitchSerial::APSwitchSerial() +{ + _q = new Packet*[RING_SIZE]; + _head = 0; + _tail = 0; + _qControl = new Packet*[QUEUE_SIZE]; + _headControl = 0; + _tailControl = 0; +} + +APSwitchSerial::~APSwitchSerial() +{ + +} + + +int +APSwitchSerial::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("IDENTITY", IntArg(), identity) + .complete() < 0) + return -1; + if(identity==1) + _block = false; + else + _block = true; + + + //TODO: checksum not set + memset(&_iph, 0, sizeof(click_ip)); + _iph.ip_v = 4; + _iph.ip_hl = sizeof(click_ip) >> 2; + _iph.ip_ttl = 250; + switch(identity) + { + case 1: _iph.ip_src.s_addr = AP1_IP;break; + case 2: _iph.ip_src.s_addr = AP2_IP;break; + } + _iph.ip_p = 6;//control msg + _iph.ip_tos = 0; + _iph.ip_off = 0; + _iph.ip_sum = 0; + _iph.ip_len = htons(22); + + + _ethh = new click_ether; + + _ethh->ether_type = htons(0x0800); + switch(identity) + { + case 1: cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; + case 2: cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; + } + + return 0; +} + +void +APSwitchSerial::push(int, Packet *p_in) +{ + switch(pkt_type(p_in)) + { + case CONTROL: push_control(p_in);break; + case DATA: push_data(p_in);break; + } +} + + +void APSwitchSerial::push_control(Packet *p_in) +{ + if(ap_id(p_in) == CONTROLLER)//stop + { + _block = true; + const unsigned char & dst_ap_id = start_ap(p_in); + + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 135; + control_content[1] = _head; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + switch(dst_ap_id) + { + case 1: _iph.ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 2: _iph.ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + memcpy(p->data(), _ethh, sizeof(click_ether)); + + enque(p); + printf("ap2ap packet push\n"); + } + else + { + const unsigned char & start_seq = start_seq(p_in); + while(_head != start_seq) + deRing(); + + + + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 135; + control_content[1] = 0; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + _iph.ip_dst.s_addr = CONTROLLER_IP;cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_dhost); + + memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + memcpy(p->data(), _ethh, sizeof(click_ether)); + + enque(p); + printf("ap-c packet push\n"); + _block = false; + + } +} + +void APSwitchSerial::push_data(Packet *p_in) +{ + unsigned char seq = start_seq(p_in); + p_in -> take(1); + while(_tail != seq) + enRing(0); + enRing(p_in); +} + + + + +Packet * +APSwitchSerial::pull(int port) +{ + if(port == 0) + return deRing(); + else + return deque(); +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(APSwitchSerial) +ELEMENT_MT_SAFE(APSwitchSerial) diff --git a/elements/standard/apswitchserial.hh b/elements/standard/apswitchserial.hh new file mode 100644 index 0000000000..b0332a4e96 --- /dev/null +++ b/elements/standard/apswitchserial.hh @@ -0,0 +1,124 @@ +// -*- c-basic-offset: 4 -*- +#ifndef CLICK_APSWITCHSERIAL_HH +#define CLICK_APSWITCHSERIAL_HH +#include +#include +#include +#include +CLICK_DECLS + +#define RING_SIZE 256 +#define QUEUE_SIZE 256 +#define STATUS 4 +#define DATA 17 +#define CONTROL 6 +#define IDLE 0 +#define SWITCH_REQ 1 +#define CLIENT1 135 +#define CONTROLLER 1 +#define AP1 2 +#define AP2 4 +#define IP_BASE 0x01a8c0 +#define AP1_IP 0x0201a8c0 +#define AP2_IP 0x0401a8c0 +#define CONTROLLER_IP 0x0101a8c0 +#define AP1_MAC "C0:56:27:72:A3:5B" +#define AP2_MAC "60:38:E0:03:FA:0B" +#define CONTROLLER_MAC "38:c9:86:40:c8:05" + +#define pkt_type(p) *(p->data()+9) +#define ip_id(p) *(p->data()+20) +#define ap_id(p) *(p->data()+15) +#define start_ap(p) *(p->data()+21) +#define start_seq(p) *(p->data()+21) +#define ap_score(p) *(p->data()+20) + + +class APSwitchSerial : public Element { public: + + APSwitchSerial() CLICK_COLD; + ~APSwitchSerial() CLICK_COLD; + + inline void enRing(Packet*);//flag: whether override + inline Packet* deRing(); + inline void enque(Packet*);//flag: whether override + inline Packet* deque(); + + const char *class_name() const { return "APSwitchSerial"; } + const char *port_count() const { return "1/2"; } + const char *processing() const { return "h/lh"; } + + int configure(Vector&, ErrorHandler*) CLICK_COLD; + + void push(int port, Packet*); + void push_control(Packet *p_in); + void push_data(Packet *p_in); + + Packet* pull(int port); + + private: + + Packet* volatile * _q; + Packet* volatile * _qControl; + volatile unsigned char _head; + volatile unsigned char _tail; + + volatile unsigned char _headControl; + volatile unsigned char _tailControl; + + volatile bool _block; + unsigned char identity; + unsigned char control_content[2]; + + click_ip _iph; + click_ether * _ethh; + +}; + + +inline void +APSwitchSerial::enRing(Packet *p) +{ + if((_tail+1)%RING_SIZE == _head)//override + { + _q[_head] -> kill(); + _head = (_head+1)%RING_SIZE; + } + _q[_tail] = p; + _tail = (_tail+1)%RING_SIZE; +} + +inline Packet * +APSwitchSerial::deRing() +{ + if(_block || _head==_tail) + return 0; + Packet *p = _q[_head]; + _head = (_head+1)%RING_SIZE; + return p; +} + +inline void +APSwitchSerial::enque(Packet *p) +{ + if((_tailControl+1)%QUEUE_SIZE == _headControl)//override + { + _qControl[_headControl] -> kill(); + _headControl = (_headControl+1)%QUEUE_SIZE; + } + _qControl[_tailControl] = p; + _tailControl = (_tailControl+1)%QUEUE_SIZE; +} + +inline Packet * +APSwitchSerial::deque() +{ + if(_headControl==_tailControl) + return 0; + Packet *p = _qControl[_headControl]; + _headControl = (_headControl+1)%QUEUE_SIZE; + return p; +} + +CLICK_ENDDECLS +#endif diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc new file mode 100755 index 0000000000..4f725e1db4 --- /dev/null +++ b/elements/tcpudp/idadder.cc @@ -0,0 +1,61 @@ +/* + * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header + * Benjie Chen, Eddie Kohler, Hansen Qian + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2007 Regents of the University of California + * Copyright (c) 2016 Princeton University + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "idadder.hh" +#include +#include +#include + + + CLICK_DECLS + + + + +IDAdder::IDAdder() +{ + counter = 0; + +} + +IDAdder::~IDAdder() +{ + +} + + +void IDAdder::push(int port, Packet *p_in) +{ + // printf("into idadder\n"); + WritablePacket *p = p_in->put(1); + memcpy(p->end_data()-1, &counter, 1); + counter ++; + printf("Tail: %X\n", *(p->end_data()-1)); + printf("counter: %u\n", counter); + // p_in -> kill(); + output(0).push(p); + +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(IDAdder) +ELEMENT_MT_SAFE(IDAdder) diff --git a/elements/tcpudp/idadder.hh b/elements/tcpudp/idadder.hh new file mode 100755 index 0000000000..02db8f889b --- /dev/null +++ b/elements/tcpudp/idadder.hh @@ -0,0 +1,53 @@ +#ifndef CLICK_IDADDER_HH +#define CLICK_IDADDER_HH +#include +#include +#include + + +CLICK_DECLS + +#define STATUS 4 +#define DATA 17 +#define CONTROL 6 +#define IDLE 0 +#define SWITCH_REQ 1 +#define CLIENT1 135 +#define AP1 2 +#define AP2 4 +#define AP1_IP 0x0201a8c0 +#define AP2_IP 0x0401a8c0 +#define CONTROLLER_IP 0x0101a8c0 +#define AP1_MAC "C0:56:27:72:A3:5B" +#define AP2_MAC "60:38:E0:03:FA:0B" +#define CONTROLLER_MAC "38:c9:86:40:c8:05" + + + +class IDAdder : public Element { public: + + + IDAdder() CLICK_COLD; + ~IDAdder() CLICK_COLD; + + const char *class_name() const { return "IDAdder"; } + const char *port_count() const { return "1/1"; } + const char *flags() const { return "A"; } + + // int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *p_in); + + + private: + + unsigned char counter; + + +}; + + + + +CLICK_ENDDECLS +#endif diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc new file mode 100755 index 0000000000..8d65902579 --- /dev/null +++ b/elements/tcpudp/packetselectionSerial.cc @@ -0,0 +1,195 @@ +/* + * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header + * Benjie Chen, Eddie Kohler, Hansen Qian + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2007 Regents of the University of California + * Copyright (c) 2016 Princeton University + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include "packetselectionSerial.hh" +#include +#include +#include +#include +#include + + CLICK_DECLS + + + + +PacketSelectionSerial::PacketSelectionSerial() +{ + int i,j; + score = new unsigned char*[n_ap]; + next_score_id = new unsigned char[n_ap]; + output_port = new unsigned char[n_client]; + for(i=0; i> 2; + _iph.ip_ttl = 250; + _iph.ip_src.s_addr = CONTROLLER_IP; + _iph.ip_p = 6;//control msg + _iph.ip_tos = 0; + _iph.ip_off = 0; + _iph.ip_sum = 0; + _iph.ip_len = htons(22); + + + + _ethh = new click_ether; + + _ethh->ether_type = htons(0x0800); + bool result = cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_shost); + + +} + +PacketSelectionSerial::~PacketSelectionSerial() +{ + +} + + + +// int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) +// { +// // if (Args(conf, this, errh) +// // .read_p("ALPHA", DoubleArg(), alpha) +// // .read_p("FRESHTIME", IntArg(), fresh_time) +// // .read_p("BIGGERTIME", IntArg(), bigger_time) +// // .read_p("FIX", IntArg(), fix) +// // .complete() < 0) +// // return -1; + + +// return 0; +// } + +void PacketSelectionSerial::push(int port, Packet *p_in) +{ + // printf("pkt_type: %x\n", pkt_type(p_in)); + switch(pkt_type(p_in)) + { + case CONTROL: push_control(p_in);break; + case STATUS: push_status(p_in);break; + } +} + + + +void PacketSelectionSerial::push_control(Packet *p_in) +{ + unsigned char c = 0; + state[c] = IDLE; + //printf("In push control.\n"); + p_in -> kill(); +} + +void PacketSelectionSerial::push_status(Packet *p_in) +{ + printf("In push status.\n"); + unsigned char a; + printf("ap id: %x\n", ap_id(p_in)); + switch(ap_id(p_in)) + { + case AP1: a = 0; break; + case AP2: a = 1; break; + } + // update_score(&ap_score(p_in), &c) + printf("ap score: %x\n", ap_score(p_in)); + printf("next_score_id[a]: %x\n", next_score_id[a]); + score[a][next_score_id[a]] = ap_score(p_in); + next_score_id[a] = (next_score_id[a] + 1)%n_compare; + // able to change state + if(state[0] == IDLE) + { + printf("state idle\n"); + unsigned char best_ap = find_best_ap(); + printf("best ap: %x\n", best_ap); + if(best_ap != output_port[0]) + { + // send message + // send_meg(best_ap) + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 135; + control_content[1] = best_ap; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + _iph.ip_dst.s_addr = (best_ap == 0)? AP1_IP : AP2_IP; + + memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + if(best_ap == 0) + cp_ethernet_address(AP1_MAC, _ethh->ether_dhost); + else + cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); + memcpy(p->data(), _ethh, sizeof(click_ether)); + + output(0).push(p); + printf("packet push\n"); + state[0] = SWITCH_REQ; + } + } + p_in -> kill(); + +} + +// incomplete version, only for 2 ap and 1 client +unsigned char PacketSelectionSerial::find_best_ap() +{ + unsigned char ¤t = output_port[0]; + unsigned char potential = (current+1)%2; + bool flip_flag = true; + int i; + + for(i=0; i=score[current][i]) + { + flip_flag = false; + break; + } + + if(flip_flag) + return potential; + else + return current; +} + +CLICK_ENDDECLS +EXPORT_ELEMENT(PacketSelectionSerial) +ELEMENT_MT_SAFE(PacketSelectionSerial) diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh new file mode 100755 index 0000000000..91861db7b4 --- /dev/null +++ b/elements/tcpudp/packetselectionSerial.hh @@ -0,0 +1,73 @@ +#ifndef CLICK_PACKETSELECTIONSERIAL_HH +#define CLICK_PACKETSELECTIONSERIAL_HH +#include +#include +#include +#include +#include +#include + +CLICK_DECLS + +#define STATUS 4 +#define DATA 17 +#define CONTROL 6 +#define IDLE 0 +#define SWITCH_REQ 1 +#define CLIENT1 135 +#define AP1 2 +#define AP2 4 +#define AP1_IP 0x0201a8c0 +#define AP2_IP 0x0401a8c0 +#define CONTROLLER_IP 0x0101a8c0 +#define AP1_MAC "C0:56:27:72:A3:5B" +#define AP2_MAC "60:38:E0:03:FA:0B" +#define CONTROLLER_MAC "38:c9:86:40:c8:05" + + +#define pkt_type(p) *(p->data()+9) +#define ip_id(p) *(p->data()+20) +#define ap_id(p) *(p->data()+15) +#define ap_score(p) *(p->data()+20) + + + +class PacketSelectionSerial : public Element { public: + + + PacketSelectionSerial() CLICK_COLD; + ~PacketSelectionSerial() CLICK_COLD; + + const char *class_name() const { return "PacketSelectionSerial"; } + const char *port_count() const { return "1/1"; } + const char *flags() const { return "A"; } + + // int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *p_in); + void push_control(Packet *p_in); + void push_status(Packet *p_in); + unsigned char find_best_ap(); + + private: + + unsigned char *state; + static const unsigned char n_client = 1; + static const unsigned char n_ap = 2; + static const unsigned char n_compare = 5; + unsigned char **score; + unsigned char *next_score_id; + unsigned char *output_port; + unsigned char control_content[2]; + + click_ip _iph; + click_ether * _ethh; + + +}; + + + + +CLICK_ENDDECLS +#endif diff --git a/tcpudp b/tcpudp new file mode 120000 index 0000000000..a8c873db21 --- /dev/null +++ b/tcpudp @@ -0,0 +1 @@ +/Users/zhenyus/github/click/elements/tcpudp \ No newline at end of file From f7189da8d6bd331739f877bd41204a9a0bed95b4 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 26 Nov 2016 21:39:20 -0500 Subject: [PATCH 035/171] tmp1 --- elements/standard/wgttqueue.cc | 2 -- elements/standard/wgttqueue.hh | 59 ---------------------------------- 2 files changed, 61 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 6308b53556..cd8956ff2c 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -25,7 +25,6 @@ CLICK_DECLS WGTTQueue::WGTTQueue() : _q(0), dequeue_counter(0) { - openlog("MYLOG", LOG_CONS| LOG_NDELAY| LOG_NOWAIT, LOG_KERN); } void * @@ -48,7 +47,6 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) .complete() < 0) return -1; dequeue_time = tmp_dequeue_time; - syslog(LOG_DEBUG, "dequeue time: %d\n", dequeue_time); _capacity = new_capacity; return 0; } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 602ac35238..980f872741 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -3,65 +3,8 @@ #define CLICK_WGTTQUEUE_HH #include #include -#include CLICK_DECLS -/* -=c - -SimpleQueue -SimpleQueue(CAPACITY) - -=s storage - -stores packets in a FIFO queue - -=d - -Stores incoming packets in a first-in-first-out queue. -Drops incoming packets if the queue already holds CAPACITY packets. -The default for CAPACITY is 1000. - -B SimpleQueue is designed to be used in an -environment with at most one concurrent pusher and at most one concurrent -puller. Thus, at most one thread pushes to the SimpleQueue at a time and at -most one thread pulls from the SimpleQueue at a time. Different threads can -push to and pull from the SimpleQueue concurrently, however. See -ThreadSafeQueue for a queue that can support multiple concurrent pushers and -pullers. - -=n - -The Queue and NotifierQueue elements act like SimpleQueue, but additionally -notify interested parties when they change state (from nonempty to empty or -vice versa, and/or from nonfull to full or vice versa). - -=h length read-only - -Returns the current number of packets in the queue. - -=h highwater_length read-only - -Returns the maximum number of packets that have ever been in the queue at once. - -=h capacity read/write - -Returns or sets the queue's capacity. - -=h drops read-only - -Returns the number of packets dropped by the queue so far. Dropped packets -are emitted on output 1 if output 1 exists. - -=h reset_counts write-only - -When written, resets the C and C counters. - -=h reset write-only - -When written, drops all packets in the queue. - -=a Queue, NotifierQueue, MixedQueue, RED, FrontDropQueue, ThreadSafeQueue */ class WGTTQueue : public Element, public Storage { public: @@ -164,8 +107,6 @@ WGTTQueue::deq() assert(p); if (dequeue_counter == dequeue_time - 1) { - syslog(LOG_DEBUG, "DEQUEUE DISABLE\n"); - closelog(); } dequeue_counter ++; From c7c2855b38faf7a68e3f05bb3b09492017481a41 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 26 Nov 2016 21:41:04 -0500 Subject: [PATCH 036/171] tmp2 --- elements/standard/wgttqueue.cc | 146 +-------------------------------- elements/standard/wgttqueue.hh | 84 +------------------ 2 files changed, 3 insertions(+), 227 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index cd8956ff2c..c93bc5f959 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -27,14 +27,7 @@ WGTTQueue::WGTTQueue() { } -void * -WGTTQueue::cast(const char *n) -{ - if (strcmp(n, "WGTTQueue") == 0) - return (Element *)this; - else - return 0; -} + int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) @@ -51,90 +44,7 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) return 0; } -int -WGTTQueue::initialize(ErrorHandler *errh) -{ - assert(!_q && head() == 0 && tail() == 0); - _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * (_capacity + 1)); - if (_q == 0) - return errh->error("out of memory"); - _drops = 0; - _highwater_length = 0; - return 0; -} - -int -WGTTQueue::live_reconfigure(Vector &conf, ErrorHandler *errh) -{ - // change the maximum queue length at runtime - Storage::index_type old_capacity = _capacity; - // NB: do not call children! - if (WGTTQueue::configure(conf, errh) < 0) - return -1; - if (_capacity == old_capacity || !_q) - return 0; - Storage::index_type new_capacity = _capacity; - _capacity = old_capacity; - - Packet **new_q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * (new_capacity + 1)); - if (new_q == 0) - return errh->error("out of memory"); - - Storage::index_type i, j; - for (i = head(), j = 0; i != tail() && j != new_capacity; i = next_i(i)) - new_q[j++] = _q[i]; - for (; i != tail(); i = next_i(i)) - _q[i]->kill(); - - CLICK_LFREE(_q, sizeof(Packet *) * (_capacity + 1)); - _q = new_q; - set_head(0); - set_tail(j); - _capacity = new_capacity; - return 0; -} - -void -WGTTQueue::take_state(Element *e, ErrorHandler *errh) -{ - WGTTQueue *q = (WGTTQueue *)e->cast("WGTTQueue"); - if (!q) - return; - - if (tail() != head() || head() != 0) { - errh->error("already have packets enqueued, can%,t take state"); - return; - } - - set_head(0); - Storage::index_type i = 0, j = q->head(); - while (i < _capacity && j != q->tail()) { - _q[i] = q->_q[j]; - i++; - j = q->next_i(j); - } - set_tail(i); - _highwater_length = size(); - - if (j != q->tail()) - errh->warning("some packets lost (old length %d, new capacity %d)", - q->size(), _capacity); - while (j != q->tail()) { - q->_q[j]->kill(); - j = q->next_i(j); - } - q->set_head(0); - q->set_tail(0); -} -void -WGTTQueue::cleanup(CleanupStage) -{ - for (Storage::index_type i = head(); i != tail(); i = next_i(i)) - _q[i]->kill(); - CLICK_LFREE(_q, sizeof(Packet *) * (_capacity + 1)); - _q = 0; -} void WGTTQueue::push(int, Packet *p) @@ -170,61 +80,7 @@ WGTTQueue::pull(int) } -String -WGTTQueue::read_handler(Element *e, void *thunk) -{ - WGTTQueue *q = static_cast(e); - int which = reinterpret_cast(thunk); - switch (which) { - case 0: - return String(q->size()); - case 1: - return String(q->highwater_length()); - case 2: - return String(q->capacity()); - case 3: - return String(q->_drops); - default: - return ""; - } -} -void -WGTTQueue::reset() -{ - while (Packet *p = pull(0)) - checked_output_push(1, p); -} - -int -WGTTQueue::write_handler(const String &, Element *e, void *thunk, ErrorHandler *errh) -{ - WGTTQueue *q = static_cast(e); - int which = reinterpret_cast(thunk); - switch (which) { - case 0: - q->_drops = 0; - q->_highwater_length = q->size(); - return 0; - case 1: - q->reset(); - return 0; - default: - return errh->error("internal error"); - } -} - -void -WGTTQueue::add_handlers() -{ - add_read_handler("length", read_handler, 0); - add_read_handler("highwater_length", read_handler, 1); - add_read_handler("capacity", read_handler, 2, Handler::h_calm); - add_read_handler("drops", read_handler, 3); - add_write_handler("capacity", reconfigure_keyword_handler, "0 CAPACITY"); - add_write_handler("reset_counts", write_handler, 0, Handler::h_button | Handler::h_nonexclusive); - add_write_handler("reset", write_handler, 1, Handler::h_button); -} CLICK_ENDDECLS ELEMENT_PROVIDES(Storage) diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 980f872741..427943d213 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -10,33 +10,18 @@ class WGTTQueue : public Element, public Storage { public: WGTTQueue() CLICK_COLD; - int drops() const { return _drops; } - int highwater_length() const { return _highwater_length; } + inline bool enq(Packet*); inline void lifo_enq(Packet*); inline Packet* deq(); - // to be used with care - Packet* packet(int i) const { return _q[i]; } - void reset(); // NB: does not do notification - - template Packet* yank1(Filter); - template Packet* yank1_peek(Filter); - template int yank(Filter, Vector &); const char *class_name() const { return "WGTTQueue"; } - const char *port_count() const { return PORTS_1_1X2; } + const char *port_count() const { return "1/2"; } const char *processing() const { return "h/lh"; } - void* cast(const char*); int configure(Vector&, ErrorHandler*) CLICK_COLD; - int initialize(ErrorHandler*) CLICK_COLD; - void cleanup(CleanupStage) CLICK_COLD; - bool can_live_reconfigure() const { return true; } - int live_reconfigure(Vector&, ErrorHandler*); - void take_state(Element*, ErrorHandler*); - void add_handlers() CLICK_COLD; void push(int port, Packet*); Packet* pull(int port); @@ -53,10 +38,6 @@ class WGTTQueue : public Element, public Storage { public: friend class TokenQueue; friend class InOrderQueue; friend class ECNQueue; - - static String read_handler(Element*, void*) CLICK_COLD; - static int write_handler(const String&, Element*, void*, ErrorHandler*) CLICK_COLD; - }; @@ -118,67 +99,6 @@ WGTTQueue::deq() } } -template -Packet * -WGTTQueue::yank1(Filter filter) - /* Remove from the queue and return the first packet that matches - 'filter(Packet *)'. The returned packet must be deallocated by the - caller. */ -{ - for (Storage::index_type trav = head(); trav != tail(); trav = next_i(trav)) - if (filter(_q[trav])) { - Packet *p = _q[trav]; - int prev = prev_i(trav); - while (trav != head()) { - _q[trav] = _q[prev]; - trav = prev; - prev = prev_i(prev); - } - set_head(next_i(head())); - return p; - } - return 0; -} - -template -Packet * -WGTTQueue::yank1_peek(Filter filter) - /* return the first packet that matches - 'filter(Packet *)'. The returned packet must *NOT* be deallocated by the - caller. */ -{ - for (Storage::index_type trav = head(); trav != tail(); trav = next_i(trav)) - if (filter(_q[trav])) { - Packet *p = _q[trav]; - return p; - } - return 0; -} - -template -int -WGTTQueue::yank(Filter filter, Vector &yank_vec) - /* Removes from the queue and adds to 'yank_vec' all packets in the queue - that match 'filter(Packet *)'. Packets are added to 'yank_vec' in LIFO - order, so 'yank_vec.back()' will equal the first packet in the queue - that matched 'filter()'. Caller should deallocate any packets returned - in 'yank_vec'. Returns the number of packets yanked. */ -{ - Storage::index_type write_ptr = tail(); - int nyanked = 0; - for (Storage::index_type trav = tail(); trav != head(); ) { - trav = prev_i(trav); - if (filter(_q[trav])) { - yank_vec.push_back(_q[trav]); - nyanked++; - } else { - write_ptr = prev_i(write_ptr); - _q[write_ptr] = _q[trav]; - } - } - set_head(write_ptr); - return nyanked; -} CLICK_ENDDECLS #endif From aae8e47e4a728d2133c050310060a88408c3d425 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 27 Nov 2016 09:47:22 -0500 Subject: [PATCH 037/171] finish wgttqueue --- elements/standard/wgttqueue.cc | 180 +++++++++++++++++++++++++++------ elements/standard/wgttqueue.hh | 128 +++++++++++------------ 2 files changed, 213 insertions(+), 95 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index c93bc5f959..158d2082b1 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -23,8 +23,13 @@ CLICK_DECLS WGTTQueue::WGTTQueue() - : _q(0), dequeue_counter(0) { + _head = 0; + _tail = 0; + _iph = (click_ip*)CLICK_LALLOC(sizeof(click_ip)); + _ethh = (click_ether*)CLICK_LALLOC(sizeof(click_ether)); + _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); + printf("wgtt init succeed\n"); } @@ -32,51 +37,162 @@ WGTTQueue::WGTTQueue() int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { - unsigned new_capacity = 1000; - int tmp_dequeue_time; + printf("In configure\n"); if (Args(conf, this, errh) - .read_p("CAPACITY", new_capacity) - .read_p("DEQUEUETIME", tmp_dequeue_time) + .read_p("IDENTITY", IntArg(), identity) .complete() < 0) - return -1; - dequeue_time = tmp_dequeue_time; - _capacity = new_capacity; + return -1; + + + printf("After configure _ip\n"); + + printf("After configure ether type\n"); + printf("identity: %X\n", identity); + + + printf("wgtt configure succeed\n"); + return 0; +} + +int +WGTTQueue::initialize(ErrorHandler *errh) +{ + printf("wgtt in initialize\n"); + + + if(identity==1) + _block = false; + else + _block = true; + + printf("After configure _block\n"); + //TODO: checksum not set + + memset(_iph, 0, sizeof(click_ip)); + _iph->ip_v = 4; + _iph->ip_hl = sizeof(click_ip) >> 2; + _iph->ip_ttl = 250; + switch(identity) + { + case 1: _iph->ip_src.s_addr = AP1_IP;break; + case 2: _iph->ip_src.s_addr = AP2_IP;break; + } + _iph->ip_p = 6;//control msg + _iph->ip_tos = 0; + _iph->ip_off = 0; + _iph->ip_sum = 0; + _iph->ip_len = htons(22); + + _ethh->ether_type = htons(0x0800); + printf("identity: %X\n", identity); + switch(identity) + { + case 1: cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; + case 2: cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; + } + + assert(_head == 0 && _tail == 0); + printf("wgtt after !_q\n"); + if (_q == 0) + return errh->error("out of memory"); + printf("wgtt initialize succeed\n"); return 0; } void -WGTTQueue::push(int, Packet *p) +WGTTQueue::push(int, Packet *p_in) +{ + printf("wgttQueue in push\n"); + switch(pkt_type(p_in)) + { + case CONTROL: push_control(p_in);break; + case DATA: push_data(p_in);break; + } +} + +void WGTTQueue::push_control(Packet *p_in) +{ + if(ap_id(p_in) == CONTROLLER)//stop + { + printf("wgttQueue in push_controller\n"); + _block = true; + const unsigned char & dst_ap_id = start_ap(p_in); + + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 135; + control_content[1] = _head; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + switch(dst_ap_id) + { + case 1: _iph->ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 2: _iph->ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + memcpy(p->data(), _ethh, sizeof(click_ether)); + + p_in -> kill(); + checked_output_push(1, p); + printf("ap2ap packet push\n"); + } + else + { + printf("wgttQueue in push_apap\n"); + const unsigned char & start_seq = start_seq(p_in); + while(_head != start_seq) + { + printf("wgttQueue in dering\n"); + deRing(); + } + + + + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 135; + control_content[1] = 0; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + _iph->ip_dst.s_addr = CONTROLLER_IP;cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_dhost); + + memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + memcpy(p->data(), _ethh, sizeof(click_ether)); + + p_in -> kill(); + printf("ap-c packet push\n"); + _block = false; + checked_output_push(1, p); + + } +} + +void WGTTQueue::push_data(Packet *p_in) { - // If you change this code, also change NotifierQueue::push() - // and FullNoteQueue::push(). - Storage::index_type h = head(), t = tail(), nt = next_i(t); - - // should this stuff be in SimpleQueue::enq? - if (nt != h) { - _q[t] = p; - set_tail(nt); - - int s = size(h, nt); - if (s > _highwater_length) - _highwater_length = s; - // printf("enque\n"); - - } else { - // if (!(_drops % 100)) - if (_drops == 0 && _capacity > 0) - click_chatter("%p{element}: overflow", this); - _drops++; - // printf("overflow\n"); - checked_output_push(1, p); + printf("wgttQueue in push data\n"); + unsigned char seq = start_seq(p_in); + p_in -> take(1); + while(_tail != seq) + { + printf("wgttQueue enring\n"); + enRing(0); } + enRing(p_in); } Packet * -WGTTQueue::pull(int) +WGTTQueue::pull(int port) { - return deq(); + // printf("wgttQueue in pull\n"); + return deRing(); } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 427943d213..bc2e40fd45 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -3,102 +3,104 @@ #define CLICK_WGTTQUEUE_HH #include #include +#include +#include +#include CLICK_DECLS +#define RING_SIZE 256 +#define STATUS 4 +#define DATA 17 +#define CONTROL 6 +#define IDLE 0 +#define SWITCH_REQ 1 +#define CLIENT1 135 +#define CONTROLLER 1 +#define AP1 2 +#define AP2 4 +#define IP_BASE 0x01a8c0 +#define AP1_IP 0x0201a8c0 +#define AP2_IP 0x0401a8c0 +#define CONTROLLER_IP 0x0101a8c0 +#define AP1_MAC "C0:56:27:72:A3:5B" +#define AP2_MAC "60:38:E0:03:FA:0B" +#define CONTROLLER_MAC "38:c9:86:40:c8:05" + +#define pkt_type(p) *(p->data()+9) +#define ip_id(p) *(p->data()+20) +#define ap_id(p) *(p->data()+15) +#define start_ap(p) *(p->data()+21) +#define start_seq(p) *(p->data()+21) +#define ap_score(p) *(p->data()+20) + class WGTTQueue : public Element, public Storage { public: WGTTQueue() CLICK_COLD; - - - inline bool enq(Packet*); - inline void lifo_enq(Packet*); - inline Packet* deq(); - + inline void enRing(Packet*);//flag: whether override + inline Packet* deRing(); + inline void enque(Packet*);//flag: whether override + inline Packet* deque(); const char *class_name() const { return "WGTTQueue"; } const char *port_count() const { return "1/2"; } const char *processing() const { return "h/lh"; } int configure(Vector&, ErrorHandler*) CLICK_COLD; + int initialize(ErrorHandler*) CLICK_COLD; void push(int port, Packet*); + void push_control(Packet *p_in); + void push_data(Packet *p_in); Packet* pull(int port); protected: Packet* volatile * _q; - volatile int dequeue_time; - volatile int dequeue_counter; - volatile int _drops; - int _highwater_length; - - friend class MixedQueue; - friend class TokenQueue; - friend class InOrderQueue; - friend class ECNQueue; -}; + volatile unsigned char _head; + volatile unsigned char _tail; -inline bool -WGTTQueue::enq(Packet *p) -{ - assert(p); - Storage::index_type h = head(), t = tail(), nt = next_i(t); - if (nt != h) { - _q[t] = p; - set_tail(nt); - int s = size(h, nt); - if (s > _highwater_length) - _highwater_length = s; - return true; - } else { - p->kill(); - _drops++; - return false; - } -} + volatile bool _block; + unsigned char identity; + unsigned char control_content[2]; + + click_ip * _iph; + click_ether * _ethh; + +}; inline void -WGTTQueue::lifo_enq(Packet *p) +WGTTQueue::enRing(Packet *p) { - // XXX NB: significantly more dangerous in a multithreaded environment - // than plain (FIFO) enq(). - assert(p); - Storage::index_type h = head(), t = tail(), ph = prev_i(h); - if (ph == t) { - t = prev_i(t); - _q[t]->kill(); - set_tail(t); + if((_tail+1)%RING_SIZE == _head)//override + { + printf("WGTTQueue override\n"); + if(_q[_head] != 0) + _q[_head] -> kill(); + _head = (_head+1)%RING_SIZE; } - _q[ph] = p; - set_head_release(ph); + printf("WGTTQueue before _q[_tail] = p\n"); + Packet *tmp = _q[_tail]; + printf("_tail: %x\n", _tail); + _q[_tail] = p; + printf("WGTTQueue finish _q[_tail] = p\n"); + _tail = (_tail+1)%RING_SIZE; + printf("WGTTQueue finish enRing\n"); } inline Packet * -WGTTQueue::deq() +WGTTQueue::deRing() { - if(dequeue_counter >= dequeue_time) + if(_block || _head==_tail) return 0; - Storage::index_type h = head(), t = tail(); - if (h != t) { - Packet *p = _q[h]; - set_head(next_i(h)); - assert(p); - if (dequeue_counter == dequeue_time - 1) - { - } - dequeue_counter ++; - - return p; - } else - { - // printf("deque function\n"); - return 0; - } + Packet *p = _q[_head]; + _head = (_head+1)%RING_SIZE; + return p; } + CLICK_ENDDECLS #endif From 7339088468a2af1c10c3e0a3ef4bb8aaab95ca89 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 27 Nov 2016 19:15:05 -0500 Subject: [PATCH 038/171] modify wattqueue and adder --- elements/standard/wgttqueue.cc | 10 +---- elements/tcpudp/idadder.cc | 80 ++++++++++++++++++++++++++++++---- elements/tcpudp/idadder.hh | 16 ++++++- 3 files changed, 88 insertions(+), 18 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 158d2082b1..215071c49e 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -44,12 +44,6 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) return -1; - printf("After configure _ip\n"); - - printf("After configure ether type\n"); - printf("identity: %X\n", identity); - - printf("wgtt configure succeed\n"); return 0; } @@ -178,13 +172,13 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { printf("wgttQueue in push data\n"); - unsigned char seq = start_seq(p_in); - p_in -> take(1); + const unsigned char & seq = start_seq(p_in); while(_tail != seq) { printf("wgttQueue enring\n"); enRing(0); } + p_in -> pull(21); enRing(p_in); } diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 4f725e1db4..64db543f5c 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -31,26 +31,88 @@ IDAdder::IDAdder() { - counter = 0; + printf("idadder in init\n"); + counter = 0; + _iph = (click_ip*)CLICK_LALLOC(sizeof(click_ip)); + + printf("idadder init finish\n"); + } + IDAdder::~IDAdder() { } +int +IDAdder::initialize(ErrorHandler *errh) +{ + + memset(_iph, 0, sizeof(click_ip)); + _iph->ip_v = 4; + _iph->ip_hl = sizeof(click_ip) >> 2; + _iph->ip_ttl = 250; + _iph->ip_src.s_addr = CONTROLLER_IP; + _iph->ip_p = 17;//data msg + _iph->ip_tos = 0; + _iph->ip_off = 0; + _iph->ip_sum = 0; + + + + printf("idadder initial finish\n"); + return 0; +} + void IDAdder::push(int port, Packet *p_in) { - // printf("into idadder\n"); - WritablePacket *p = p_in->put(1); - memcpy(p->end_data()-1, &counter, 1); - counter ++; - printf("Tail: %X\n", *(p->end_data()-1)); - printf("counter: %u\n", counter); - // p_in -> kill(); - output(0).push(p); + printf("idadder in push\n"); + static unsigned char tmp_counter = 0; + if(tmp_counter ==0) + { + tmp_counter++; + _ethh.ether_type = htons(0x0800); + cp_ethernet_address(CONTROLLER_MAC, _ethh.ether_shost); + + } + + + _iph->ip_len = p_in->length()+sizeof(click_ip)+1; + p_in->push(sizeof(click_ip)+sizeof(click_ether)+1); + for(int i = 0;i<1;i++) + { + Packet *p_tmp = p_in->clone(); + WritablePacket *p = p_tmp->uniqueify(); + + if(i == 0) + { + _iph->ip_dst.s_addr = AP1_IP; + cp_ethernet_address(AP1_MAC, _ethh.ether_dhost); + } + else + { + _iph->ip_dst.s_addr = AP2_IP; + cp_ethernet_address(AP2_MAC, _ethh.ether_dhost); + } + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); + memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + memcpy(p->data(), &_ethh, sizeof(click_ether)); + printf("idadder push %dth\n", i); + output(0).push(p); + } + + WritablePacket *p = p_in->uniqueify(); + _iph->ip_dst.s_addr = AP2_IP; + cp_ethernet_address(AP2_MAC, _ethh.ether_dhost); + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); + memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + memcpy(p->data(), &_ethh, sizeof(click_ether)); + output(0).push(p); + + counter ++; } diff --git a/elements/tcpudp/idadder.hh b/elements/tcpudp/idadder.hh index 02db8f889b..26d7c2d93b 100755 --- a/elements/tcpudp/idadder.hh +++ b/elements/tcpudp/idadder.hh @@ -3,18 +3,23 @@ #include #include #include +#include +#include CLICK_DECLS +#define RING_SIZE 256 #define STATUS 4 #define DATA 17 #define CONTROL 6 #define IDLE 0 #define SWITCH_REQ 1 #define CLIENT1 135 +#define CONTROLLER 1 #define AP1 2 #define AP2 4 +#define IP_BASE 0x01a8c0 #define AP1_IP 0x0201a8c0 #define AP2_IP 0x0401a8c0 #define CONTROLLER_IP 0x0101a8c0 @@ -22,6 +27,13 @@ CLICK_DECLS #define AP2_MAC "60:38:E0:03:FA:0B" #define CONTROLLER_MAC "38:c9:86:40:c8:05" +#define pkt_type(p) *(p->data()+9) +#define ip_id(p) *(p->data()+20) +#define ap_id(p) *(p->data()+15) +#define start_ap(p) *(p->data()+21) +#define start_seq(p) *(p->data()+21) +#define ap_score(p) *(p->data()+20) + class IDAdder : public Element { public: @@ -35,13 +47,15 @@ class IDAdder : public Element { public: const char *flags() const { return "A"; } // int configure(Vector &, ErrorHandler *) CLICK_COLD; - + int initialize(ErrorHandler*) CLICK_COLD; void push(int port, Packet *p_in); private: unsigned char counter; + click_ip * _iph; + click_ether _ethh; }; From a613111a4c3bae6a1c8b78f860873f36f80bb6fe Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 27 Nov 2016 19:59:04 -0500 Subject: [PATCH 039/171] control.ip.proto from 6 to 27 --- elements/standard/wgttqueue.cc | 6 +++--- elements/standard/wgttqueue.hh | 10 +++++----- elements/tcpudp/packetselectionSerial.cc | 6 +++--- elements/tcpudp/packetselectionSerial.hh | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 215071c49e..879da3b6ed 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -71,7 +71,7 @@ WGTTQueue::initialize(ErrorHandler *errh) case 1: _iph->ip_src.s_addr = AP1_IP;break; case 2: _iph->ip_src.s_addr = AP2_IP;break; } - _iph->ip_p = 6;//control msg + _iph->ip_p = 27;//control msg _iph->ip_tos = 0; _iph->ip_off = 0; _iph->ip_sum = 0; @@ -141,7 +141,7 @@ void WGTTQueue::push_control(Packet *p_in) const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { - printf("wgttQueue in dering\n"); + // printf("wgttQueue in dering\n"); deRing(); } @@ -175,7 +175,7 @@ void WGTTQueue::push_data(Packet *p_in) const unsigned char & seq = start_seq(p_in); while(_tail != seq) { - printf("wgttQueue enring\n"); + // printf("wgttQueue enring\n"); enRing(0); } p_in -> pull(21); diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index bc2e40fd45..9deaf79e0f 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -11,7 +11,7 @@ CLICK_DECLS #define RING_SIZE 256 #define STATUS 4 #define DATA 17 -#define CONTROL 6 +#define CONTROL 27 #define IDLE 0 #define SWITCH_REQ 1 #define CLIENT1 135 @@ -81,13 +81,13 @@ WGTTQueue::enRing(Packet *p) _q[_head] -> kill(); _head = (_head+1)%RING_SIZE; } - printf("WGTTQueue before _q[_tail] = p\n"); + // printf("WGTTQueue before _q[_tail] = p\n"); Packet *tmp = _q[_tail]; - printf("_tail: %x\n", _tail); + // printf("_tail: %x\n", _tail); _q[_tail] = p; - printf("WGTTQueue finish _q[_tail] = p\n"); + // printf("WGTTQueue finish _q[_tail] = p\n"); _tail = (_tail+1)%RING_SIZE; - printf("WGTTQueue finish enRing\n"); + // printf("WGTTQueue finish enRing\n"); } inline Packet * diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 8d65902579..e519c49736 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -60,7 +60,7 @@ PacketSelectionSerial::PacketSelectionSerial() _iph.ip_hl = sizeof(click_ip) >> 2; _iph.ip_ttl = 250; _iph.ip_src.s_addr = CONTROLLER_IP; - _iph.ip_p = 6;//control msg + _iph.ip_p = 27;//control msg _iph.ip_tos = 0; _iph.ip_off = 0; _iph.ip_sum = 0; @@ -129,7 +129,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } // update_score(&ap_score(p_in), &c) printf("ap score: %x\n", ap_score(p_in)); - printf("next_score_id[a]: %x\n", next_score_id[a]); + // printf("next_score_id[a]: %x\n", next_score_id[a]); score[a][next_score_id[a]] = ap_score(p_in); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state @@ -161,7 +161,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); output(0).push(p); - printf("packet push\n"); + // printf("packet push\n"); state[0] = SWITCH_REQ; } } diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index 91861db7b4..a69074e4f9 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -11,7 +11,7 @@ CLICK_DECLS #define STATUS 4 #define DATA 17 -#define CONTROL 6 +#define CONTROL 27 #define IDLE 0 #define SWITCH_REQ 1 #define CLIENT1 135 From aa831a7f98f1024e300037472ee26a4dd07bd8eb Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 28 Nov 2016 10:08:40 -0500 Subject: [PATCH 040/171] remove printf --- elements/standard/wgttqueue.cc | 24 ++++++++++++------------ elements/standard/wgttqueue.hh | 2 +- elements/tcpudp/idadder.cc | 8 ++++---- elements/tcpudp/packetselectionSerial.cc | 10 +++++----- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 879da3b6ed..fff8493684 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -37,7 +37,7 @@ WGTTQueue::WGTTQueue() int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { - printf("In configure\n"); + //printf("In configure\n"); if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) .complete() < 0) @@ -51,7 +51,7 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) int WGTTQueue::initialize(ErrorHandler *errh) { - printf("wgtt in initialize\n"); + //printf("wgtt in initialize\n"); if(identity==1) @@ -59,7 +59,7 @@ WGTTQueue::initialize(ErrorHandler *errh) else _block = true; - printf("After configure _block\n"); + // printf("After configure _block\n"); //TODO: checksum not set memset(_iph, 0, sizeof(click_ip)); @@ -78,7 +78,7 @@ WGTTQueue::initialize(ErrorHandler *errh) _iph->ip_len = htons(22); _ethh->ether_type = htons(0x0800); - printf("identity: %X\n", identity); + // printf("identity: %X\n", identity); switch(identity) { case 1: cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; @@ -86,10 +86,10 @@ WGTTQueue::initialize(ErrorHandler *errh) } assert(_head == 0 && _tail == 0); - printf("wgtt after !_q\n"); + // printf("wgtt after !_q\n"); if (_q == 0) return errh->error("out of memory"); - printf("wgtt initialize succeed\n"); + printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -98,7 +98,7 @@ WGTTQueue::initialize(ErrorHandler *errh) void WGTTQueue::push(int, Packet *p_in) { - printf("wgttQueue in push\n"); + // printf("wgttQueue in push\n"); switch(pkt_type(p_in)) { case CONTROL: push_control(p_in);break; @@ -110,7 +110,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(ap_id(p_in) == CONTROLLER)//stop { - printf("wgttQueue in push_controller\n"); + // printf("wgttQueue in push_controller\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); @@ -133,11 +133,11 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); checked_output_push(1, p); - printf("ap2ap packet push\n"); + // printf("ap2ap packet push\n"); } else { - printf("wgttQueue in push_apap\n"); + // printf("wgttQueue in push_apap\n"); const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { @@ -162,7 +162,7 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); p_in -> kill(); - printf("ap-c packet push\n"); + // printf("ap-c packet push\n"); _block = false; checked_output_push(1, p); @@ -171,7 +171,7 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { - printf("wgttQueue in push data\n"); + // printf("wgttQueue in push data\n"); const unsigned char & seq = start_seq(p_in); while(_tail != seq) { diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 9deaf79e0f..079733c339 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -76,7 +76,7 @@ WGTTQueue::enRing(Packet *p) { if((_tail+1)%RING_SIZE == _head)//override { - printf("WGTTQueue override\n"); + // printf("WGTTQueue override\n"); if(_q[_head] != 0) _q[_head] -> kill(); _head = (_head+1)%RING_SIZE; diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 64db543f5c..159cc4b881 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -31,7 +31,7 @@ IDAdder::IDAdder() { - printf("idadder in init\n"); + // printf("idadder in init\n"); counter = 0; _iph = (click_ip*)CLICK_LALLOC(sizeof(click_ip)); @@ -62,14 +62,14 @@ IDAdder::initialize(ErrorHandler *errh) - printf("idadder initial finish\n"); + printf("idadder initial finish, ready to start\n"); return 0; } void IDAdder::push(int port, Packet *p_in) { - printf("idadder in push\n"); + // printf("idadder in push\n"); static unsigned char tmp_counter = 0; if(tmp_counter ==0) { @@ -100,7 +100,7 @@ void IDAdder::push(int port, Packet *p_in) memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); memcpy(p->data(), &_ethh, sizeof(click_ether)); - printf("idadder push %dth\n", i); + // printf("idadder push %dth\n", i); output(0).push(p); } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index e519c49736..c66f22a256 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -72,7 +72,7 @@ PacketSelectionSerial::PacketSelectionSerial() _ethh->ether_type = htons(0x0800); bool result = cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_shost); - + printf("Packetselection: init finish, ready to start\n"); } @@ -119,9 +119,9 @@ void PacketSelectionSerial::push_control(Packet *p_in) void PacketSelectionSerial::push_status(Packet *p_in) { - printf("In push status.\n"); + //printf("In push status.\n"); unsigned char a; - printf("ap id: %x\n", ap_id(p_in)); + //printf("ap id: %x\n", ap_id(p_in)); switch(ap_id(p_in)) { case AP1: a = 0; break; @@ -135,9 +135,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) // able to change state if(state[0] == IDLE) { - printf("state idle\n"); + //printf("state idle\n"); unsigned char best_ap = find_best_ap(); - printf("best ap: %x\n", best_ap); + //printf("best ap: %x\n", best_ap); if(best_ap != output_port[0]) { // send message From 31b8cf827f82104c889f3a713a59da805bfe2143 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 28 Nov 2016 10:29:23 -0500 Subject: [PATCH 041/171] add print when switch --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index c66f22a256..3013958f44 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -161,7 +161,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); output(0).push(p); - // printf("packet push\n"); + printf("controller issu switch to ap %X\n", best_ap); state[0] = SWITCH_REQ; } } From 0bc6f782ddc72155d627eaa41121357a4a098118 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 28 Nov 2016 10:56:25 -0500 Subject: [PATCH 042/171] add print for handshake control --- elements/standard/wgttqueue.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index fff8493684..a3dc8271fe 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -110,7 +110,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(ap_id(p_in) == CONTROLLER)//stop { - // printf("wgttQueue in push_controller\n"); + printf("wgttQueue: receive switch req\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); @@ -133,11 +133,11 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); checked_output_push(1, p); - // printf("ap2ap packet push\n"); + printf("wgttQueue send ap-ap seq\n"); } else { - // printf("wgttQueue in push_apap\n"); + printf("wgttQueue receive ap-ap seq\n"); const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { @@ -165,7 +165,7 @@ void WGTTQueue::push_control(Packet *p_in) // printf("ap-c packet push\n"); _block = false; checked_output_push(1, p); - + printf("wgttQueue send switch ack\n"); } } From 31e9817f7d8dae0f5d786359a3e8cf516c4b3ba4 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 28 Nov 2016 11:32:24 -0500 Subject: [PATCH 043/171] fix bug: dst ip --- elements/standard/wgttqueue.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index a3dc8271fe..2d0ab41d93 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -123,8 +123,8 @@ void WGTTQueue::push_control(Packet *p_in) // //ip part switch(dst_ap_id) { - case 1: _iph->ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 2: _iph->ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 0: _iph->ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1: _iph->ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; } memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); // p->set_ip_header(ip, sizeof(click_ip)); From d529e19e23fe789a4cbc1b1c753bb7ef34583b92 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 10:37:48 -0500 Subject: [PATCH 044/171] add four prints for queue --- elements/standard/wgttqueue.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 2d0ab41d93..ecebe2ac19 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -137,11 +137,14 @@ void WGTTQueue::push_control(Packet *p_in) } else { + printf("wgttQueue receive ap-ap seq\n"); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail) const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { - // printf("wgttQueue in dering\n"); + printf("wgttQueue in dering\n"); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail) deRing(); } From aa642b67937e58de305147b8289105dabb6e2db1 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 10:50:04 -0500 Subject: [PATCH 045/171] fix a bug: not dering --- elements/standard/wgttqueue.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index ecebe2ac19..7048275a29 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -139,13 +139,15 @@ void WGTTQueue::push_control(Packet *p_in) { printf("wgttQueue receive ap-ap seq\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail) + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { printf("wgttQueue in dering\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail) - deRing(); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + if(_q[_head] != 0) + _q[_head] -> kill(); + _head = (_head+1)%RING_SIZE; } @@ -178,11 +180,12 @@ void WGTTQueue::push_data(Packet *p_in) const unsigned char & seq = start_seq(p_in); while(_tail != seq) { - // printf("wgttQueue enring\n"); + printf("wgttQueue enring 0, _head: %X, _tail: %X\n"); enRing(0); } p_in -> pull(21); enRing(p_in); + printf("wgttQueue enring, _head: %X, _tail: %X\n"); } Packet * From 428f379d5eb3d8045d5478a0fc6c72ec0e50edd4 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 11:17:11 -0500 Subject: [PATCH 046/171] check dering enring in detail --- elements/standard/wgttqueue.cc | 16 ++++++++++------ elements/tcpudp/packetselectionSerial.cc | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 7048275a29..b9fd72913f 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -132,8 +132,9 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); p_in -> kill(); - checked_output_push(1, p); printf("wgttQueue send ap-ap seq\n"); + checked_output_push(1, p); + } else { @@ -143,7 +144,7 @@ void WGTTQueue::push_control(Packet *p_in) const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { - printf("wgttQueue in dering\n"); + printf("wgttQueue in dering-prepare\n"); printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); if(_q[_head] != 0) _q[_head] -> kill(); @@ -169,8 +170,9 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // printf("ap-c packet push\n"); _block = false; - checked_output_push(1, p); printf("wgttQueue send switch ack\n"); + checked_output_push(1, p); + } } @@ -180,18 +182,20 @@ void WGTTQueue::push_data(Packet *p_in) const unsigned char & seq = start_seq(p_in); while(_tail != seq) { - printf("wgttQueue enring 0, _head: %X, _tail: %X\n"); + printf("wgttQueue in enring-prepare\n"); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); enRing(0); } p_in -> pull(21); enRing(p_in); - printf("wgttQueue enring, _head: %X, _tail: %X\n"); + printf("wgttQueue enring, _head: %X, _tail: %X\n", _head, _tail); } Packet * WGTTQueue::pull(int port) { - // printf("wgttQueue in pull\n"); + printf("wgttQueue in pull\n"); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); return deRing(); } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 3013958f44..52cd3244e7 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -163,6 +163,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) output(0).push(p); printf("controller issu switch to ap %X\n", best_ap); state[0] = SWITCH_REQ; + output_port[0] = best_ap; } } p_in -> kill(); From f29c0cce2199ba90e3af4c6be8ce2e46556197e2 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 19:18:49 -0500 Subject: [PATCH 047/171] remove NULL pull print --- elements/standard/wgttqueue.cc | 4 +--- elements/standard/wgttqueue.hh | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index b9fd72913f..aa3f5b94db 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -187,15 +187,13 @@ void WGTTQueue::push_data(Packet *p_in) enRing(0); } p_in -> pull(21); - enRing(p_in); printf("wgttQueue enring, _head: %X, _tail: %X\n", _head, _tail); + enRing(p_in); } Packet * WGTTQueue::pull(int port) { - printf("wgttQueue in pull\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); return deRing(); } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 079733c339..acabbaf3cc 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -97,6 +97,11 @@ WGTTQueue::deRing() return 0; Packet *p = _q[_head]; _head = (_head+1)%RING_SIZE; + if(p != 0) + { + printf("wgttQueue in pull\n"); + printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + } return p; } From 0bace36b84207de7b074c1b6515e487e46c234df Mon Sep 17 00:00:00 2001 From: Zhenyu Date: Tue, 29 Nov 2016 19:20:40 -0500 Subject: [PATCH 048/171] compulsory switch --- elements/tcpudp/packetselectionSerial.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 3013958f44..4ca8a3a8aa 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -53,7 +53,7 @@ PacketSelectionSerial::PacketSelectionSerial() } state = new unsigned char[n_client]; - + state[0] = IDLE; //TODO: checksum not set memset(&_iph, 0, sizeof(click_ip)); _iph.ip_v = 4; @@ -113,7 +113,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) { unsigned char c = 0; state[c] = IDLE; - //printf("In push control.\n"); + printf("switch request ack.\n"); p_in -> kill(); } @@ -128,16 +128,25 @@ void PacketSelectionSerial::push_status(Packet *p_in) case AP2: a = 1; break; } // update_score(&ap_score(p_in), &c) - printf("ap score: %x\n", ap_score(p_in)); + printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); score[a][next_score_id[a]] = ap_score(p_in); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state + + static unsigned char tmp_counter = 0; + + if(state[0] == IDLE) { - //printf("state idle\n"); + tmp_counter++; + printf("state idle\n"); unsigned char best_ap = find_best_ap(); //printf("best ap: %x\n", best_ap); + if(tmp_counter == 20) + { + best_ap = 1; + } if(best_ap != output_port[0]) { // send message @@ -149,12 +158,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); // //ip part - _iph.ip_dst.s_addr = (best_ap == 0)? AP1_IP : AP2_IP; + _iph.ip_dst.s_addr = (output_port[0] == 0)? AP1_IP : AP2_IP; memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); // p->set_ip_header(ip, sizeof(click_ip)); //ether part - if(best_ap == 0) + if(output_port[0] == 0) cp_ethernet_address(AP1_MAC, _ethh->ether_dhost); else cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); From 2dc4149f6e7cb237206ba71b3d79008cfe76c2d9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 19:26:52 -0500 Subject: [PATCH 049/171] after compulsory switch will lock, and IDadder print --- elements/tcpudp/idadder.cc | 4 +++- elements/tcpudp/packetselectionSerial.cc | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 159cc4b881..ca0b0d400b 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -78,6 +78,7 @@ void IDAdder::push(int port, Packet *p_in) cp_ethernet_address(CONTROLLER_MAC, _ethh.ether_shost); } + printf("IDadder: counter: %X\n", counter); _iph->ip_len = p_in->length()+sizeof(click_ip)+1; @@ -110,9 +111,10 @@ void IDAdder::push(int port, Packet *p_in) memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); memcpy(p->data(), &_ethh, sizeof(click_ether)); + counter ++; output(0).push(p); - counter ++; + } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index f1522bbccc..b661fcc1f0 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -143,7 +143,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) printf("state idle\n"); unsigned char best_ap = find_best_ap(); //printf("best ap: %x\n", best_ap); - if(tmp_counter == 20) + if(tmp_counter >= 20) { best_ap = 1; } @@ -169,10 +169,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); memcpy(p->data(), _ethh, sizeof(click_ether)); - output(0).push(p); + printf("controller issu switch to ap %X\n", best_ap); state[0] = SWITCH_REQ; output_port[0] = best_ap; + output(0).push(p); + } } p_in -> kill(); From c0c2bed2b3906baa5927aefe675186da6cbc2483 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 22:57:32 -0500 Subject: [PATCH 050/171] fix bug: start_seq & seq mix together --- elements/standard/wgttqueue.cc | 7 +++---- elements/standard/wgttqueue.hh | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index aa3f5b94db..75ce2f2dd7 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -141,11 +141,10 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue receive ap-ap seq\n"); printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + printf("wgttQueue in dering-prepare\n"); const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) - { - printf("wgttQueue in dering-prepare\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + { if(_q[_head] != 0) _q[_head] -> kill(); _head = (_head+1)%RING_SIZE; @@ -179,7 +178,7 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { // printf("wgttQueue in push data\n"); - const unsigned char & seq = start_seq(p_in); + const unsigned char & seq = seq(p_in); while(_tail != seq) { printf("wgttQueue in enring-prepare\n"); diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index acabbaf3cc..b7dd8b996d 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -32,6 +32,7 @@ CLICK_DECLS #define start_ap(p) *(p->data()+21) #define start_seq(p) *(p->data()+21) #define ap_score(p) *(p->data()+20) +#define sep(p) *(p->data()+20) class WGTTQueue : public Element, public Storage { public: From 904a4f7632f267fd994f056d87b43927d2747138 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 29 Nov 2016 23:01:46 -0500 Subject: [PATCH 051/171] spelling error --- elements/standard/wgttqueue.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index b7dd8b996d..e9448f650d 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -32,7 +32,7 @@ CLICK_DECLS #define start_ap(p) *(p->data()+21) #define start_seq(p) *(p->data()+21) #define ap_score(p) *(p->data()+20) -#define sep(p) *(p->data()+20) +#define seq(p) *(p->data()+20) class WGTTQueue : public Element, public Storage { public: From c0403b7803a2dba8d1aa0a4a3e49aeefd5241fdc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 30 Nov 2016 09:09:42 -0500 Subject: [PATCH 052/171] data photo from 17 to 28 --- elements/standard/wgttqueue.hh | 2 +- elements/tcpudp/idadder.cc | 2 +- elements/tcpudp/idadder.hh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index e9448f650d..9f01854c87 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -10,7 +10,7 @@ CLICK_DECLS #define RING_SIZE 256 #define STATUS 4 -#define DATA 17 +#define DATA 0x1c #define CONTROL 27 #define IDLE 0 #define SWITCH_REQ 1 diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index ca0b0d400b..b620439534 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -55,7 +55,7 @@ IDAdder::initialize(ErrorHandler *errh) _iph->ip_hl = sizeof(click_ip) >> 2; _iph->ip_ttl = 250; _iph->ip_src.s_addr = CONTROLLER_IP; - _iph->ip_p = 17;//data msg + _iph->ip_p = DATA;//data msg _iph->ip_tos = 0; _iph->ip_off = 0; _iph->ip_sum = 0; diff --git a/elements/tcpudp/idadder.hh b/elements/tcpudp/idadder.hh index 26d7c2d93b..8bdc076ecf 100755 --- a/elements/tcpudp/idadder.hh +++ b/elements/tcpudp/idadder.hh @@ -11,7 +11,7 @@ CLICK_DECLS #define RING_SIZE 256 #define STATUS 4 -#define DATA 17 +#define DATA 0x1c #define CONTROL 6 #define IDLE 0 #define SWITCH_REQ 1 From ba67db8ed27a912475b520dae26ca99c0cbb5ae9 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 30 Nov 2016 10:41:32 -0500 Subject: [PATCH 053/171] remove printf --- elements/standard/wgttqueue.cc | 20 ++++++++++---------- elements/standard/wgttqueue.hh | 10 +++++----- elements/tcpudp/idadder.cc | 2 +- elements/tcpudp/packetselectionSerial.cc | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 75ce2f2dd7..86f9300fbe 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -89,7 +89,7 @@ WGTTQueue::initialize(ErrorHandler *errh) // printf("wgtt after !_q\n"); if (_q == 0) return errh->error("out of memory"); - printf("wgtt initialize succeed, ready to start\n"); + // printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -110,7 +110,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(ap_id(p_in) == CONTROLLER)//stop { - printf("wgttQueue: receive switch req\n"); + // printf("wgttQueue: receive switch req\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); @@ -132,16 +132,16 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); p_in -> kill(); - printf("wgttQueue send ap-ap seq\n"); + // printf("wgttQueue send ap-ap seq\n"); checked_output_push(1, p); } else { - printf("wgttQueue receive ap-ap seq\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); - printf("wgttQueue in dering-prepare\n"); + // printf("wgttQueue receive ap-ap seq\n"); + // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + // printf("wgttQueue in dering-prepare\n"); const unsigned char & start_seq = start_seq(p_in); while(_head != start_seq) { @@ -169,7 +169,7 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // printf("ap-c packet push\n"); _block = false; - printf("wgttQueue send switch ack\n"); + // printf("wgttQueue send switch ack\n"); checked_output_push(1, p); } @@ -181,12 +181,12 @@ void WGTTQueue::push_data(Packet *p_in) const unsigned char & seq = seq(p_in); while(_tail != seq) { - printf("wgttQueue in enring-prepare\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + // printf("wgttQueue in enring-prepare\n"); + // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); enRing(0); } p_in -> pull(21); - printf("wgttQueue enring, _head: %X, _tail: %X\n", _head, _tail); + // printf("wgttQueue enring, _head: %X, _tail: %X\n", _head, _tail); enRing(p_in); } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 9f01854c87..9051b7a8e2 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -98,11 +98,11 @@ WGTTQueue::deRing() return 0; Packet *p = _q[_head]; _head = (_head+1)%RING_SIZE; - if(p != 0) - { - printf("wgttQueue in pull\n"); - printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); - } + // if(p != 0) + // { + // printf("wgttQueue in pull\n"); + // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); + // } return p; } diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index b620439534..80f265f535 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -78,7 +78,7 @@ void IDAdder::push(int port, Packet *p_in) cp_ethernet_address(CONTROLLER_MAC, _ethh.ether_shost); } - printf("IDadder: counter: %X\n", counter); + // printf("IDadder: counter: %X\n", counter); _iph->ip_len = p_in->length()+sizeof(click_ip)+1; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index b661fcc1f0..52fc12bb1e 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -134,19 +134,19 @@ void PacketSelectionSerial::push_status(Packet *p_in) next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state - static unsigned char tmp_counter = 0; + // static unsigned char tmp_counter = 0; if(state[0] == IDLE) { - tmp_counter++; - printf("state idle\n"); + // tmp_counter++; + // printf("state idle\n"); unsigned char best_ap = find_best_ap(); //printf("best ap: %x\n", best_ap); - if(tmp_counter >= 20) - { - best_ap = 1; - } + // if(tmp_counter >= 20) + // { + // best_ap = 1; + // } if(best_ap != output_port[0]) { // send message From c7c949be5f9bc6522deefecdb73ae19abf3cdb4c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 1 Dec 2016 11:44:59 -0500 Subject: [PATCH 054/171] add print --- elements/standard/wgttqueue.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 86f9300fbe..dc5aa10aa0 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -89,7 +89,7 @@ WGTTQueue::initialize(ErrorHandler *errh) // printf("wgtt after !_q\n"); if (_q == 0) return errh->error("out of memory"); - // printf("wgtt initialize succeed, ready to start\n"); + printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -110,7 +110,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(ap_id(p_in) == CONTROLLER)//stop { - // printf("wgttQueue: receive switch req\n"); + printf("wgttQueue: receive switch req\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); @@ -132,14 +132,14 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); p_in -> kill(); - // printf("wgttQueue send ap-ap seq\n"); + printf("wgttQueue send ap-ap seq\n"); checked_output_push(1, p); } else { - // printf("wgttQueue receive ap-ap seq\n"); + printf("wgttQueue receive ap-ap seq\n"); // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); // printf("wgttQueue in dering-prepare\n"); const unsigned char & start_seq = start_seq(p_in); @@ -169,7 +169,7 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // printf("ap-c packet push\n"); _block = false; - // printf("wgttQueue send switch ack\n"); + printf("wgttQueue send switch ack\n"); checked_output_push(1, p); } From cfbd98bf3897ae7170b2bce0cdc08032d6c50ac5 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 1 Dec 2016 11:52:02 -0500 Subject: [PATCH 055/171] manually switch --- elements/tcpudp/packetselectionSerial.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 52fc12bb1e..a35b167cf6 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -134,19 +134,19 @@ void PacketSelectionSerial::push_status(Packet *p_in) next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state - // static unsigned char tmp_counter = 0; + static unsigned int tmp_counter = 0; if(state[0] == IDLE) { - // tmp_counter++; + tmp_counter++; // printf("state idle\n"); unsigned char best_ap = find_best_ap(); - //printf("best ap: %x\n", best_ap); - // if(tmp_counter >= 20) - // { - // best_ap = 1; - // } + printf("best ap: %x\n", best_ap); + if(tmp_counter >= 20) + { + best_ap = 1; + } if(best_ap != output_port[0]) { // send message From 483806b4814900837dbd3daa5cabc6d65b3ccf0a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 1 Dec 2016 12:01:06 -0500 Subject: [PATCH 056/171] configurable switch time --- elements/tcpudp/packetselectionSerial.cc | 33 ++++++++++++------------ elements/tcpudp/packetselectionSerial.hh | 3 ++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index a35b167cf6..8f0d800071 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -33,6 +33,7 @@ PacketSelectionSerial::PacketSelectionSerial() { int i,j; + interval = 20; score = new unsigned char*[n_ap]; next_score_id = new unsigned char[n_ap]; output_port = new unsigned char[n_client]; @@ -83,19 +84,16 @@ PacketSelectionSerial::~PacketSelectionSerial() -// int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) -// { -// // if (Args(conf, this, errh) -// // .read_p("ALPHA", DoubleArg(), alpha) -// // .read_p("FRESHTIME", IntArg(), fresh_time) -// // .read_p("BIGGERTIME", IntArg(), bigger_time) -// // .read_p("FIX", IntArg(), fix) -// // .complete() < 0) -// // return -1; +int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("INTERVAl", IntArg(), interval) + .complete() < 0) + return -1; -// return 0; -// } + return 0; +} void PacketSelectionSerial::push(int port, Packet *p_in) { @@ -141,12 +139,13 @@ void PacketSelectionSerial::push_status(Packet *p_in) { tmp_counter++; // printf("state idle\n"); - unsigned char best_ap = find_best_ap(); - printf("best ap: %x\n", best_ap); - if(tmp_counter >= 20) - { - best_ap = 1; - } + // unsigned char best_ap = find_best_ap(); + + // WGTT + unsigned char best_ap = output_port[0]; + if(!(tmp_counter%interval)) + best_ap = 1 - output_port[0]; + if(best_ap != output_port[0]) { // send message diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index a69074e4f9..5db2c79d13 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -42,7 +42,7 @@ class PacketSelectionSerial : public Element { public: const char *port_count() const { return "1/1"; } const char *flags() const { return "A"; } - // int configure(Vector &, ErrorHandler *) CLICK_COLD; + int configure(Vector &, ErrorHandler *) CLICK_COLD; void push(int port, Packet *p_in); void push_control(Packet *p_in); @@ -59,6 +59,7 @@ class PacketSelectionSerial : public Element { public: unsigned char *next_score_id; unsigned char *output_port; unsigned char control_content[2]; + int interval; click_ip _iph; click_ether * _ethh; From b204efd32e92402fa8b5a8090f5c0dc1d2477747 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 1 Dec 2016 12:18:27 -0500 Subject: [PATCH 057/171] comment ap print --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 8f0d800071..72a5e2e15a 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -126,7 +126,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) case AP2: a = 1; break; } // update_score(&ap_score(p_in), &c) - printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); + // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); score[a][next_score_id[a]] = ap_score(p_in); next_score_id[a] = (next_score_id[a] + 1)%n_compare; From ffda3475661865a448a79445e120f6f72d027112 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 1 Dec 2016 19:42:34 -0500 Subject: [PATCH 058/171] add reset code --- elements/standard/wgttqueue.cc | 15 +++++++++ elements/tcpudp/packetselectionSerial.cc | 41 ++++++++++++++++++++++-- elements/tcpudp/packetselectionSerial.hh | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index dc5aa10aa0..63a64c43c1 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -110,6 +110,20 @@ void WGTTQueue::push_control(Packet *p_in) { if(ap_id(p_in) == CONTROLLER)//stop { + if(ip_id(p_in) == 0xff) + { + printf("wgttQueue: receive reset req\n"); + _tail = 0; + _head = 0; + _block = (identity == 1)? false:true; + for(unsigned int i=0;i<256;i++) + { + if(_q[i] != 0) + _q[i] -> kill(); + } + } + else + { printf("wgttQueue: receive switch req\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); @@ -134,6 +148,7 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); printf("wgttQueue send ap-ap seq\n"); checked_output_push(1, p); + } } else diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 72a5e2e15a..57036718a5 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -73,6 +73,7 @@ PacketSelectionSerial::PacketSelectionSerial() _ethh->ether_type = htons(0x0800); bool result = cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_shost); + printf("Packetselection: init finish, ready to start\n"); } @@ -86,25 +87,61 @@ PacketSelectionSerial::~PacketSelectionSerial() int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) { + printf("PacketSelectionSerial in\n"); if (Args(conf, this, errh) - .read_p("INTERVAl", IntArg(), interval) + .read_p("INTERVAL", IntArg(), interval) .complete() < 0) return -1; - + printf("PacketSelectionSerial out. interval: %X\n", interval); return 0; } void PacketSelectionSerial::push(int port, Packet *p_in) { + static unsigned char lock = 0; + + if(!lock) + { + lock++; + reset_ap(); + } + // printf("pkt_type: %x\n", pkt_type(p_in)); switch(pkt_type(p_in)) { case CONTROL: push_control(p_in);break; case STATUS: push_status(p_in);break; } + } +void PacketSelectionSerial::reset_ap() +{ + for(int i=0;i<2;i++){ + WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = 0xff; + control_content[1] = 0xff; + memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + // //ip part + _iph.ip_dst.s_addr = (i == 0)? AP1_IP : AP2_IP; + + memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); + // p->set_ip_header(ip, sizeof(click_ip)); + //ether part + if(i == 0) + cp_ethernet_address(AP1_MAC, _ethh->ether_dhost); + else + cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); + memcpy(p->data(), _ethh, sizeof(click_ether)); + + + printf("controller reset ap %X\n", i); + output(0).push(p); + } +} void PacketSelectionSerial::push_control(Packet *p_in) diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index 5db2c79d13..a9c15ba78a 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -44,6 +44,7 @@ class PacketSelectionSerial : public Element { public: int configure(Vector &, ErrorHandler *) CLICK_COLD; + void reset_ap(); void push(int port, Packet *p_in); void push_control(Packet *p_in); void push_status(Packet *p_in); From 09416e352fda34f49323f61d91ca90282ff8f2ea Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 3 Dec 2016 12:45:33 -0500 Subject: [PATCH 059/171] test csisep --- elements/ip/csisep.cc | 51 +++++++++++++++++++++++++++++++++- elements/ip/csisep.hh | 1 + elements/standard/wgttqueue.cc | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index d077246623..5036c4247a 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -22,6 +22,7 @@ #include #include #include +#include "iwinfo.h" CLICK_DECLS CSISep::CSISep() @@ -41,6 +42,7 @@ CSISep::CSISep() // printf("little endian\n"); sprintf(shellcmd,"iwinfo wlan1 info | grep 'Signal'"); sample_counter = 0; + printf("CSISep: finish init\n"); // total_msg_cnt = 0; } @@ -103,11 +105,56 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) // csi_status->rssi_2 = buf_addr[22]; // } +int CSISep::get_rssi() +{ + printf("In get_rssi\n"); + int i, rv = 0, len; + const struct iwinfo_ops *iw; + char buf[IWINFO_BUFSIZE]; + struct iwinfo_assoclist_entry *e; + const char ifname[6] = "wlan1"; + + iw = iwinfo_backend(ifname); + + + if (!iw) + { + rv = 1; + } + else + { + if (iw->assoclist(ifname, buf, &len)) + { + rv = 2; + } + else if (len <= 0) + { + rv = 3; + } + else + { + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + { + e = (struct iwinfo_assoclist_entry *) &buf[i]; + + printf("RateSignal: %d\n", e->signal); + printf("RateNoise: %d\n", e->noise); + printf("RateRXRaw: %d\n", e->rx_rate); + printf("RateTXRaw: %d\n", e->tx_rate); + } + rv = 0; + } + } + iwinfo_finish(); + + return rv; +} void CSISep::fragment(Packet *p_in) { + get_rssi(); sample_counter ++; if(sample_counter>sample_rate) { @@ -136,6 +183,7 @@ CSISep::fragment(Packet *p_in) } } + // printf("CSISep: out fragment\n"); output(0).push(p_in); } @@ -143,10 +191,11 @@ CSISep::fragment(Packet *p_in) void CSISep::push(int, Packet *p) { + // printf("CSISep: in push\n"); fragment(p); } CLICK_ENDDECLS EXPORT_ELEMENT(CSISep) -ELEMENT_MT_SAFE(CSISep) +ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) \ No newline at end of file diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 984b0f13b5..57924d1a9f 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -44,6 +44,7 @@ class CSISep : public Element { public: void push(int, Packet *); void fragment(Packet *); + int get_rssi(); // int open_csi_device(); // void close_csi_device(int fd); // int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 63a64c43c1..39e60e9b4d 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -127,12 +127,12 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue: receive switch req\n"); _block = true; const unsigned char & dst_ap_id = start_ap(p_in); - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part control_content[0] = 135; control_content[1] = _head; + printf("wgttQueue: switch id: %X\n", _head); memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); // //ip part switch(dst_ap_id) From de303b2178ef5b6cad483a08617bc6d3abb4c628 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 4 Dec 2016 16:19:21 -0500 Subject: [PATCH 060/171] finish rssi interface --- elements/ip/csisep.cc | 165 +++++++++--------------------------------- elements/ip/csisep.hh | 54 ++++---------- 2 files changed, 51 insertions(+), 168 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 5036c4247a..072a09c88d 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -22,35 +22,32 @@ #include #include #include -#include "iwinfo.h" + + + CLICK_DECLS CSISep::CSISep() -{ - // csi_status = (csi_struct*)malloc(sizeof(csi_struct)); - // print_flag = true; - // fd = open_csi_device(); - // printf("This is a new version\n"); - // if (fd < 0) - // printf("Failed to open the device...\n"); - // else - // printf("#Receiving data!\n"); - // big_endian_flag = is_big_endian(); - // if(big_endian_flag) - // printf("big endian\n"); - // else - // printf("little endian\n"); - sprintf(shellcmd,"iwinfo wlan1 info | grep 'Signal'"); - sample_counter = 0; +{ +#ifndef __APPLE__ + + iw = iwinfo_backend(ifname); + if (!iw) + printf("CSISep: can not connect to backend iwinfo\n"); + if (iw->assoclist(ifname, buf, &len)) + printf("CSISep: can not find associlist\n"); + else if (len <= 0) + printf("CSISep: associ number < 0\n"); printf("CSISep: finish init\n"); // total_msg_cnt = 0; - +#endif } CSISep::~CSISep() { - // close_csi_device(fd); - // free(csi_status); +#ifndef __APPLE__ + iwinfo_finish(); +#endif } int @@ -60,139 +57,49 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) .read_p("SAMPLERATE", IntArg(), sample_rate) .complete() < 0) return -1; - + printf("CSISep: finish configure, ready to start\n"); return 0; } - -// int CSISep::open_csi_device(){ -// int fd; -// fd = open("/dev/CSI_dev",O_RDWR); -// return fd; -// } - -// void CSISep::close_csi_device(int fd){ -// close(fd); -// //remove("/dev/CSI_dev"); -// } - -// bool CSISep::is_big_endian() -// { -// unsigned int a = 0x1; -// unsigned char b = *(unsigned char *)&a; -// if ( b == 0) -// { -// return true; -// } -// return false; -// } - -// int CSISep::read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE){ -// int cnt; -// /* listen to the port -// * read when 1, a csi is reported from kernel -// * 2, time out -// */ -// cnt = read(fd,buf_addr,BUFSIZE); -// if(cnt) -// return cnt; -// else -// return 0; -// } -// void CSISep::record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status){ -// csi_status->rssi_0 = buf_addr[20]; -// csi_status->rssi_1 = buf_addr[21]; -// csi_status->rssi_2 = buf_addr[22]; -// } - -int CSISep::get_rssi() -{ - printf("In get_rssi\n"); - int i, rv = 0, len; - const struct iwinfo_ops *iw; - char buf[IWINFO_BUFSIZE]; - struct iwinfo_assoclist_entry *e; - const char ifname[6] = "wlan1"; - - iw = iwinfo_backend(ifname); - - - if (!iw) - { - rv = 1; - } - else - { - if (iw->assoclist(ifname, buf, &len)) - { - rv = 2; - } - else if (len <= 0) - { - rv = 3; - } - else - { - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) - { - e = (struct iwinfo_assoclist_entry *) &buf[i]; - - printf("RateSignal: %d\n", e->signal); - printf("RateNoise: %d\n", e->noise); - printf("RateRXRaw: %d\n", e->rx_rate); - printf("RateTXRaw: %d\n", e->tx_rate); - } - rv = 0; - } - } - - iwinfo_finish(); - - return rv; -} - void CSISep::fragment(Packet *p_in) { +#ifndef __APPLE__ + int i; get_rssi(); sample_counter ++; if(sample_counter>sample_rate) { sample_counter = 0; - if(NULL == (file = popen(shellcmd,"r"))) - { - // printf("execute command failed!"); - } - else - { - fgets(buffer, 100, file); - char * p = strchr(buffer, ':'); - // printf("the string buffer: %s\n", p+3); - uint8_t length = atoi(p+3); - // printf("The Signal length %hu\n", length); - if(length>0) + if(len>0) { - WritablePacket *p_csi = Packet::make(1); - memcpy(p_csi->data(), &length, 1); + WritablePacket *p_csi = Packet::make(sizeof(iwinfo_associlist_entry)*len); + + memcpy(p_csi->data(), buf, sizeof(iwinfo_assoclist_entry)*len); output(1).push(p_csi); + // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + // { + // e = (struct iwinfo_assoclist_entry *) &buf[i]; + // printf("RateSignal: %d\n", e->signal); + // printf("RateNoise: %d\n", e->noise); + // printf("RateRXRaw: %d\n", e->rx_rate); + // printf("RateTXRaw: %d\n", e->tx_rate); + // } } - pclose(file); - - } - } - - // printf("CSISep: out fragment\n"); +#endif output(0).push(p_in); - + } void CSISep::push(int, Packet *p) { +#ifndef __APPLE__ // printf("CSISep: in push\n"); fragment(p); +#endif } diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 57924d1a9f..b910292a30 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -5,31 +5,16 @@ #include #include #include -CLICK_DECLS - - -// typedef struct -// { -// int real; -// int imag; -// }COMPLEX; - -// typedef struct -// { -// uint64_t tstamp; /* h/w assigned time stamp */ - -// uint8_t rssi; /* rx frame RSSI */ -// uint8_t rssi_0; /* rx frame RSSI [ctl, chain 0] */ -// uint8_t rssi_1; rx frame RSSI [ctl, chain 1] -// uint8_t rssi_2; /* rx frame RSSI [ctl, chain 2] */ - -// uint16_t payload_len; /* payload length (bytes) */ -// uint16_t csi_len; /* csi data length (bytes) */ -// uint16_t buf_len; /* data length in buffer */ -// }csi_struct; +#ifndef __APPLE__ +extern "C" +{ + #include "iwinfo.h" +} +#endif +CLICK_DECLS class CSISep : public Element { public: @@ -45,29 +30,20 @@ class CSISep : public Element { public: void push(int, Packet *); void fragment(Packet *); int get_rssi(); - // int open_csi_device(); - // void close_csi_device(int fd); - // int read_csi_buf(unsigned char* buf_addr,int fd, int BUFSIZE); - // void record_status(unsigned char* buf_addr, int cnt, csi_struct* csi_status); - // bool is_big_endian(); private: - // static const uint32_t CSI_LEN = 280; - // csi_struct* csi_status; - // int fd; - // int total_msg_cnt; - - // unsigned char buf_addr[24]; - - // bool print_flag; - // bool big_endian_flag; - char shellcmd[64]; - char buffer[100]; - FILE *file; int sample_rate; int sample_counter; +#ifndef __APPLE__ + int len; + const struct iwinfo_ops *iw; + char buf[IWINFO_BUFSIZE]; + const char ifname[6] = "wlan1"; +#endif + + }; CLICK_ENDDECLS From 4670a5cd55868934d11e6a02d8eb171057daebd0 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 5 Dec 2016 10:46:59 -0500 Subject: [PATCH 061/171] debug --- elements/grid/airoinfo.cc | 304 +++++++++++++++++++------------------- elements/grid/airoinfo.hh | 18 +-- elements/ip/csisep.cc | 38 ++--- elements/ip/csisep.hh | 14 +- 4 files changed, 194 insertions(+), 180 deletions(-) diff --git a/elements/grid/airoinfo.cc b/elements/grid/airoinfo.cc index aa2acd85d3..3fe4d385b2 100644 --- a/elements/grid/airoinfo.cc +++ b/elements/grid/airoinfo.cc @@ -42,7 +42,7 @@ #endif #ifdef __linux__ -#include +// #include #ifdef IW_MAX_SPY #undef IW_MAX_SPY #define IW_MAX_SPY 40 /* more fuckation -- this constant must be the same across all the drivers as well */ @@ -74,18 +74,18 @@ AiroInfo::configure(Vector &conf, ErrorHandler *errh) int AiroInfo::initialize(ErrorHandler *errh) { - memset(&_ifr, 0, sizeof(_ifr)); - strncpy(_ifr.ifr_name, _ifname.c_str(), sizeof(_ifr.ifr_name)); - _ifr.ifr_name[sizeof(_ifr.ifr_name) - 1] = 0; -#ifdef __linux__ - memset(&_ifr2, 0, sizeof(_ifr2)); - strncpy(_ifr2.ifr_name, _ifname.c_str(), sizeof(_ifr2.ifr_name)); - _ifr2.ifr_name[sizeof(_ifr2.ifr_name) - 1] = 0; -#endif - - _fd = socket(AF_INET, SOCK_DGRAM, 0); - if (_fd < 0) - return errh->error("Unable to open socket to %s device", _ifr.ifr_name); +// memset(&_ifr, 0, sizeof(_ifr)); +// strncpy(_ifr.ifr_name, _ifname.c_str(), sizeof(_ifr.ifr_name)); +// _ifr.ifr_name[sizeof(_ifr.ifr_name) - 1] = 0; +// #ifdef __linux__ +// memset(&_ifr2, 0, sizeof(_ifr2)); +// strncpy(_ifr2.ifr_name, _ifname.c_str(), sizeof(_ifr2.ifr_name)); +// _ifr2.ifr_name[sizeof(_ifr2.ifr_name) - 1] = 0; +// #endif + +// _fd = socket(AF_INET, SOCK_DGRAM, 0); +// if (_fd < 0) +// return errh->error("Unable to open socket to %s device", _ifr.ifr_name); return 0; } @@ -95,36 +95,36 @@ AiroInfo::initialize(ErrorHandler *errh) bool AiroInfo::get_signal_info(const EtherAddress &e, int &dbm, int &quality) { - struct an_req areq; - memset(&areq, 0, sizeof(areq)); - - areq.an_len = AN_MAX_DATALEN; - areq.an_type = AN_RID_READ_CACHE; - - - /* due to AN_MAX_DATALEN = 512 16-bit vals, we could only ever get - ~56 entries from the card's cache. however, since the current - driver mod has only 30 entries, that's cool... but this could be - a problem in big (e.g. > 30 nodes) networks... */ - _ifr.ifr_data = (char *) &areq; - int res = ioctl(_fd, SIOCGAIRONET, &_ifr); - if (res == -1) { - click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading signal cache: %s\n", - strerror(errno)); - return false; - } - - int *num_entries = (int *) &areq.an_val; - char *p = (char *) &areq.an_val; - p += sizeof(int); - struct an_sigcache *entries = (struct an_sigcache *) p; - for (int i = 0; i < *num_entries; i++) { - if (e == EtherAddress((unsigned char *) entries[i].macsrc)) { - dbm = entries[i].signal; - quality = entries[i].quality; - return true; - } - } + // struct an_req areq; + // memset(&areq, 0, sizeof(areq)); + + // areq.an_len = AN_MAX_DATALEN; + // areq.an_type = AN_RID_READ_CACHE; + + + // /* due to AN_MAX_DATALEN = 512 16-bit vals, we could only ever get + // ~56 entries from the card's cache. however, since the current + // driver mod has only 30 entries, that's cool... but this could be + // a problem in big (e.g. > 30 nodes) networks... */ + // _ifr.ifr_data = (char *) &areq; + // int res = ioctl(_fd, SIOCGAIRONET, &_ifr); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading signal cache: %s\n", + // strerror(errno)); + // return false; + // } + + // int *num_entries = (int *) &areq.an_val; + // char *p = (char *) &areq.an_val; + // p += sizeof(int); + // struct an_sigcache *entries = (struct an_sigcache *) p; + // for (int i = 0; i < *num_entries; i++) { + // if (e == EtherAddress((unsigned char *) entries[i].macsrc)) { + // dbm = entries[i].signal; + // quality = entries[i].quality; + // return true; + // } + // } return false; } @@ -132,68 +132,68 @@ AiroInfo::get_signal_info(const EtherAddress &e, int &dbm, int &quality) bool AiroInfo::get_tx_stats(const EtherAddress &e, int &num_successful, int &num_failed) { - struct an_req areq; - memset(&areq, 0, sizeof(areq)); - - areq.an_len = AN_MAX_DATALEN; - areq.an_type = AN_RID_READ_LLFAIL; - - _ifr.ifr_data = (char *) &areq; - int res = ioctl(_fd, SIOCGAIRONET, &_ifr); - if (res == -1) { - click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading tx stats cache: %s\n", - strerror(errno)); - return false; - } - - int *num_entries = (int *) &areq.an_val; - char *p = (char *) &areq.an_val; - p += sizeof(int); - struct an_llfailcache *entries = (struct an_llfailcache *) p; - for (int i = 0; i < *num_entries; i++) { - if (e == EtherAddress((unsigned char *) entries[i].macdst)) { - num_failed = entries[i].num_fail; - num_successful = entries[i].num_succeed; - return true; - } - } + // struct an_req areq; + // memset(&areq, 0, sizeof(areq)); + + // areq.an_len = AN_MAX_DATALEN; + // areq.an_type = AN_RID_READ_LLFAIL; + + // _ifr.ifr_data = (char *) &areq; + // int res = ioctl(_fd, SIOCGAIRONET, &_ifr); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading tx stats cache: %s\n", + // strerror(errno)); + // return false; + // } + + // int *num_entries = (int *) &areq.an_val; + // char *p = (char *) &areq.an_val; + // p += sizeof(int); + // struct an_llfailcache *entries = (struct an_llfailcache *) p; + // for (int i = 0; i < *num_entries; i++) { + // if (e == EtherAddress((unsigned char *) entries[i].macdst)) { + // num_failed = entries[i].num_fail; + // num_successful = entries[i].num_succeed; + // return true; + // } + // } return false; } bool AiroInfo::get_noise(int &max_over_sec, int &avg_over_minute, int &max_over_minute) { - struct an_req areq; - memset(&areq, 0, sizeof(areq)); - - areq.an_len = AN_MAX_DATALEN; - areq.an_type = AN_RID_STATUS; - - _ifr.ifr_data = (char *) &areq; - int res = ioctl(_fd, SIOCGAIRONET, &_ifr); - if (res == -1) { - click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading noise from status struct: %s\n", - strerror(errno)); - return false; - } - - // noise info from Marco Molteni (molter@tin.it) - // u_int8_t an_noise_prev_sec_pc; /* 0x7A */ - // u_int8_t an_noise_prev_sec_db; /* 0x7B */ - // u_int8_t an_avg_noise_prev_min_pc; /* 0x7C */ - // u_int8_t an_avg_noise_prev_min_db; /* 0x7D */ - // u_int8_t an_max_noise_prev_min_pc; /* 0x7E */ - // u_int8_t an_max_noise_prev_min_db; /* 0x7F */ - - u_int8_t *base = (u_int8_t *) _ifr.ifr_data; - u_int8_t *u8 = base + 0x7B; - max_over_sec = *u8; - - u8 = base + 0x7D; - avg_over_minute = *u8; - - u8 = base + 0x7F; - max_over_minute = *u8; + // struct an_req areq; + // memset(&areq, 0, sizeof(areq)); + + // areq.an_len = AN_MAX_DATALEN; + // areq.an_type = AN_RID_STATUS; + + // _ifr.ifr_data = (char *) &areq; + // int res = ioctl(_fd, SIOCGAIRONET, &_ifr); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when reading noise from status struct: %s\n", + // strerror(errno)); + // return false; + // } + + // // noise info from Marco Molteni (molter@tin.it) + // // u_int8_t an_noise_prev_sec_pc; /* 0x7A */ + // // u_int8_t an_noise_prev_sec_db; /* 0x7B */ + // // u_int8_t an_avg_noise_prev_min_pc; /* 0x7C */ + // // u_int8_t an_avg_noise_prev_min_db; /* 0x7D */ + // // u_int8_t an_max_noise_prev_min_pc; /* 0x7E */ + // // u_int8_t an_max_noise_prev_min_db; /* 0x7F */ + + // u_int8_t *base = (u_int8_t *) _ifr.ifr_data; + // u_int8_t *u8 = base + 0x7B; + // max_over_sec = *u8; + + // u8 = base + 0x7D; + // avg_over_minute = *u8; + + // u8 = base + 0x7F; + // max_over_minute = *u8; return true; } @@ -203,29 +203,29 @@ AiroInfo::get_noise(int &max_over_sec, int &avg_over_minute, int &max_over_minut bool AiroInfo::get_signal_info(const EtherAddress &e, int &dbm, int &quality) { - char buf[(sizeof(struct iw_quality) + sizeof(struct sockaddr)) * IW_MAX_SPY]; - - _ifr.u.data.pointer = buf; - _ifr.u.data.length = 0; - _ifr.u.data.flags = 0; - int res = ioctl(_fd, SIOCGIWSPY, &_ifr); - if (res == -1) { - click_chatter("AiroInfo: ioctl(SIOCGIWSPY) error when reading signal info: %s\n", - strerror(errno)); - return false; - } - - int n = _ifr.u.data.length; - - for (int i = 0; i < n; i++) { - struct sockaddr *sa = (struct sockaddr *) (buf + i * sizeof(struct sockaddr)); - if (e == EtherAddress((unsigned char *) &sa->sa_data)) { - struct iw_quality *q = (struct iw_quality *) (buf + n*sizeof(struct sockaddr) + i*sizeof(struct iw_quality)); - dbm = ((int) q->level) - 256; - quality = q->qual; - return true; - } - } + // char buf[(sizeof(struct iw_quality) + sizeof(struct sockaddr)) * IW_MAX_SPY]; + + // _ifr.u.data.pointer = buf; + // _ifr.u.data.length = 0; + // _ifr.u.data.flags = 0; + // int res = ioctl(_fd, SIOCGIWSPY, &_ifr); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(SIOCGIWSPY) error when reading signal info: %s\n", + // strerror(errno)); + // return false; + // } + + // int n = _ifr.u.data.length; + + // for (int i = 0; i < n; i++) { + // struct sockaddr *sa = (struct sockaddr *) (buf + i * sizeof(struct sockaddr)); + // if (e == EtherAddress((unsigned char *) &sa->sa_data)) { + // struct iw_quality *q = (struct iw_quality *) (buf + n*sizeof(struct sockaddr) + i*sizeof(struct iw_quality)); + // dbm = ((int) q->level) - 256; + // quality = q->qual; + // return true; + // } + // } return false; } @@ -250,25 +250,25 @@ struct aironet_ioctl_t { bool AiroInfo::get_noise(int &max_over_sec, int &avg_over_minute, int &max_over_minute) { - u_int8_t buf[0x80]; - memset(buf, 69, sizeof(buf)); - - aironet_ioctl_t airo_cmd; - airo_cmd.command = AIROGSTAT; - airo_cmd.data = buf; - airo_cmd.len = sizeof(buf); - _ifr2.ifr_data = (char *) &airo_cmd; - - int res = ioctl(_fd, AIROIOCTL, &_ifr2); - if (res == -1) { - click_chatter("AiroInfo: ioctl(AIROIOCTL) error when reading noise info: %s\n", - strerror(errno)); - return false; - } - - max_over_sec = -buf[0x7B]; - avg_over_minute = -buf[0x7D]; - max_over_minute = -buf[0x7F]; + // u_int8_t buf[0x80]; + // memset(buf, 69, sizeof(buf)); + + // aironet_ioctl_t airo_cmd; + // airo_cmd.command = AIROGSTAT; + // airo_cmd.data = buf; + // airo_cmd.len = sizeof(buf); + // _ifr2.ifr_data = (char *) &airo_cmd; + + // int res = ioctl(_fd, AIROIOCTL, &_ifr2); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(AIROIOCTL) error when reading noise info: %s\n", + // strerror(errno)); + // return false; + // } + + // max_over_sec = -buf[0x7B]; + // avg_over_minute = -buf[0x7D]; + // max_over_minute = -buf[0x7F]; return true; } @@ -304,17 +304,17 @@ void AiroInfo::clear_tx_stats() { #ifdef __OpenBSD__ - struct an_req areq; - memset(&areq, 0, sizeof(areq)); - areq.an_len = 0; - areq.an_type = AN_RID_ZERO_LLFAIL; - - _ifr.ifr_data = (char *) &areq; - int res = ioctl(_fd, SIOCGAIRONET, &_ifr); - if (res == -1) { - click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when resetting tx stats cache: %s\n", - strerror(errno)); - } + // struct an_req areq; + // memset(&areq, 0, sizeof(areq)); + // areq.an_len = 0; + // areq.an_type = AN_RID_ZERO_LLFAIL; + + // _ifr.ifr_data = (char *) &areq; + // int res = ioctl(_fd, SIOCGAIRONET, &_ifr); + // if (res == -1) { + // click_chatter("AiroInfo: ioctl(SIOCGAIRONET) error when resetting tx stats cache: %s\n", + // strerror(errno)); + // } #endif } diff --git a/elements/grid/airoinfo.hh b/elements/grid/airoinfo.hh index 7f1d57a2d1..9e4ea64afb 100644 --- a/elements/grid/airoinfo.hh +++ b/elements/grid/airoinfo.hh @@ -4,14 +4,14 @@ #include #ifdef __linux__ #include -#include -#include +// #include +// #include #else /* OpenBSD 2.9 doesn't protect from multiple inclusion, but later versions do */ #ifndef CLICK_NET_IF_H #define CLICK_NET_IF_H -#include +// #include #endif #endif CLICK_DECLS @@ -69,12 +69,12 @@ private: int _fd; String _ifname; -#ifdef __linux__ - struct iwreq _ifr; - struct ifreq _ifr2; -#else - struct ifreq _ifr; -#endif +// #ifdef __linux__ +// struct iwreq _ifr; +// struct ifreq _ifr2; +// #else +// struct ifreq _ifr; +// #endif }; diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 072a09c88d..391fe0b6fa 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,18 +29,12 @@ CLICK_DECLS CSISep::CSISep() { -#ifndef __APPLE__ - - iw = iwinfo_backend(ifname); - if (!iw) - printf("CSISep: can not connect to backend iwinfo\n"); - if (iw->assoclist(ifname, buf, &len)) - printf("CSISep: can not find associlist\n"); - else if (len <= 0) - printf("CSISep: associ number < 0\n"); +#ifndef __APPLE__ + strcpy(ifname, "wlan0"); printf("CSISep: finish init\n"); // total_msg_cnt = 0; -#endif +#endif + } CSISep::~CSISep() @@ -53,20 +47,30 @@ CSISep::~CSISep() int CSISep::configure(Vector &conf, ErrorHandler *errh) { - if (Args(conf, this, errh) + if (Args(conf, this, errh) .read_p("SAMPLERATE", IntArg(), sample_rate) .complete() < 0) return -1; - printf("CSISep: finish configure, ready to start\n"); - return 0; + +#ifndef __APPLE__ + + iw = iwinfo_backend(ifname); + if (!iw) + printf("CSISep: can not connect to backend iwinfo\n"); + if (iw->assoclist(ifname, buf, &len)) + printf("CSISep: can not find associlist\n"); + else if (len <= 0) + printf("CSISep: associ number < 0\n"); +#endif + printf("CSISep: finish configure, ready to start\n"); + return 0; } void CSISep::fragment(Packet *p_in) { #ifndef __APPLE__ - int i; - get_rssi(); + // int i; sample_counter ++; if(sample_counter>sample_rate) { @@ -74,9 +78,9 @@ CSISep::fragment(Packet *p_in) if(len>0) { - WritablePacket *p_csi = Packet::make(sizeof(iwinfo_associlist_entry)*len); + WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*len); - memcpy(p_csi->data(), buf, sizeof(iwinfo_assoclist_entry)*len); + memcpy(p_csi->data(), buf, sizeof(my_test_struct)*len); output(1).push(p_csi); // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) // { diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index b910292a30..afcb760dd8 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -13,6 +13,17 @@ extern "C" } #endif +struct my_test_struct { + uint8_t mac[6]; + int8_t signal; + int8_t noise; + // uint32_t inactive; + // uint32_t rx_packets; + // uint32_t tx_packets; + // struct iwinfo_rate_entry rx_rate; + // struct iwinfo_rate_entry tx_rate; +}; + CLICK_DECLS @@ -29,7 +40,6 @@ class CSISep : public Element { public: void push(int, Packet *); void fragment(Packet *); - int get_rssi(); private: @@ -40,7 +50,7 @@ class CSISep : public Element { public: int len; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; - const char ifname[6] = "wlan1"; + char ifname[6]; #endif From f4881dc4828e67c9d03a374aba9a2a1178460cdb Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 6 Dec 2016 14:07:27 -0500 Subject: [PATCH 062/171] new ap_score --- elements/tcpudp/packetselectionSerial.cc | 1 + elements/tcpudp/packetselectionSerial.hh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 57036718a5..9eb28527e8 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -166,6 +166,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); score[a][next_score_id[a]] = ap_score(p_in); + printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index a9c15ba78a..b557b92ab5 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -28,7 +28,7 @@ CLICK_DECLS #define pkt_type(p) *(p->data()+9) #define ip_id(p) *(p->data()+20) #define ap_id(p) *(p->data()+15) -#define ap_score(p) *(p->data()+20) +#define ap_score(p) *(p->data()+26) From 863860281442aa290f34897518a43c9718a9c120 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 6 Dec 2016 17:13:48 -0500 Subject: [PATCH 063/171] modify --- elements/ip/csisep.cc | 10 +++++----- elements/tcpudp/packetselectionSerial.cc | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 391fe0b6fa..eff06e57fa 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -57,10 +57,6 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) iw = iwinfo_backend(ifname); if (!iw) printf("CSISep: can not connect to backend iwinfo\n"); - if (iw->assoclist(ifname, buf, &len)) - printf("CSISep: can not find associlist\n"); - else if (len <= 0) - printf("CSISep: associ number < 0\n"); #endif printf("CSISep: finish configure, ready to start\n"); return 0; @@ -76,7 +72,11 @@ CSISep::fragment(Packet *p_in) { sample_counter = 0; - if(len>0) + if (iw->assoclist(ifname, buf, &len)) + printf("CSISep: can not find associlist\n"); + else if (len <= 0) + printf("CSISep: associ number < 0\n"); + else { WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*len); diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 9eb28527e8..1575fe83b9 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -165,8 +165,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) // update_score(&ap_score(p_in), &c) // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); - score[a][next_score_id[a]] = ap_score(p_in); - printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); + // score[a][next_score_id[a]] = ap_score(p_in); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state @@ -176,13 +175,15 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(state[0] == IDLE) { tmp_counter++; + if(tmp_counter%100==0) + printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("state idle\n"); - // unsigned char best_ap = find_best_ap(); + unsigned char best_ap = find_best_ap(); // WGTT - unsigned char best_ap = output_port[0]; - if(!(tmp_counter%interval)) - best_ap = 1 - output_port[0]; + // unsigned char best_ap = output_port[0]; + // if(!(tmp_counter%interval)) + // best_ap = 1 - output_port[0]; if(best_ap != output_port[0]) { From 6e20d95804716268fded74900c96e11ef27dcf69 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 6 Dec 2016 17:20:51 -0500 Subject: [PATCH 064/171] enable update score --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 1575fe83b9..5480039c3a 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -165,7 +165,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) // update_score(&ap_score(p_in), &c) // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); - // score[a][next_score_id[a]] = ap_score(p_in); + score[a][next_score_id[a]] = ap_score(p_in); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state From 79fcb53519378e7e3fb7309020cd19b9d5f2643f Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 7 Dec 2016 09:41:28 -0500 Subject: [PATCH 065/171] more log to debug switch --- elements/standard/wgttqueue.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 39e60e9b4d..d06f9bda5b 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -164,7 +164,7 @@ void WGTTQueue::push_control(Packet *p_in) _q[_head] -> kill(); _head = (_head+1)%RING_SIZE; } - + printf("wgttQueue finish ap-ap dequeue\n"); WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); @@ -192,7 +192,7 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { - // printf("wgttQueue in push data\n"); + printf("wgttQueue in push data\n"); const unsigned char & seq = seq(p_in); while(_tail != seq) { @@ -201,7 +201,7 @@ void WGTTQueue::push_data(Packet *p_in) enRing(0); } p_in -> pull(21); - // printf("wgttQueue enring, _head: %X, _tail: %X\n", _head, _tail); + printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head, _tail); enRing(p_in); } From 1f6c47a2e8095228d127e2a61040d5294b6c4a80 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 7 Dec 2016 23:48:12 -0500 Subject: [PATCH 066/171] new click --- elements/ip/csisep.cc | 47 ++++-- elements/ip/csisep.hh | 10 +- elements/standard/apswitchserial.cc | 175 ----------------------- elements/standard/apswitchserial.hh | 124 ---------------- elements/standard/wgttqueue.cc | 79 ++++------ elements/standard/wgttqueue.hh | 30 +--- elements/tcpudp/idadder.cc | 59 +++----- elements/tcpudp/idadder.hh | 30 +--- elements/tcpudp/packetselectionSerial.cc | 161 +++++++++++---------- elements/tcpudp/packetselectionSerial.hh | 26 +--- include/clicknet/wgtt.h | 58 ++++++++ 11 files changed, 232 insertions(+), 567 deletions(-) delete mode 100644 elements/standard/apswitchserial.cc delete mode 100644 elements/standard/apswitchserial.hh create mode 100644 include/clicknet/wgtt.h diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index eff06e57fa..cd9b756a17 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -30,7 +30,6 @@ CLICK_DECLS CSISep::CSISep() { #ifndef __APPLE__ - strcpy(ifname, "wlan0"); printf("CSISep: finish init\n"); // total_msg_cnt = 0; #endif @@ -47,13 +46,20 @@ CSISep::~CSISep() int CSISep::configure(Vector &conf, ErrorHandler *errh) { + int wlan_port; if (Args(conf, this, errh) .read_p("SAMPLERATE", IntArg(), sample_rate) + .read_p("WLANPORT", IntArg(), wlan_port) .complete() < 0) return -1; #ifndef __APPLE__ - + if(wlan_port == 0) + strcpy(ifname, "wlan0"); + else if(wlan_port == 1) + strcpy(ifname, "wlan0"); + else + printf("Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) printf("CSISep: can not connect to backend iwinfo\n"); @@ -66,7 +72,7 @@ void CSISep::fragment(Packet *p_in) { #ifndef __APPLE__ - // int i; + int i, j=0; sample_counter ++; if(sample_counter>sample_rate) { @@ -78,18 +84,27 @@ CSISep::fragment(Packet *p_in) printf("CSISep: associ number < 0\n"); else { - WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*len); + WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - memcpy(p_csi->data(), buf, sizeof(my_test_struct)*len); + output(1).push(p_csi); - // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) - // { - // e = (struct iwinfo_assoclist_entry *) &buf[i]; - // printf("RateSignal: %d\n", e->signal); - // printf("RateNoise: %d\n", e->noise); - // printf("RateRXRaw: %d\n", e->rx_rate); - // printf("RateTXRaw: %d\n", e->tx_rate); - // } + for (i = 0; i < N_CLIENT; i += sizeof(struct iwinfo_assoclist_entry)) + { + e = (struct iwinfo_assoclist_entry *) &buf[i]; + memcpy(p_csi->data()+j, &(e->signal), sizeof(my_test_struct.signal)); + j += sizeof(my_test_struct.signal); + memcpy(p_csi->data()+j, &(e->noise), sizeof(my_test_struct.noise)); + j += sizeof(my_test_struct.noise); + memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(my_test_struct.rx_rate)); + j += sizeof(my_test_struct.rx_rate); + memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(my_test_struct.tx_rate)); + j += sizeof(my_test_struct.tx_rate); + + printf("RateSignal: %d\n", e->signal); + printf("RateNoise: %d\n", e->noise); + printf("RateRXRaw: %d\n", e->rx_rate); + printf("RateTXRaw: %d\n", e->tx_rate); + } } } #endif @@ -109,4 +124,8 @@ CSISep::push(int, Packet *p) CLICK_ENDDECLS EXPORT_ELEMENT(CSISep) -ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) \ No newline at end of file +ELEMENT_MT_SAFE(CSISep) +#ifndef __APPLE__ +ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) +#endif + diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index afcb760dd8..15a259f366 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -14,14 +14,12 @@ extern "C" #endif struct my_test_struct { - uint8_t mac[6]; + uint8_t mac; int8_t signal; int8_t noise; - // uint32_t inactive; - // uint32_t rx_packets; - // uint32_t tx_packets; - // struct iwinfo_rate_entry rx_rate; - // struct iwinfo_rate_entry tx_rate; + uint32_t rx_rate; + uint32_t tx_rate; + }; diff --git a/elements/standard/apswitchserial.cc b/elements/standard/apswitchserial.cc deleted file mode 100644 index cf4406a97f..0000000000 --- a/elements/standard/apswitchserial.cc +++ /dev/null @@ -1,175 +0,0 @@ -// -*- c-basic-offset: 4 -*- -/* - * simplequeue.{cc,hh} -- queue element - * Eddie Kohler - * - * Copyright (c) 1999-2000 Massachusetts Institute of Technology - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, subject to the conditions - * listed in the Click LICENSE file. These conditions include: you must - * preserve this copyright notice, and you cannot mention the copyright - * holders in advertising related to the Software without their permission. - * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This - * notice is a summary of the Click LICENSE file; the license in that file is - * legally binding. - */ - -#include -#include "apswitchserial.hh" -#include -#include -CLICK_DECLS - -APSwitchSerial::APSwitchSerial() -{ - _q = new Packet*[RING_SIZE]; - _head = 0; - _tail = 0; - _qControl = new Packet*[QUEUE_SIZE]; - _headControl = 0; - _tailControl = 0; -} - -APSwitchSerial::~APSwitchSerial() -{ - -} - - -int -APSwitchSerial::configure(Vector &conf, ErrorHandler *errh) -{ - if (Args(conf, this, errh) - .read_p("IDENTITY", IntArg(), identity) - .complete() < 0) - return -1; - if(identity==1) - _block = false; - else - _block = true; - - - //TODO: checksum not set - memset(&_iph, 0, sizeof(click_ip)); - _iph.ip_v = 4; - _iph.ip_hl = sizeof(click_ip) >> 2; - _iph.ip_ttl = 250; - switch(identity) - { - case 1: _iph.ip_src.s_addr = AP1_IP;break; - case 2: _iph.ip_src.s_addr = AP2_IP;break; - } - _iph.ip_p = 6;//control msg - _iph.ip_tos = 0; - _iph.ip_off = 0; - _iph.ip_sum = 0; - _iph.ip_len = htons(22); - - - _ethh = new click_ether; - - _ethh->ether_type = htons(0x0800); - switch(identity) - { - case 1: cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; - case 2: cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; - } - - return 0; -} - -void -APSwitchSerial::push(int, Packet *p_in) -{ - switch(pkt_type(p_in)) - { - case CONTROL: push_control(p_in);break; - case DATA: push_data(p_in);break; - } -} - - -void APSwitchSerial::push_control(Packet *p_in) -{ - if(ap_id(p_in) == CONTROLLER)//stop - { - _block = true; - const unsigned char & dst_ap_id = start_ap(p_in); - - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); - // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); - // // data part - control_content[0] = 135; - control_content[1] = _head; - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); - // //ip part - switch(dst_ap_id) - { - case 1: _iph.ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 2: _iph.ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; - } - memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); - //ether part - memcpy(p->data(), _ethh, sizeof(click_ether)); - - enque(p); - printf("ap2ap packet push\n"); - } - else - { - const unsigned char & start_seq = start_seq(p_in); - while(_head != start_seq) - deRing(); - - - - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); - // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); - // // data part - control_content[0] = 135; - control_content[1] = 0; - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); - // //ip part - _iph.ip_dst.s_addr = CONTROLLER_IP;cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_dhost); - - memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); - //ether part - memcpy(p->data(), _ethh, sizeof(click_ether)); - - enque(p); - printf("ap-c packet push\n"); - _block = false; - - } -} - -void APSwitchSerial::push_data(Packet *p_in) -{ - unsigned char seq = start_seq(p_in); - p_in -> take(1); - while(_tail != seq) - enRing(0); - enRing(p_in); -} - - - - -Packet * -APSwitchSerial::pull(int port) -{ - if(port == 0) - return deRing(); - else - return deque(); -} - - - -CLICK_ENDDECLS -EXPORT_ELEMENT(APSwitchSerial) -ELEMENT_MT_SAFE(APSwitchSerial) diff --git a/elements/standard/apswitchserial.hh b/elements/standard/apswitchserial.hh deleted file mode 100644 index b0332a4e96..0000000000 --- a/elements/standard/apswitchserial.hh +++ /dev/null @@ -1,124 +0,0 @@ -// -*- c-basic-offset: 4 -*- -#ifndef CLICK_APSWITCHSERIAL_HH -#define CLICK_APSWITCHSERIAL_HH -#include -#include -#include -#include -CLICK_DECLS - -#define RING_SIZE 256 -#define QUEUE_SIZE 256 -#define STATUS 4 -#define DATA 17 -#define CONTROL 6 -#define IDLE 0 -#define SWITCH_REQ 1 -#define CLIENT1 135 -#define CONTROLLER 1 -#define AP1 2 -#define AP2 4 -#define IP_BASE 0x01a8c0 -#define AP1_IP 0x0201a8c0 -#define AP2_IP 0x0401a8c0 -#define CONTROLLER_IP 0x0101a8c0 -#define AP1_MAC "C0:56:27:72:A3:5B" -#define AP2_MAC "60:38:E0:03:FA:0B" -#define CONTROLLER_MAC "38:c9:86:40:c8:05" - -#define pkt_type(p) *(p->data()+9) -#define ip_id(p) *(p->data()+20) -#define ap_id(p) *(p->data()+15) -#define start_ap(p) *(p->data()+21) -#define start_seq(p) *(p->data()+21) -#define ap_score(p) *(p->data()+20) - - -class APSwitchSerial : public Element { public: - - APSwitchSerial() CLICK_COLD; - ~APSwitchSerial() CLICK_COLD; - - inline void enRing(Packet*);//flag: whether override - inline Packet* deRing(); - inline void enque(Packet*);//flag: whether override - inline Packet* deque(); - - const char *class_name() const { return "APSwitchSerial"; } - const char *port_count() const { return "1/2"; } - const char *processing() const { return "h/lh"; } - - int configure(Vector&, ErrorHandler*) CLICK_COLD; - - void push(int port, Packet*); - void push_control(Packet *p_in); - void push_data(Packet *p_in); - - Packet* pull(int port); - - private: - - Packet* volatile * _q; - Packet* volatile * _qControl; - volatile unsigned char _head; - volatile unsigned char _tail; - - volatile unsigned char _headControl; - volatile unsigned char _tailControl; - - volatile bool _block; - unsigned char identity; - unsigned char control_content[2]; - - click_ip _iph; - click_ether * _ethh; - -}; - - -inline void -APSwitchSerial::enRing(Packet *p) -{ - if((_tail+1)%RING_SIZE == _head)//override - { - _q[_head] -> kill(); - _head = (_head+1)%RING_SIZE; - } - _q[_tail] = p; - _tail = (_tail+1)%RING_SIZE; -} - -inline Packet * -APSwitchSerial::deRing() -{ - if(_block || _head==_tail) - return 0; - Packet *p = _q[_head]; - _head = (_head+1)%RING_SIZE; - return p; -} - -inline void -APSwitchSerial::enque(Packet *p) -{ - if((_tailControl+1)%QUEUE_SIZE == _headControl)//override - { - _qControl[_headControl] -> kill(); - _headControl = (_headControl+1)%QUEUE_SIZE; - } - _qControl[_tailControl] = p; - _tailControl = (_tailControl+1)%QUEUE_SIZE; -} - -inline Packet * -APSwitchSerial::deque() -{ - if(_headControl==_tailControl) - return 0; - Packet *p = _qControl[_headControl]; - _headControl = (_headControl+1)%QUEUE_SIZE; - return p; -} - -CLICK_ENDDECLS -#endif diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index d06f9bda5b..03df972961 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -26,8 +26,7 @@ WGTTQueue::WGTTQueue() { _head = 0; _tail = 0; - _iph = (click_ip*)CLICK_LALLOC(sizeof(click_ip)); - _ethh = (click_ether*)CLICK_LALLOC(sizeof(click_ether)); + _ethh = new click_ether[N_AP+1]; _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); printf("wgtt init succeed\n"); } @@ -59,30 +58,18 @@ WGTTQueue::initialize(ErrorHandler *errh) else _block = true; - // printf("After configure _block\n"); - //TODO: checksum not set - memset(_iph, 0, sizeof(click_ip)); - _iph->ip_v = 4; - _iph->ip_hl = sizeof(click_ip) >> 2; - _iph->ip_ttl = 250; - switch(identity) - { - case 1: _iph->ip_src.s_addr = AP1_IP;break; - case 2: _iph->ip_src.s_addr = AP2_IP;break; - } - _iph->ip_p = 27;//control msg - _iph->ip_tos = 0; - _iph->ip_off = 0; - _iph->ip_sum = 0; - _iph->ip_len = htons(22); - - _ethh->ether_type = htons(0x0800); + _ethh->ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); // printf("identity: %X\n", identity); - switch(identity) + + for(int i=0; i < N_AP+1; i++) { - case 1: cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; - case 2: cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; + switch(identity) + { + case 0: cp_ethernet_address(AP0_MAC, _ethh[i].ether_shost);break; + case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + } } assert(_head == 0 && _tail == 0); @@ -101,16 +88,16 @@ WGTTQueue::push(int, Packet *p_in) // printf("wgttQueue in push\n"); switch(pkt_type(p_in)) { - case CONTROL: push_control(p_in);break; - case DATA: push_data(p_in);break; + case CONTROL_SUFFIX: push_control(p_in);break; + case DATA_SUFFIX: push_data(p_in);break; } } void WGTTQueue::push_control(Packet *p_in) { - if(ap_id(p_in) == CONTROLLER)//stop + if(status_ap(p_in) == CONTROLLER_IN_MAC_SUFFIX)//stop { - if(ip_id(p_in) == 0xff) + if(client_ip(p_in) == 0xff) { printf("wgttQueue: receive reset req\n"); _tail = 0; @@ -126,24 +113,20 @@ void WGTTQueue::push_control(Packet *p_in) { printf("wgttQueue: receive switch req\n"); _block = true; - const unsigned char & dst_ap_id = start_ap(p_in); - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); - // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + const unsigned char & dst_ap = start_ap(p_in); + WritablePacket *p = Packet::make(sizeof(click_ether)+2); // // data part - control_content[0] = 135; + control_content[0] = 0; control_content[1] = _head; printf("wgttQueue: switch id: %X\n", _head); - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); + memcpy(p->data()+sizeof(click_ether), &control_content, 2); // //ip part - switch(dst_ap_id) + switch(dst_ap) { - case 0: _iph->ip_dst.s_addr = AP1_IP;cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 1: _iph->ip_dst.s_addr = AP2_IP;cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 0: memcpy(p->data(), &(_ethh[0]), sizeof(click_ether));break; + case 1: memcpy(p->data(), &(_ethh[1]), sizeof(click_ether));break; + case 2: memcpy(p->data(), &(_ethh[2]), sizeof(click_ether));break; } - memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); - //ether part - memcpy(p->data(), _ethh, sizeof(click_ether)); p_in -> kill(); printf("wgttQueue send ap-ap seq\n"); @@ -167,19 +150,15 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue finish ap-ap dequeue\n"); - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = 135; + control_content[0] = 0; control_content[1] = 0; - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); - // //ip part - _iph->ip_dst.s_addr = CONTROLLER_IP;cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_dhost); - - memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); + memcpy(p->data()+sizeof(click_ether), &control_content, 2); + //ether part - memcpy(p->data(), _ethh, sizeof(click_ether)); + memcpy(p->data(), &(_ethh[N_AP]), sizeof(click_ether)); p_in -> kill(); // printf("ap-c packet push\n"); @@ -193,14 +172,14 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { printf("wgttQueue in push data\n"); - const unsigned char & seq = seq(p_in); + const unsigned char & seq = queue_seq(p_in); while(_tail != seq) { // printf("wgttQueue in enring-prepare\n"); // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); enRing(0); } - p_in -> pull(21); + p_in -> pull(15); printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head, _tail); enRing(p_in); } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 9051b7a8e2..4826db0881 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -3,36 +3,13 @@ #define CLICK_WGTTQUEUE_HH #include #include -#include #include #include +#include CLICK_DECLS -#define RING_SIZE 256 -#define STATUS 4 -#define DATA 0x1c -#define CONTROL 27 -#define IDLE 0 -#define SWITCH_REQ 1 -#define CLIENT1 135 -#define CONTROLLER 1 -#define AP1 2 -#define AP2 4 -#define IP_BASE 0x01a8c0 -#define AP1_IP 0x0201a8c0 -#define AP2_IP 0x0401a8c0 -#define CONTROLLER_IP 0x0101a8c0 -#define AP1_MAC "C0:56:27:72:A3:5B" -#define AP2_MAC "60:38:E0:03:FA:0B" -#define CONTROLLER_MAC "38:c9:86:40:c8:05" - -#define pkt_type(p) *(p->data()+9) -#define ip_id(p) *(p->data()+20) -#define ap_id(p) *(p->data()+15) -#define start_ap(p) *(p->data()+21) -#define start_seq(p) *(p->data()+21) -#define ap_score(p) *(p->data()+20) -#define seq(p) *(p->data()+20) + + class WGTTQueue : public Element, public Storage { public: @@ -67,7 +44,6 @@ class WGTTQueue : public Element, public Storage { public: unsigned char identity; unsigned char control_content[2]; - click_ip * _iph; click_ether * _ethh; }; diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 80f265f535..432e98d61c 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -33,7 +33,6 @@ IDAdder::IDAdder() { // printf("idadder in init\n"); counter = 0; - _iph = (click_ip*)CLICK_LALLOC(sizeof(click_ip)); printf("idadder init finish\n"); @@ -49,18 +48,6 @@ IDAdder::~IDAdder() int IDAdder::initialize(ErrorHandler *errh) { - - memset(_iph, 0, sizeof(click_ip)); - _iph->ip_v = 4; - _iph->ip_hl = sizeof(click_ip) >> 2; - _iph->ip_ttl = 250; - _iph->ip_src.s_addr = CONTROLLER_IP; - _iph->ip_p = DATA;//data msg - _iph->ip_tos = 0; - _iph->ip_off = 0; - _iph->ip_sum = 0; - - printf("idadder initial finish, ready to start\n"); return 0; @@ -70,52 +57,40 @@ IDAdder::initialize(ErrorHandler *errh) void IDAdder::push(int port, Packet *p_in) { // printf("idadder in push\n"); - static unsigned char tmp_counter = 0; - if(tmp_counter ==0) + static bool lock = false; + if(!false) { - tmp_counter++; - _ethh.ether_type = htons(0x0800); - cp_ethernet_address(CONTROLLER_MAC, _ethh.ether_shost); - + lock = true; + _ethh.ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); + cp_ethernet_address(CONTROLLER_IN_MAC, _ethh.ether_shost); } // printf("IDadder: counter: %X\n", counter); - - _iph->ip_len = p_in->length()+sizeof(click_ip)+1; - p_in->push(sizeof(click_ip)+sizeof(click_ether)+1); - for(int i = 0;i<1;i++) + p_in->push(sizeof(click_ether)+1); + for(int i = 1;iclone(); WritablePacket *p = p_tmp->uniqueify(); - if(i == 0) - { - _iph->ip_dst.s_addr = AP1_IP; - cp_ethernet_address(AP1_MAC, _ethh.ether_dhost); - } - else - { - _iph->ip_dst.s_addr = AP2_IP; - cp_ethernet_address(AP2_MAC, _ethh.ether_dhost); - } - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); - memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + switch(i) + { + case 0:cp_ethernet_address(AP0_MAC, _ethh.ether_dhost);break; + case 1:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; + case 2:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; + } + + memcpy(p->data()+sizeof(click_ether), &counter, 1); memcpy(p->data(), &_ethh, sizeof(click_ether)); // printf("idadder push %dth\n", i); output(0).push(p); } WritablePacket *p = p_in->uniqueify(); - _iph->ip_dst.s_addr = AP2_IP; - cp_ethernet_address(AP2_MAC, _ethh.ether_dhost); - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &counter, 1); - memcpy(p->data()+sizeof(click_ether), _iph, sizeof(click_ip)); + cp_ethernet_address(AP0_MAC, _ethh.ether_dhost); + memcpy(p->data()+sizeof(click_ether), &counter, 1); memcpy(p->data(), &_ethh, sizeof(click_ether)); counter ++; output(0).push(p); - - - } diff --git a/elements/tcpudp/idadder.hh b/elements/tcpudp/idadder.hh index 8bdc076ecf..0e356edeb4 100755 --- a/elements/tcpudp/idadder.hh +++ b/elements/tcpudp/idadder.hh @@ -3,38 +3,11 @@ #include #include #include -#include #include - +#include CLICK_DECLS -#define RING_SIZE 256 -#define STATUS 4 -#define DATA 0x1c -#define CONTROL 6 -#define IDLE 0 -#define SWITCH_REQ 1 -#define CLIENT1 135 -#define CONTROLLER 1 -#define AP1 2 -#define AP2 4 -#define IP_BASE 0x01a8c0 -#define AP1_IP 0x0201a8c0 -#define AP2_IP 0x0401a8c0 -#define CONTROLLER_IP 0x0101a8c0 -#define AP1_MAC "C0:56:27:72:A3:5B" -#define AP2_MAC "60:38:E0:03:FA:0B" -#define CONTROLLER_MAC "38:c9:86:40:c8:05" - -#define pkt_type(p) *(p->data()+9) -#define ip_id(p) *(p->data()+20) -#define ap_id(p) *(p->data()+15) -#define start_ap(p) *(p->data()+21) -#define start_seq(p) *(p->data()+21) -#define ap_score(p) *(p->data()+20) - - class IDAdder : public Element { public: @@ -54,7 +27,6 @@ class IDAdder : public Element { public: private: unsigned char counter; - click_ip * _iph; click_ether _ethh; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 5480039c3a..8cba21e3fc 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include CLICK_DECLS @@ -34,45 +33,32 @@ PacketSelectionSerial::PacketSelectionSerial() { int i,j; interval = 20; - score = new unsigned char*[n_ap]; - next_score_id = new unsigned char[n_ap]; - output_port = new unsigned char[n_client]; - for(i=0; i> 2; - _iph.ip_ttl = 250; - _iph.ip_src.s_addr = CONTROLLER_IP; - _iph.ip_p = 27;//control msg - _iph.ip_tos = 0; - _iph.ip_off = 0; - _iph.ip_sum = 0; - _iph.ip_len = htons(22); - - _ethh = new click_ether; - _ethh->ether_type = htons(0x0800); - bool result = cp_ethernet_address(CONTROLLER_MAC, _ethh->ether_shost); + _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); + bool result = cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); printf("Packetselection: init finish, ready to start\n"); @@ -110,34 +96,29 @@ void PacketSelectionSerial::push(int port, Packet *p_in) // printf("pkt_type: %x\n", pkt_type(p_in)); switch(pkt_type(p_in)) { - case CONTROL: push_control(p_in);break; - case STATUS: push_status(p_in);break; + case CONTROL_SUFFIX: push_control(p_in);break; + case STATUS_SUFFIX: push_status(p_in);break; } } void PacketSelectionSerial::reset_ap() { - for(int i=0;i<2;i++){ - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); - // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + for(int i=0;idata()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); - // //ip part - _iph.ip_dst.s_addr = (i == 0)? AP1_IP : AP2_IP; - - memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); + control_content[0] = RESET_CONTENT; + control_content[1] = RESET_CONTENT; + memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - if(i == 0) - cp_ethernet_address(AP1_MAC, _ethh->ether_dhost); - else - cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); + switch(i) + { + case 0:cp_ethernet_address(AP0_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data(), _ethh, sizeof(click_ether)); - - printf("controller reset ap %X\n", i); output(0).push(p); } @@ -146,8 +127,9 @@ void PacketSelectionSerial::reset_ap() void PacketSelectionSerial::push_control(Packet *p_in) { - unsigned char c = 0; - state[c] = IDLE; + const unsigned char & c = client_ip(p_in); + printf("switch request ack ip: %X.\n", c); + state[c-CLIENT0_IP_SUFFIX] = IDLE; printf("switch request ack.\n"); p_in -> kill(); } @@ -155,17 +137,12 @@ void PacketSelectionSerial::push_control(Packet *p_in) void PacketSelectionSerial::push_status(Packet *p_in) { //printf("In push status.\n"); - unsigned char a; - //printf("ap id: %x\n", ap_id(p_in)); - switch(ap_id(p_in)) - { - case AP1: a = 0; break; - case AP2: a = 1; break; - } - // update_score(&ap_score(p_in), &c) + const unsigned char &a = status_ap(p_in); // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); - score[a][next_score_id[a]] = ap_score(p_in); + //since the score are minus, we minus again + score[a][next_score_id[a]] = - ap_score(p_in); + printf("current score: %d\n", score[a][next_score_id[a]]); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state @@ -176,7 +153,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) { tmp_counter++; if(tmp_counter%100==0) - printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); + printf("ap id: %x, score: %x\n", status_ap(p_in), ap_score(p_in)); // printf("state idle\n"); unsigned char best_ap = find_best_ap(); @@ -189,22 +166,19 @@ void PacketSelectionSerial::push_status(Packet *p_in) { // send message // send_meg(best_ap) - WritablePacket *p = Packet::make(sizeof(click_ether)+sizeof(click_ip)+2); + WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = 135; + control_content[0] = 0; control_content[1] = best_ap; - memcpy(p->data()+sizeof(click_ether)+sizeof(click_ip), &control_content, 2); - // //ip part - _iph.ip_dst.s_addr = (output_port[0] == 0)? AP1_IP : AP2_IP; - - memcpy(p->data()+sizeof(click_ether), &_iph, sizeof(click_ip)); - // p->set_ip_header(ip, sizeof(click_ip)); + memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - if(output_port[0] == 0) - cp_ethernet_address(AP1_MAC, _ethh->ether_dhost); - else - cp_ethernet_address(AP2_MAC, _ethh->ether_dhost); + switch(best_ap) + { + case 0:cp_ethernet_address(AP0_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + } memcpy(p->data(), _ethh, sizeof(click_ether)); @@ -223,19 +197,54 @@ void PacketSelectionSerial::push_status(Packet *p_in) unsigned char PacketSelectionSerial::find_best_ap() { unsigned char ¤t = output_port[0]; - unsigned char potential = (current+1)%2; - bool flip_flag = true; - int i; + + // unsigned char potential = (current+1)%2; + bool switch_to_left = true, switch_to_right = true; + int j; - for(i=0; i=score[current][i]) + // find potential, can only be left 1 or right one + if(current==0) + switch_to_left = false; + else if(current == N_AP-1) + switch_to_right = false; + + if(switch_to_left) + { + for(j=0; j=score[current][j]) + { + switch_to_left = false; + break; + } + } + if(switch_to_right) + { + for(j=0; j=score[current][j]) + { + switch_to_right = false; + break; + } + } + if(switch_to_left && switch_to_right) + { + int sum_left = 0, sum_right = 0; + for(j=0; j #include #include -#include #include #include +#include CLICK_DECLS -#define STATUS 4 -#define DATA 17 -#define CONTROL 27 -#define IDLE 0 -#define SWITCH_REQ 1 -#define CLIENT1 135 -#define AP1 2 -#define AP2 4 -#define AP1_IP 0x0201a8c0 -#define AP2_IP 0x0401a8c0 -#define CONTROLLER_IP 0x0101a8c0 -#define AP1_MAC "C0:56:27:72:A3:5B" -#define AP2_MAC "60:38:E0:03:FA:0B" -#define CONTROLLER_MAC "38:c9:86:40:c8:05" -#define pkt_type(p) *(p->data()+9) -#define ip_id(p) *(p->data()+20) -#define ap_id(p) *(p->data()+15) -#define ap_score(p) *(p->data()+26) - class PacketSelectionSerial : public Element { public: @@ -53,16 +34,13 @@ class PacketSelectionSerial : public Element { public: private: unsigned char *state; - static const unsigned char n_client = 1; - static const unsigned char n_ap = 2; static const unsigned char n_compare = 5; - unsigned char **score; + int **score; unsigned char *next_score_id; unsigned char *output_port; unsigned char control_content[2]; int interval; - click_ip _iph; click_ether * _ethh; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h new file mode 100644 index 0000000000..34c94c3872 --- /dev/null +++ b/include/clicknet/wgtt.h @@ -0,0 +1,58 @@ +/* + * Definitation of WGTT project, maintained by Zheyu Song: sunnyszy@gmail.com + */ +#ifndef _WGTT_H_ +#define _WGTT_H_ + +// ether type +#define ETHER_PROTO_BASE 0x0800 +#define CONTROL_SUFFIX 0x1 +#define STATUS_SUFFIX 0x2 +#define DATA_SUFFIX 0x3 + +// ip +#define IP_BASE 0xac110200 + +// controller state +#define IDLE 0 +#define SWITCH_REQ 1 + +// client 1 ip +#define CLIENT0_IP_SUFFIX 135 + +// ap +#define AP0_IP_SUFFIX 0 +#define AP1_IP_SUFFIX 1 +#define AP2_IP_SUFFIX 2 + +// controller +#define CONTROLLER_IN_IP_SUFFIX 68 +#define AP0_MAC "70:88:6b:80:60:00" +#define AP1_MAC "70:88:6b:80:60:01" +#define AP2_MAC "70:88:6b:80:60:02" +#define CONTROLLER_IN_MAC "70:88:6b:80:60:7d" +#define CONTROLLER_IN_MAC_SUFFIX 0x7d + +#define RING_SIZE 256 +#define N_CLIENT 1 +#define N_AP 3 + +#define RESET_CONTENT 0xff + + +#define pkt_type(p) *(p->data()+13) +#define client_ip(p) *(p->data()+14) +#define status_ap(p) *(p->data()+11) + +#define ap_score(p) *((char *)(p->data()+15)) +#define ap_noise(p) *((char *)(p->data()+16)) +// #define ip_id(p) *(p->data()+20) + + +#define start_ap(p) *(p->data()+15) +#define start_seq(p) *(p->data()+15) +#define queue_seq(p) *(p->data()+14) +// #define seq(p) *(p->data()+20) + + +#endif /* !_WGTT_H_ */ From dcb9906f46340ab4ff7f3fd7256764ab4d7e31e0 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 11:51:19 -0500 Subject: [PATCH 067/171] fix bug --- elements/ip/csisep.cc | 18 ++++++++++-------- elements/ip/csisep.hh | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index cd9b756a17..f94c9c8f11 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -91,14 +91,16 @@ CSISep::fragment(Packet *p_in) for (i = 0; i < N_CLIENT; i += sizeof(struct iwinfo_assoclist_entry)) { e = (struct iwinfo_assoclist_entry *) &buf[i]; - memcpy(p_csi->data()+j, &(e->signal), sizeof(my_test_struct.signal)); - j += sizeof(my_test_struct.signal); - memcpy(p_csi->data()+j, &(e->noise), sizeof(my_test_struct.noise)); - j += sizeof(my_test_struct.noise); - memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(my_test_struct.rx_rate)); - j += sizeof(my_test_struct.rx_rate); - memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(my_test_struct.tx_rate)); - j += sizeof(my_test_struct.tx_rate); + memcpy(p_csi->data()+j, &(e->mac[5]), sizeof(uint8_t)); + j += sizeof(uint8_t); + memcpy(p_csi->data()+j, &(e->signal), sizeof(int8_t)); + j += sizeof(int8_t); + memcpy(p_csi->data()+j, &(e->noise), sizeof(int8_t)); + j += sizeof(int8_t); + memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(uint32_t)); + j += sizeof(uint32_t); + memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(uint32_t)); + j += sizeof(uint32_t); printf("RateSignal: %d\n", e->signal); printf("RateNoise: %d\n", e->noise); diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 15a259f366..1dc02d6bb9 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -5,6 +5,7 @@ #include #include #include +#include #ifndef __APPLE__ extern "C" @@ -49,6 +50,7 @@ class CSISep : public Element { public: const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; char ifname[6]; + struct iwinfo_assoclist_entry *e; #endif From e3776e6a4f3f13bae621c155ca4c32ce78be4a63 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 19:06:24 -0500 Subject: [PATCH 068/171] new version click --- elements/standard/wgttqueue.cc | 8 ++++---- elements/tcpudp/idadder.cc | 8 ++++---- elements/tcpudp/packetselectionSerial.cc | 20 ++++++++++---------- include/clicknet/wgtt.h | 11 ++++++----- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 03df972961..10865b97af 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -66,9 +66,9 @@ WGTTQueue::initialize(ErrorHandler *errh) { switch(identity) { - case 0: cp_ethernet_address(AP0_MAC, _ethh[i].ether_shost);break; - case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; - case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; } } @@ -97,7 +97,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(status_ap(p_in) == CONTROLLER_IN_MAC_SUFFIX)//stop { - if(client_ip(p_in) == 0xff) + if(client_ip(p_in) == RESET_CONTENT) { printf("wgttQueue: receive reset req\n"); _tail = 0; diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 432e98d61c..7d7a7fe369 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -74,9 +74,9 @@ void IDAdder::push(int port, Packet *p_in) switch(i) { - case 0:cp_ethernet_address(AP0_MAC, _ethh.ether_dhost);break; - case 1:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; - case 2:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh.ether_dhost);break; } memcpy(p->data()+sizeof(click_ether), &counter, 1); @@ -86,7 +86,7 @@ void IDAdder::push(int port, Packet *p_in) } WritablePacket *p = p_in->uniqueify(); - cp_ethernet_address(AP0_MAC, _ethh.ether_dhost); + cp_ethernet_address(AP1_MAC, _ethh.ether_dhost); memcpy(p->data()+sizeof(click_ether), &counter, 1); memcpy(p->data(), &_ethh, sizeof(click_ether)); counter ++; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 8cba21e3fc..8db2f2abf2 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -113,9 +113,9 @@ void PacketSelectionSerial::reset_ap() //ether part switch(i) { - case 0:cp_ethernet_address(AP0_MAC, _ethh->ether_dhost);break; - case 1:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 2:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; } memcpy(p->data(), _ethh, sizeof(click_ether)); @@ -129,7 +129,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) { const unsigned char & c = client_ip(p_in); printf("switch request ack ip: %X.\n", c); - state[c-CLIENT0_IP_SUFFIX] = IDLE; + state[c-CLIENT1_IP_SUFFIX] = IDLE; printf("switch request ack.\n"); p_in -> kill(); } @@ -137,7 +137,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) void PacketSelectionSerial::push_status(Packet *p_in) { //printf("In push status.\n"); - const unsigned char &a = status_ap(p_in); + unsigned char a = status_ap(p_in) - 1; // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); //since the score are minus, we minus again @@ -169,20 +169,20 @@ void PacketSelectionSerial::push_status(Packet *p_in) WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = 0; + control_content[0] = 135; control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part switch(best_ap) { - case 0:cp_ethernet_address(AP0_MAC, _ethh->ether_dhost);break; - case 1:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 2:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; } memcpy(p->data(), _ethh, sizeof(click_ether)); - printf("controller issu switch to ap %X\n", best_ap); + printf("controller issu switch to ap %X\n", best_ap+1); state[0] = SWITCH_REQ; output_port[0] = best_ap; output(0).push(p); diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 34c94c3872..b566e1b5fc 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -18,24 +18,25 @@ #define SWITCH_REQ 1 // client 1 ip -#define CLIENT0_IP_SUFFIX 135 +#define N_CLIENT 1 +#define CLIENT1_IP_SUFFIX 135 // ap -#define AP0_IP_SUFFIX 0 +#define N_AP 3 #define AP1_IP_SUFFIX 1 #define AP2_IP_SUFFIX 2 +#define AP3_IP_SUFFIX 3 // controller #define CONTROLLER_IN_IP_SUFFIX 68 -#define AP0_MAC "70:88:6b:80:60:00" #define AP1_MAC "70:88:6b:80:60:01" #define AP2_MAC "70:88:6b:80:60:02" +#define AP3_MAC "70:88:6b:80:60:03" #define CONTROLLER_IN_MAC "70:88:6b:80:60:7d" #define CONTROLLER_IN_MAC_SUFFIX 0x7d #define RING_SIZE 256 -#define N_CLIENT 1 -#define N_AP 3 + #define RESET_CONTENT 0xff From b01b56949803037e8d6cfc348da0adc14ef43a6b Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 20:43:07 -0500 Subject: [PATCH 069/171] first test two ap --- elements/tcpudp/packetselectionSerial.cc | 9 ++++++--- include/clicknet/wgtt.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 8db2f2abf2..1867c2c1a9 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -158,9 +158,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) unsigned char best_ap = find_best_ap(); // WGTT - // unsigned char best_ap = output_port[0]; - // if(!(tmp_counter%interval)) - // best_ap = 1 - output_port[0]; + if(interval>0) + { + best_ap = output_port[0]; + if(!(tmp_counter%interval)) + best_ap = 1 - output_port[0]; + } if(best_ap != output_port[0]) { diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index b566e1b5fc..6a3e9d57ef 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -22,7 +22,7 @@ #define CLIENT1_IP_SUFFIX 135 // ap -#define N_AP 3 +#define N_AP 2 #define AP1_IP_SUFFIX 1 #define AP2_IP_SUFFIX 2 #define AP3_IP_SUFFIX 3 From da60cdb821ce72e4e1ced1fac34f617bc3a3a6f2 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 21:46:11 -0500 Subject: [PATCH 070/171] use macro __arm__ instead of __APPLE__ --- elements/ip/csisep.cc | 13 ++-- elements/ip/csisep.hh | 12 ++-- macro_test/main.c | 31 ++++++++++ macro_test/main.o | Bin 0 -> 792 bytes macro_test/test | Bin 0 -> 8432 bytes tmp.log | 137 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 macro_test/main.c create mode 100644 macro_test/main.o create mode 100755 macro_test/test create mode 100644 tmp.log diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index f94c9c8f11..404442f0e5 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -29,7 +29,7 @@ CLICK_DECLS CSISep::CSISep() { -#ifndef __APPLE__ +#ifdef __arm__ printf("CSISep: finish init\n"); // total_msg_cnt = 0; #endif @@ -38,7 +38,7 @@ CSISep::CSISep() CSISep::~CSISep() { -#ifndef __APPLE__ +#ifdef __arm__ iwinfo_finish(); #endif } @@ -53,7 +53,7 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) .complete() < 0) return -1; -#ifndef __APPLE__ +#ifdef __arm__ if(wlan_port == 0) strcpy(ifname, "wlan0"); else if(wlan_port == 1) @@ -71,7 +71,7 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) void CSISep::fragment(Packet *p_in) { -#ifndef __APPLE__ +#ifdef __arm__ int i, j=0; sample_counter ++; if(sample_counter>sample_rate) @@ -117,7 +117,7 @@ CSISep::fragment(Packet *p_in) void CSISep::push(int, Packet *p) { -#ifndef __APPLE__ +#ifdef __arm__ // printf("CSISep: in push\n"); fragment(p); #endif @@ -127,7 +127,4 @@ CSISep::push(int, Packet *p) CLICK_ENDDECLS EXPORT_ELEMENT(CSISep) ELEMENT_MT_SAFE(CSISep) -#ifndef __APPLE__ -ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) -#endif diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 1dc02d6bb9..0fc8bbf9d7 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -7,11 +7,11 @@ #include #include -#ifndef __APPLE__ -extern "C" -{ - #include "iwinfo.h" -} +#ifdef __arm__ + extern "C" + { + #include "iwinfo.h" + } #endif struct my_test_struct { @@ -45,7 +45,7 @@ class CSISep : public Element { public: int sample_rate; int sample_counter; -#ifndef __APPLE__ +#ifdef __arm__ int len; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; diff --git a/macro_test/main.c b/macro_test/main.c new file mode 100644 index 0000000000..61ee2dc5de --- /dev/null +++ b/macro_test/main.c @@ -0,0 +1,31 @@ +/* + * iwinfo - Wireless Information Library - Command line frontend + * + * Copyright (C) 2011 Jo-Philipp Wich + * + * The iwinfo library is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * The iwinfo library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the iwinfo library. If not, see http://www.gnu.org/licenses/. + */ + +#include + + +int main(int argc, char **argv) +{ + #ifdef __arm__ + printf("__arm__ is defined"); + #else + printf("__arm__ is not defined"); + #endif + + return 0; +} diff --git a/macro_test/main.o b/macro_test/main.o new file mode 100644 index 0000000000000000000000000000000000000000..469d050dd7df6aff4260f68418fce324236eece2 GIT binary patch literal 792 zcma)4PfNp43{U6WhVxGkiV7Ycs7DWiA3)JT4<1A&c#%-H&h^l)Y#k0k7!1T7gng8K z2ZiZLKY|xwhY21~Zeogao_xkjn1~A5e4$>qkBuEt-0E?s-eDQ~L zB(AuIMEk@EtT7)UV(2tNGDHybxx>8nhPWXn^KtDxVN9Kb<}i!-3bnB6`o|I+<y?(XPZ#yxSAU_b;svj;*M&kssOr;Mel?Ky*j(f$JA z*%WLGpSX|(C~KQ>h16stJHcl>lLf*a)$xZj)C}KK-B+(<#=`w+mC(Q8z=|HNR$p0{ z&w5uMXa%;-3gsSM2T;C~j+EChbyM87X=O`GS5?WvU1EfZ4u8qa~|GRI-^Q~aSB WK16sozqzzfp6&X80qs;+0{8?HEL0Q# literal 0 HcmV?d00001 diff --git a/macro_test/test b/macro_test/test new file mode 100755 index 0000000000000000000000000000000000000000..270c1f90b77043af5393cec87bccb26a7da521f2 GIT binary patch literal 8432 zcmeHMO=}ZD7@qV)OIvMv@uPmQ7At;0Tfu|g8fj>XMO#}zgfb@0wpmEFCD~vL3YFSJ zz(NnwlRv;?k9rUUg{l{?9=%v9RH!!*F+R`kOtML>HxI(R@aCQOW1g9LW)?O(AAWrO zwO@!xqY#S?LWmCNdXo^#!a_@kqtFCY%F);8!@D8gy{jk(vBOztc zz2~@T>A2IgzF)f^>k5y1PN83q5oCg2?&}s*%E8z~ER@0i)$FU@-_X9|%vG?ZbhEOs zkW0;G<(!w_6HmkNe6YV3^6!tQ0#as^f5VHSKkHjmJ^e5q&t2HBJ_jSi*RRC~hxHk@ z>edOLvJ)6VobbH5@tpNDX9Z)oz#gHm#Il5c^!s61NA8)=z~?!B4tp844LS-93v0E8 ztK#^jr-G5+{M!LxI{S9>uJCxs%&87RlQ zYX$tBQ$G1IVi+(C7zPXjh5^HXVZbn882Hx=+)9)_CziIY#7grJ#@dMgGHFkl!k3>XIfD+W5dqhp+K=KwGJ{L65e!u>EVugCIY zRpg_c19A=*(B3pWNJQd3zCq?P(w?`cik^+T?j*}k<&usodiWutQM@|IT8M5i+!66_ t3jOa3hkQTyW}&}nz*asz@LncMh Date: Thu, 8 Dec 2016 22:12:43 -0500 Subject: [PATCH 071/171] ethertype: CONTROL -> DATA --- elements/tcpudp/idadder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 7d7a7fe369..627f0a80f6 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -61,7 +61,7 @@ void IDAdder::push(int port, Packet *p_in) if(!false) { lock = true; - _ethh.ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); + _ethh.ether_type = htons(ETHER_PROTO_BASE+DATA_SUFFIX); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh.ether_shost); } // printf("IDadder: counter: %X\n", counter); From 457d8986f01eaa42a1a3c69852b34d922d8f8db1 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 23:30:51 -0500 Subject: [PATCH 072/171] deal with status --- elements/ip/csisep.cc | 57 ++++++++++++++++-------- elements/standard/wgttqueue.cc | 6 +-- elements/tcpudp/packetselectionSerial.cc | 8 +++- include/clicknet/wgtt.h | 9 ++-- 4 files changed, 54 insertions(+), 26 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 404442f0e5..5f31846e9f 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -57,7 +57,7 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) if(wlan_port == 0) strcpy(ifname, "wlan0"); else if(wlan_port == 1) - strcpy(ifname, "wlan0"); + strcpy(ifname, "wlan1"); else printf("Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); @@ -84,29 +84,50 @@ CSISep::fragment(Packet *p_in) printf("CSISep: associ number < 0\n"); else { - WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - - - output(1).push(p_csi); + // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); + WritablePacket *p_csi = Packet::make(11*N_CLIENT); for (i = 0; i < N_CLIENT; i += sizeof(struct iwinfo_assoclist_entry)) { - e = (struct iwinfo_assoclist_entry *) &buf[i]; - memcpy(p_csi->data()+j, &(e->mac[5]), sizeof(uint8_t)); - j += sizeof(uint8_t); - memcpy(p_csi->data()+j, &(e->signal), sizeof(int8_t)); - j += sizeof(int8_t); - memcpy(p_csi->data()+j, &(e->noise), sizeof(int8_t)); - j += sizeof(int8_t); - memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(uint32_t)); - j += sizeof(uint32_t); - memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(uint32_t)); - j += sizeof(uint32_t); - + e = (struct iwinfo_assoclist_entry *) &buf[i]; + uint8_t & mac = e->mac[5]; + int8_t & signal = e->signal; + int8_t & noise = e->noise; + uint32_t & rx_rate = e->rx_rate; + uint32_t & tx_rate = e->tx_rate; + + memcpy(p_csi->data()+j, &(mac), 1); + j += 1; + memcpy(p_csi->data()+j, &(signal), 1); + j += 1; + memcpy(p_csi->data()+j, &(noise), 1); + j += 1; + memcpy(p_csi->data()+j, &(tx_rate), 4); + j += 4; + memcpy(p_csi->data()+j, &(rx_rate), 4); + j += 4; + + + + // memcpy(p_csi->data()+j, &(e->mac[5]), sizeof(uint8_t)); + // j += sizeof(uint8_t); + // memcpy(p_csi->data()+j, &(e->signal), sizeof(int8_t)); + // j += sizeof(int8_t); + // memcpy(p_csi->data()+j, &(e->noise), sizeof(int8_t)); + // j += sizeof(int8_t); + // memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(uint32_t)); + // j += sizeof(uint32_t); + // memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(uint32_t)); + // j += sizeof(uint32_t); + + // printf("Status[0]: %X\n", p_csi->data()); printf("RateSignal: %d\n", e->signal); + // printf("Status[1]: %X\n", p_csi->data()+1); printf("RateNoise: %d\n", e->noise); + // printf("Status[2]: %X\n", p_csi->data()+1); printf("RateRXRaw: %d\n", e->rx_rate); printf("RateTXRaw: %d\n", e->tx_rate); - } + } + output(1).push(p_csi); } } #endif diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 10865b97af..a57cd8a37e 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -66,9 +66,9 @@ WGTTQueue::initialize(ErrorHandler *errh) { switch(identity) { - case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; - case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; - case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; } } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 1867c2c1a9..d46ae38527 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -141,8 +141,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); // printf("next_score_id[a]: %x\n", next_score_id[a]); //since the score are minus, we minus again - score[a][next_score_id[a]] = - ap_score(p_in); + score[a][next_score_id[a]] = - status_score(p_in); + printf("current mac: %X\n", status_mac(p_in)); printf("current score: %d\n", score[a][next_score_id[a]]); + printf("current noise: %d\n", status_noise(p_in)); + printf("current rx_rate: %d\n", status_rxrate(p_in)); + printf("current tx_rate: %d\n", status_txrate(p_in)); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state @@ -153,7 +157,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) { tmp_counter++; if(tmp_counter%100==0) - printf("ap id: %x, score: %x\n", status_ap(p_in), ap_score(p_in)); + printf("ap id: %x, score: %x\n", status_ap(p_in), status_score(p_in)); // printf("state idle\n"); unsigned char best_ap = find_best_ap(); diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 6a3e9d57ef..9d0a2fba05 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -45,9 +45,12 @@ #define client_ip(p) *(p->data()+14) #define status_ap(p) *(p->data()+11) -#define ap_score(p) *((char *)(p->data()+15)) -#define ap_noise(p) *((char *)(p->data()+16)) -// #define ip_id(p) *(p->data()+20) +#define status_mac(p) *((unsigned char *)(p->data()+14)) +#define status_score(p) *((char *)(p->data()+15)) +#define status_noise(p) *((char *)(p->data()+16)) +#define status_rxrate(p) *((int *)(p->data()+17)) +#define status_txrate(p) *((int *)(p->data()+21)) +#define ip_id(p) *(p->data()+20) #define start_ap(p) *(p->data()+15) From 5b7f1feb344145213cc51d96bb4320d1005ae754 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 8 Dec 2016 23:50:12 -0500 Subject: [PATCH 073/171] little print --- elements/ip/csisep.cc | 31 ++++++------------------ elements/tcpudp/packetselectionSerial.cc | 14 ++++++----- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 5f31846e9f..917e209638 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -92,9 +92,11 @@ CSISep::fragment(Packet *p_in) uint8_t & mac = e->mac[5]; int8_t & signal = e->signal; int8_t & noise = e->noise; - uint32_t & rx_rate = e->rx_rate; - uint32_t & tx_rate = e->tx_rate; + uint32_t & rx_rate = (e->rx_rate).rate; + uint32_t & tx_rate = (e->tx_rate).rate; + // printf("rx_rate: %d\n", rx_rate); + // printf("tx_rate: %d\n", tx_rate); memcpy(p_csi->data()+j, &(mac), 1); j += 1; memcpy(p_csi->data()+j, &(signal), 1); @@ -105,27 +107,10 @@ CSISep::fragment(Packet *p_in) j += 4; memcpy(p_csi->data()+j, &(rx_rate), 4); j += 4; - - - - // memcpy(p_csi->data()+j, &(e->mac[5]), sizeof(uint8_t)); - // j += sizeof(uint8_t); - // memcpy(p_csi->data()+j, &(e->signal), sizeof(int8_t)); - // j += sizeof(int8_t); - // memcpy(p_csi->data()+j, &(e->noise), sizeof(int8_t)); - // j += sizeof(int8_t); - // memcpy(p_csi->data()+j, &((e->rx_rate).rate), sizeof(uint32_t)); - // j += sizeof(uint32_t); - // memcpy(p_csi->data()+j, &((e->tx_rate).rate), sizeof(uint32_t)); - // j += sizeof(uint32_t); - - // printf("Status[0]: %X\n", p_csi->data()); - printf("RateSignal: %d\n", e->signal); - // printf("Status[1]: %X\n", p_csi->data()+1); - printf("RateNoise: %d\n", e->noise); - // printf("Status[2]: %X\n", p_csi->data()+1); - printf("RateRXRaw: %d\n", e->rx_rate); - printf("RateTXRaw: %d\n", e->tx_rate); + // printf("RateSignal: %d\n", e->signal); + // printf("RateNoise: %d\n", e->noise); + // printf("RateRXRaw: %d\n", (e->rx_rate).rate); + // printf("RateTXRaw: %d\n", (e->tx_rate).rate); } output(1).push(p_csi); } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index d46ae38527..7f8c4d9e37 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -142,11 +142,6 @@ void PacketSelectionSerial::push_status(Packet *p_in) // printf("next_score_id[a]: %x\n", next_score_id[a]); //since the score are minus, we minus again score[a][next_score_id[a]] = - status_score(p_in); - printf("current mac: %X\n", status_mac(p_in)); - printf("current score: %d\n", score[a][next_score_id[a]]); - printf("current noise: %d\n", status_noise(p_in)); - printf("current rx_rate: %d\n", status_rxrate(p_in)); - printf("current tx_rate: %d\n", status_txrate(p_in)); next_score_id[a] = (next_score_id[a] + 1)%n_compare; // able to change state @@ -157,7 +152,14 @@ void PacketSelectionSerial::push_status(Packet *p_in) { tmp_counter++; if(tmp_counter%100==0) - printf("ap id: %x, score: %x\n", status_ap(p_in), status_score(p_in)); + { + printf("ap id: %X\n", status_ap(p_in)); + // printf("current mac: %X\n", status_mac(p_in)); + printf("current score: %d\n", status_score(p_in)); + printf("current noise: %d\n", status_noise(p_in)); + printf("current rx_rate: %d\n", status_rxrate(p_in)); + printf("current tx_rate: %d\n", status_txrate(p_in)); + } // printf("state idle\n"); unsigned char best_ap = find_best_ap(); From 38426cb92d4e0899db6f399297d0e5b118c1f5a7 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 15:32:50 -0500 Subject: [PATCH 074/171] full support for 8 ap --- elements/standard/wgttqueue.cc | 18 +++++++++--------- elements/tcpudp/idadder.cc | 5 +++++ elements/tcpudp/packetselectionSerial.cc | 10 ++++++++++ include/clicknet/wgtt.h | 15 ++++++++++++++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index a57cd8a37e..51d84186ba 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -26,7 +26,7 @@ WGTTQueue::WGTTQueue() { _head = 0; _tail = 0; - _ethh = new click_ether[N_AP+1]; + _ethh = new click_ether[M_N_AP+1]; _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); printf("wgtt init succeed\n"); } @@ -62,13 +62,18 @@ WGTTQueue::initialize(ErrorHandler *errh) _ethh->ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); // printf("identity: %X\n", identity); - for(int i=0; i < N_AP+1; i++) + for(int i=0; i < M_N_AP+1; i++) { switch(identity) { case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + case 4: cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; + case 5: cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; + case 6: cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; + case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; + case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; } } @@ -121,12 +126,7 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue: switch id: %X\n", _head); memcpy(p->data()+sizeof(click_ether), &control_content, 2); // //ip part - switch(dst_ap) - { - case 0: memcpy(p->data(), &(_ethh[0]), sizeof(click_ether));break; - case 1: memcpy(p->data(), &(_ethh[1]), sizeof(click_ether));break; - case 2: memcpy(p->data(), &(_ethh[2]), sizeof(click_ether));break; - } + memcpy(p->data(), &(_ethh[dst_ap]), sizeof(click_ether)); p_in -> kill(); printf("wgttQueue send ap-ap seq\n"); @@ -158,7 +158,7 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - memcpy(p->data(), &(_ethh[N_AP]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[M_N_AP]), sizeof(click_ether)); p_in -> kill(); // printf("ap-c packet push\n"); diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index 627f0a80f6..e558d3be40 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -77,6 +77,11 @@ void IDAdder::push(int port, Packet *p_in) case 0:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; case 1:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; case 2:cp_ethernet_address(AP3_MAC, _ethh.ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh.ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh.ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh.ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh.ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh.ether_dhost);break; } memcpy(p->data()+sizeof(click_ether), &counter, 1); diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 7f8c4d9e37..b566c6147f 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -116,6 +116,11 @@ void PacketSelectionSerial::reset_ap() case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; } memcpy(p->data(), _ethh, sizeof(click_ether)); @@ -187,6 +192,11 @@ void PacketSelectionSerial::push_status(Packet *p_in) case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; } memcpy(p->data(), _ethh, sizeof(click_ether)); diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 9d0a2fba05..40c99a1fd6 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -20,18 +20,31 @@ // client 1 ip #define N_CLIENT 1 #define CLIENT1_IP_SUFFIX 135 +#define CLIENT2_IP_SUFFIX 136 // ap -#define N_AP 2 +#define MAX_N_AP 8 +#define N_AP 3 #define AP1_IP_SUFFIX 1 #define AP2_IP_SUFFIX 2 #define AP3_IP_SUFFIX 3 +#define AP4_IP_SUFFIX 4 +#define AP5_IP_SUFFIX 5 +#define AP6_IP_SUFFIX 6 +#define AP7_IP_SUFFIX 7 +#define AP8_IP_SUFFIX 8 // controller #define CONTROLLER_IN_IP_SUFFIX 68 #define AP1_MAC "70:88:6b:80:60:01" #define AP2_MAC "70:88:6b:80:60:02" #define AP3_MAC "70:88:6b:80:60:03" +#define AP4_MAC "70:88:6b:80:60:04" +#define AP5_MAC "70:88:6b:80:60:05" +#define AP6_MAC "70:88:6b:80:60:06" +#define AP7_MAC "70:88:6b:80:60:07" +#define AP8_MAC "70:88:6b:80:60:08" + #define CONTROLLER_IN_MAC "70:88:6b:80:60:7d" #define CONTROLLER_IN_MAC_SUFFIX 0x7d From 5ae839118f8b1dd9fb2d431eb75c7fe923ef27a2 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 21:24:50 -0500 Subject: [PATCH 075/171] debug: when switching, send to wrong ap --- elements/standard/wgttqueue.cc | 6 +++--- elements/standard/wgttqueue.hh | 2 +- elements/tcpudp/packetselectionSerial.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 51d84186ba..e06eede232 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -26,7 +26,7 @@ WGTTQueue::WGTTQueue() { _head = 0; _tail = 0; - _ethh = new click_ether[M_N_AP+1]; + _ethh = new click_ether[MAX_N_AP+1]; _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); printf("wgtt init succeed\n"); } @@ -62,7 +62,7 @@ WGTTQueue::initialize(ErrorHandler *errh) _ethh->ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); // printf("identity: %X\n", identity); - for(int i=0; i < M_N_AP+1; i++) + for(int i=0; i < MAX_N_AP+1; i++) { switch(identity) { @@ -158,7 +158,7 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - memcpy(p->data(), &(_ethh[M_N_AP]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[MAX_N_AP]), sizeof(click_ether)); p_in -> kill(); // printf("ap-c packet push\n"); diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 4826db0881..b0d2e1e03b 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -59,7 +59,7 @@ WGTTQueue::enRing(Packet *p) _head = (_head+1)%RING_SIZE; } // printf("WGTTQueue before _q[_tail] = p\n"); - Packet *tmp = _q[_tail]; + // Packet *tmp = _q[_tail]; // printf("_tail: %x\n", _tail); _q[_tail] = p; // printf("WGTTQueue finish _q[_tail] = p\n"); diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index b566c6147f..aa979f7ee0 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -187,7 +187,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - switch(best_ap) + switch(output_port[0]) { case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; From c4631e903da681c23f8921b18710a22a067dad88 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 22:13:25 -0500 Subject: [PATCH 076/171] more print in selection --- elements/standard/wgttqueue.cc | 21 +++++++++++++++++---- elements/tcpudp/packetselectionSerial.cc | 13 +++++++++++-- include/clicknet/wgtt.h | 1 - 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index e06eede232..9849663981 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -59,11 +59,12 @@ WGTTQueue::initialize(ErrorHandler *errh) _block = true; - _ethh->ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); + // printf("identity: %X\n", identity); for(int i=0; i < MAX_N_AP+1; i++) { + _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); switch(identity) { case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; @@ -75,6 +76,18 @@ WGTTQueue::initialize(ErrorHandler *errh) case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; } + switch(i) + { + case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; + case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; + case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; + case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; + case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; + case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; + case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; + case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; + case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + } } assert(_head == 0 && _tail == 0); @@ -121,11 +134,11 @@ void WGTTQueue::push_control(Packet *p_in) const unsigned char & dst_ap = start_ap(p_in); WritablePacket *p = Packet::make(sizeof(click_ether)+2); // // data part - control_content[0] = 0; + control_content[0] = client_ip(p_in); control_content[1] = _head; + printf("wgttQueue: switch to internal ap: %u\n", dst_ap); printf("wgttQueue: switch id: %X\n", _head); memcpy(p->data()+sizeof(click_ether), &control_content, 2); - // //ip part memcpy(p->data(), &(_ethh[dst_ap]), sizeof(click_ether)); p_in -> kill(); @@ -153,7 +166,7 @@ void WGTTQueue::push_control(Packet *p_in) WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = 0; + control_content[0] = client_ip(p_in); control_content[1] = 0; memcpy(p->data()+sizeof(click_ether), &control_content, 2); diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index aa979f7ee0..8932f996ec 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -134,7 +134,16 @@ void PacketSelectionSerial::push_control(Packet *p_in) { const unsigned char & c = client_ip(p_in); printf("switch request ack ip: %X.\n", c); - state[c-CLIENT1_IP_SUFFIX] = IDLE; + if(c == CLIENT1_IP_SUFFIX) + { + printf("PacketSelection: set client %X state to IDLE\n", c); + state[c-CLIENT1_IP_SUFFIX] = IDLE; + } + else + { + printf("PacketSelection: I didn't find the client you ack\n"); + } + printf("switch request ack.\n"); p_in -> kill(); } @@ -183,7 +192,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = 135; + control_content[0] = CLIENT1_IP_SUFFIX; control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 40c99a1fd6..71b4ff59ea 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -65,7 +65,6 @@ #define status_txrate(p) *((int *)(p->data()+21)) #define ip_id(p) *(p->data()+20) - #define start_ap(p) *(p->data()+15) #define start_seq(p) *(p->data()+15) #define queue_seq(p) *(p->data()+14) From a3da447ab26ecaac950e1eda79494a2818afd5aa Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 22:21:38 -0500 Subject: [PATCH 077/171] add first start --- elements/standard/wgttqueue.cc | 3 ++- elements/standard/wgttqueue.hh | 3 ++- elements/tcpudp/packetselectionSerial.cc | 12 +++++++----- elements/tcpudp/packetselectionSerial.hh | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 9849663981..667fc9d3f5 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -39,6 +39,7 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) //printf("In configure\n"); if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) + .read_p("FIRSTSTART", IntArg(), first_start) .complete() < 0) return -1; @@ -53,7 +54,7 @@ WGTTQueue::initialize(ErrorHandler *errh) //printf("wgtt in initialize\n"); - if(identity==1) + if(identity==first_start) _block = false; else _block = true; diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index b0d2e1e03b..5ce609b519 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -41,7 +41,8 @@ class WGTTQueue : public Element, public Storage { public: volatile unsigned char _tail; volatile bool _block; - unsigned char identity; + int identity; + int first_start; unsigned char control_content[2]; click_ether * _ethh; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 8932f996ec..7963161a09 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -46,11 +46,6 @@ PacketSelectionSerial::PacketSelectionSerial() } next_score_id[i] = 0;//a pointer } - - for(i=0; i &conf, ErrorHandler *errh) { + int i; printf("PacketSelectionSerial in\n"); if (Args(conf, this, errh) .read_p("INTERVAL", IntArg(), interval) + .read_p("FIRSTSTART", IntArg(), first_start) .complete() < 0) return -1; + for(i=0; i Date: Fri, 9 Dec 2016 22:23:00 -0500 Subject: [PATCH 078/171] add first start --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 7963161a09..d9a71131ea 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -78,7 +78,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) for(i=0; i Date: Fri, 9 Dec 2016 22:36:46 -0500 Subject: [PATCH 079/171] add manual support for n router --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index d9a71131ea..b6fb2173cf 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -184,7 +184,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) { best_ap = output_port[0]; if(!(tmp_counter%interval)) - best_ap = 1 - output_port[0]; + best_ap = (best_ap + 1)% MAX_N_AP; } if(best_ap != output_port[0]) From a8fcb6ce5875219bf17048eb616b5663ff2be08a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 22:39:08 -0500 Subject: [PATCH 080/171] debug, MAX_N_AP -> N_AP --- elements/tcpudp/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index b6fb2173cf..915b56b807 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -184,7 +184,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) { best_ap = output_port[0]; if(!(tmp_counter%interval)) - best_ap = (best_ap + 1)% MAX_N_AP; + best_ap = (best_ap + 1)% N_AP; } if(best_ap != output_port[0]) From cc5c1c29527127f22df6fc7ad2689075cc5a3374 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 9 Dec 2016 22:49:00 -0500 Subject: [PATCH 081/171] add print to manually switching --- elements/tcpudp/packetselectionSerial.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 915b56b807..555115fa2f 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -184,7 +184,10 @@ void PacketSelectionSerial::push_status(Packet *p_in) { best_ap = output_port[0]; if(!(tmp_counter%interval)) + { best_ap = (best_ap + 1)% N_AP; + printf("prepare manually switch to ap %X\n", best_ap+1); + } } if(best_ap != output_port[0]) From f22d3b15219cfc8c2d0a3e24d24a578332993909 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 10 Dec 2016 11:27:48 -0500 Subject: [PATCH 082/171] configurable print_interval --- elements/tcpudp/packetselectionSerial.cc | 3 ++- elements/tcpudp/packetselectionSerial.hh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 555115fa2f..774bf8c972 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -73,6 +73,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) if (Args(conf, this, errh) .read_p("INTERVAL", IntArg(), interval) .read_p("FIRSTSTART", IntArg(), first_start) + .read_p("PRINTINTERVAL", IntArg(), print_interval) .complete() < 0) return -1; @@ -167,7 +168,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(state[0] == IDLE) { tmp_counter++; - if(tmp_counter%100==0) + if(!(tmp_counter%print_interval)) { printf("ap id: %X\n", status_ap(p_in)); // printf("current mac: %X\n", status_mac(p_in)); diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index 5e4d3df9e2..c7d9d97722 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -41,6 +41,7 @@ class PacketSelectionSerial : public Element { public: unsigned char control_content[2]; int interval; int first_start; + int print_interval; click_ether * _ethh; From 54eb66ec94f6d12768e8cba55524361e93fa357c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 10 Dec 2016 11:31:27 -0500 Subject: [PATCH 083/171] bug: reset should start from first_start --- elements/standard/wgttqueue.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 667fc9d3f5..1bfdf256ab 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -121,7 +121,7 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue: receive reset req\n"); _tail = 0; _head = 0; - _block = (identity == 1)? false:true; + _block = (identity == first_start)? false:true; for(unsigned int i=0;i<256;i++) { if(_q[i] != 0) From 2ec4f6f0d330d7e60b7ad3bf3cbca9c9a31f9ce5 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 13 Dec 2016 21:51:28 -0500 Subject: [PATCH 084/171] add lib --- elements/ip/csisep.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 917e209638..5f0daad2be 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -132,5 +132,7 @@ CSISep::push(int, Packet *p) CLICK_ENDDECLS EXPORT_ELEMENT(CSISep) -ELEMENT_MT_SAFE(CSISep) +#ifdef __arm__ + ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) +#endif From 614cde43808cd5802e7e27459d88b2bd63192e40 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 13 Dec 2016 21:51:36 -0500 Subject: [PATCH 085/171] debug --- elements/ip/csisep.hh | 11 ++-- elements/standard/wgttqueue.cc | 107 +++++++++++++++++---------------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 0fc8bbf9d7..2fdca8ba1c 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -7,12 +7,11 @@ #include #include -#ifdef __arm__ - extern "C" - { - #include "iwinfo.h" - } -#endif + +extern "C" +{ + #include "iwinfo.h" +} struct my_test_struct { uint8_t mac; diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 1bfdf256ab..e479361160 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -24,11 +24,11 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { - _head = 0; - _tail = 0; - _ethh = new click_ether[MAX_N_AP+1]; - _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); - printf("wgtt init succeed\n"); + // _head = 0; + // _tail = 0; + // _ethh = new click_ether[MAX_N_AP+1]; + // _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); + // printf("wgtt init succeed\n"); } @@ -44,58 +44,58 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) return -1; - printf("wgtt configure succeed\n"); + // printf("wgtt configure succeed\n"); return 0; } int WGTTQueue::initialize(ErrorHandler *errh) { - //printf("wgtt in initialize\n"); + // //printf("wgtt in initialize\n"); - if(identity==first_start) - _block = false; - else - _block = true; + // if(identity==first_start) + // _block = false; + // else + // _block = true; - // printf("identity: %X\n", identity); - - for(int i=0; i < MAX_N_AP+1; i++) - { - _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); - switch(identity) - { - case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; - case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; - case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; - case 4: cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; - case 5: cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; - case 6: cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; - case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; - case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; - } - switch(i) - { - case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; - case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; - case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; - case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; - case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; - case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; - case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; - case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; - case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; - } - } - - assert(_head == 0 && _tail == 0); - // printf("wgtt after !_q\n"); - if (_q == 0) - return errh->error("out of memory"); - printf("wgtt initialize succeed, ready to start\n"); + // // printf("identity: %X\n", identity); + + // for(int i=0; i < MAX_N_AP+1; i++) + // { + // _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); + // switch(identity) + // { + // case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + // case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + // case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + // case 4: cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; + // case 5: cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; + // case 6: cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; + // case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; + // case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; + // } + // switch(i) + // { + // case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; + // case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; + // case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; + // case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; + // case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; + // case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; + // case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; + // case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; + // case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + // } + // } + + // assert(_head == 0 && _tail == 0); + // // printf("wgtt after !_q\n"); + // if (_q == 0) + // return errh->error("out of memory"); + // printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -104,12 +104,12 @@ WGTTQueue::initialize(ErrorHandler *errh) void WGTTQueue::push(int, Packet *p_in) { - // printf("wgttQueue in push\n"); - switch(pkt_type(p_in)) - { - case CONTROL_SUFFIX: push_control(p_in);break; - case DATA_SUFFIX: push_data(p_in);break; - } + // // printf("wgttQueue in push\n"); + // switch(pkt_type(p_in)) + // { + // case CONTROL_SUFFIX: push_control(p_in);break; + // case DATA_SUFFIX: push_data(p_in);break; + // } } void WGTTQueue::push_control(Packet *p_in) @@ -201,7 +201,8 @@ void WGTTQueue::push_data(Packet *p_in) Packet * WGTTQueue::pull(int port) { - return deRing(); + // return deRing(); + return NULL; } From 06ce7a96bb63085b014a8a6d645987f6a037edc5 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 14 Dec 2016 16:31:28 -0500 Subject: [PATCH 086/171] add time function --- elements/ip/csisep.cc | 7 +- elements/ip/csisep.hh | 4 +- elements/standard/wgttqueue.cc | 106 +++++++++++------------ elements/tcpudp/packetselectionSerial.cc | 41 ++++++--- elements/tcpudp/packetselectionSerial.hh | 6 ++ include/clicknet/wgtt.h | 3 +- 6 files changed, 96 insertions(+), 71 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 5f0daad2be..60bc186193 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -24,7 +24,6 @@ #include - CLICK_DECLS CSISep::CSISep() @@ -132,7 +131,7 @@ CSISep::push(int, Packet *p) CLICK_ENDDECLS EXPORT_ELEMENT(CSISep) -#ifdef __arm__ - ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) -#endif +// #ifdef __arm__ +// ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) +// #endif diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 2fdca8ba1c..4e0032dee4 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -7,11 +7,13 @@ #include #include - +#ifdef __arm__ extern "C" { #include "iwinfo.h" } +#endif + struct my_test_struct { uint8_t mac; diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index e479361160..3c04511e3e 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -24,11 +24,11 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { - // _head = 0; - // _tail = 0; - // _ethh = new click_ether[MAX_N_AP+1]; - // _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); - // printf("wgtt init succeed\n"); + _head = 0; + _tail = 0; + _ethh = new click_ether[MAX_N_AP+1]; + _q = (Packet **) CLICK_LALLOC(sizeof(Packet *) * RING_SIZE); + printf("wgtt init succeed\n"); } @@ -44,58 +44,58 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) return -1; - // printf("wgtt configure succeed\n"); + printf("wgtt configure succeed\n"); return 0; } int WGTTQueue::initialize(ErrorHandler *errh) { - // //printf("wgtt in initialize\n"); + //printf("wgtt in initialize\n"); - // if(identity==first_start) - // _block = false; - // else - // _block = true; + if(identity==first_start) + _block = false; + else + _block = true; - // // printf("identity: %X\n", identity); - - // for(int i=0; i < MAX_N_AP+1; i++) - // { - // _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); - // switch(identity) - // { - // case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; - // case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; - // case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; - // case 4: cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; - // case 5: cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; - // case 6: cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; - // case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; - // case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; - // } - // switch(i) - // { - // case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; - // case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; - // case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; - // case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; - // case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; - // case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; - // case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; - // case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; - // case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; - // } - // } - - // assert(_head == 0 && _tail == 0); - // // printf("wgtt after !_q\n"); - // if (_q == 0) - // return errh->error("out of memory"); - // printf("wgtt initialize succeed, ready to start\n"); + // printf("identity: %X\n", identity); + + for(int i=0; i < MAX_N_AP+1; i++) + { + _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); + switch(identity) + { + case 1: cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 2: cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 3: cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + case 4: cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; + case 5: cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; + case 6: cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; + case 7: cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; + case 8: cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; + } + switch(i) + { + case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; + case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; + case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; + case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; + case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; + case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; + case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; + case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; + case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + } + } + + assert(_head == 0 && _tail == 0); + // printf("wgtt after !_q\n"); + if (_q == 0) + return errh->error("out of memory"); + printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -104,12 +104,12 @@ WGTTQueue::initialize(ErrorHandler *errh) void WGTTQueue::push(int, Packet *p_in) { - // // printf("wgttQueue in push\n"); - // switch(pkt_type(p_in)) - // { - // case CONTROL_SUFFIX: push_control(p_in);break; - // case DATA_SUFFIX: push_data(p_in);break; - // } + // printf("wgttQueue in push\n"); + switch(pkt_type(p_in)) + { + case CONTROL_SUFFIX: push_control(p_in);break; + case DATA_SUFFIX: push_data(p_in);break; + } } void WGTTQueue::push_control(Packet *p_in) @@ -201,7 +201,7 @@ void WGTTQueue::push_data(Packet *p_in) Packet * WGTTQueue::pull(int port) { - // return deRing(); + return deRing(); return NULL; } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 774bf8c972..ed26e1195e 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -53,7 +53,14 @@ PacketSelectionSerial::PacketSelectionSerial() _ethh = new click_ether; _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); - bool result = cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); + cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); + + //set the time lock to be false + time_lock = false; + gettimeofday(&tv, NULL); + double tmp_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + printf("Tmp_time: %f\n", tmp_time); + printf("Packetselection: init finish, ready to start\n"); @@ -163,20 +170,25 @@ void PacketSelectionSerial::push_status(Packet *p_in) // able to change state static unsigned int tmp_counter = 0; + tmp_counter++; + if(!(tmp_counter%print_interval)) + { + printf("ap id: %X\n", status_ap(p_in)); + // printf("current mac: %X\n", status_mac(p_in)); + printf("current score: %d\n", status_score(p_in)); + printf("current noise: %d\n", status_noise(p_in)); + printf("current rx_rate: %d\n", status_rxrate(p_in)); + printf("current tx_rate: %d\n", status_txrate(p_in)); + } + gettimeofday(&tv, NULL); + double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + if(now_time - last_time > 1000) + time_lock = false; - if(state[0] == IDLE) + + if(state[0] == IDLE && !time_lock) { - tmp_counter++; - if(!(tmp_counter%print_interval)) - { - printf("ap id: %X\n", status_ap(p_in)); - // printf("current mac: %X\n", status_mac(p_in)); - printf("current score: %d\n", status_score(p_in)); - printf("current noise: %d\n", status_noise(p_in)); - printf("current rx_rate: %d\n", status_rxrate(p_in)); - printf("current tx_rate: %d\n", status_txrate(p_in)); - } // printf("state idle\n"); unsigned char best_ap = find_best_ap(); @@ -219,6 +231,11 @@ void PacketSelectionSerial::push_status(Packet *p_in) printf("controller issu switch to ap %X\n", best_ap+1); state[0] = SWITCH_REQ; output_port[0] = best_ap; + + // after issue switch, time lock will be turn on, and turned off after 1 s + time_lock = true; + gettimeofday(&tv, NULL); + last_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; output(0).push(p); } diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/tcpudp/packetselectionSerial.hh index c7d9d97722..f05e341680 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/tcpudp/packetselectionSerial.hh @@ -6,6 +6,7 @@ #include #include #include +#include CLICK_DECLS @@ -43,6 +44,11 @@ class PacketSelectionSerial : public Element { public: int first_start; int print_interval; + // after issue switch, a time lock will be set for 1 second + bool time_lock; + double last_time; + struct timeval tv; + click_ether * _ethh; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 71b4ff59ea..85bfad0323 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -24,7 +24,7 @@ // ap #define MAX_N_AP 8 -#define N_AP 3 +#define N_AP 8 #define AP1_IP_SUFFIX 1 #define AP2_IP_SUFFIX 2 #define AP3_IP_SUFFIX 3 @@ -49,6 +49,7 @@ #define CONTROLLER_IN_MAC_SUFFIX 0x7d #define RING_SIZE 256 +#define SWITCH_MIN 1000 #define RESET_CONTENT 0xff From e853754c124ce6ca25e55f20c8c2d5761c41b093 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 14 Dec 2016 18:41:43 -0500 Subject: [PATCH 087/171] debug --- elements/ip/csisep.cc | 9 ++++++--- elements/tcpudp/packetselectionSerial.cc | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 60bc186193..4ff9d3a796 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -31,6 +31,7 @@ CSISep::CSISep() #ifdef __arm__ printf("CSISep: finish init\n"); // total_msg_cnt = 0; + sample_counter = 0; #endif } @@ -75,6 +76,7 @@ CSISep::fragment(Packet *p_in) sample_counter ++; if(sample_counter>sample_rate) { + // for debug sample_counter = 0; if (iw->assoclist(ifname, buf, &len)) @@ -94,7 +96,8 @@ CSISep::fragment(Packet *p_in) uint32_t & rx_rate = (e->rx_rate).rate; uint32_t & tx_rate = (e->tx_rate).rate; - // printf("rx_rate: %d\n", rx_rate); + printf("rx_rate: %d\n", rx_rate); + printf("rx_rate: %X\n", rx_rate); // printf("tx_rate: %d\n", tx_rate); memcpy(p_csi->data()+j, &(mac), 1); j += 1; @@ -102,10 +105,10 @@ CSISep::fragment(Packet *p_in) j += 1; memcpy(p_csi->data()+j, &(noise), 1); j += 1; - memcpy(p_csi->data()+j, &(tx_rate), 4); - j += 4; memcpy(p_csi->data()+j, &(rx_rate), 4); j += 4; + memcpy(p_csi->data()+j, &(tx_rate), 4); + j += 4; // printf("RateSignal: %d\n", e->signal); // printf("RateNoise: %d\n", e->noise); // printf("RateRXRaw: %d\n", (e->rx_rate).rate); diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index ed26e1195e..3cb9ed0045 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -57,9 +57,9 @@ PacketSelectionSerial::PacketSelectionSerial() //set the time lock to be false time_lock = false; - gettimeofday(&tv, NULL); - double tmp_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; - printf("Tmp_time: %f\n", tmp_time); + // gettimeofday(&tv, NULL); + // double tmp_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + // printf("Tmp_time: %f\n", tmp_time); printf("Packetselection: init finish, ready to start\n"); @@ -180,6 +180,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) printf("current rx_rate: %d\n", status_rxrate(p_in)); printf("current tx_rate: %d\n", status_txrate(p_in)); } + printf("current rx_rate: %d\n", status_rxrate(p_in)); + printf("%d.%d MBit/s\n",status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100); + printf("current rx_rate: %X\n", status_rxrate(p_in)); gettimeofday(&tv, NULL); double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; From 8a5675c179691d722b50176caa0b1f9c915251ef Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 14 Dec 2016 18:54:15 -0500 Subject: [PATCH 088/171] remove debug effect --- elements/ip/csisep.cc | 5 ++--- elements/tcpudp/packetselectionSerial.cc | 9 ++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 4ff9d3a796..b077ea0171 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -76,7 +76,6 @@ CSISep::fragment(Packet *p_in) sample_counter ++; if(sample_counter>sample_rate) { - // for debug sample_counter = 0; if (iw->assoclist(ifname, buf, &len)) @@ -96,8 +95,8 @@ CSISep::fragment(Packet *p_in) uint32_t & rx_rate = (e->rx_rate).rate; uint32_t & tx_rate = (e->tx_rate).rate; - printf("rx_rate: %d\n", rx_rate); - printf("rx_rate: %X\n", rx_rate); + // printf("rx_rate: %d\n", rx_rate); + // printf("rx_rate: %X\n", rx_rate); // printf("tx_rate: %d\n", tx_rate); memcpy(p_csi->data()+j, &(mac), 1); j += 1; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 3cb9ed0045..06a441392f 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -177,12 +177,11 @@ void PacketSelectionSerial::push_status(Packet *p_in) // printf("current mac: %X\n", status_mac(p_in)); printf("current score: %d\n", status_score(p_in)); printf("current noise: %d\n", status_noise(p_in)); - printf("current rx_rate: %d\n", status_rxrate(p_in)); - printf("current tx_rate: %d\n", status_txrate(p_in)); + printf("current rx_rate: %d.%d MBit/s\n", + status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100); + printf("current tx_rate: %d.%d MBit/s\n", + status_txrate(p_in) / 1000, status_txrate(p_in) / 100); } - printf("current rx_rate: %d\n", status_rxrate(p_in)); - printf("%d.%d MBit/s\n",status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100); - printf("current rx_rate: %X\n", status_rxrate(p_in)); gettimeofday(&tv, NULL); double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; From 28fca6f3f3541c640226c4c6eac0d594b2749344 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 15 Dec 2016 22:01:55 -0500 Subject: [PATCH 089/171] 4 client support for packetselection --- elements/tcpudp/packetselectionSerial.cc | 205 ++++++++--------------- elements/tcpudp/packetselectionSerial.hh | 36 ++-- include/clicknet/wgtt.h | 49 +++--- tcpudp | 1 - 4 files changed, 119 insertions(+), 172 deletions(-) delete mode 120000 tcpudp diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 06a441392f..17b8e21a2b 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -1,20 +1,8 @@ /* - * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header - * Benjie Chen, Eddie Kohler, Hansen Qian - * - * Copyright (c) 1999-2000 Massachusetts Institute of Technology - * Copyright (c) 2007 Regents of the University of California - * Copyright (c) 2016 Princeton University - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, subject to the conditions - * listed in the Click LICENSE file. These conditions include: you must - * preserve this copyright notice, and you cannot mention the copyright - * holders in advertising related to the Software without their permission. - * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This - * notice is a summary of the Click LICENSE file; the license in that file is - * legally binding. + Controller program, issusing switching between different ap. + Input: control/status packet + Output: control packet + Created by Zhenyu Song: sunnyszy@gmail.com */ #include @@ -24,79 +12,65 @@ #include #include - CLICK_DECLS - - - +CLICK_DECLS PacketSelectionSerial::PacketSelectionSerial() { - int i,j; - interval = 20; - score = new int*[N_AP]; - next_score_id = new unsigned char[N_AP]; - output_port = new unsigned char[N_CLIENT]; - for(i=0; iether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); - //set the time lock to be false - time_lock = false; - // gettimeofday(&tv, NULL); - // double tmp_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; - // printf("Tmp_time: %f\n", tmp_time); - - printf("Packetselection: init finish, ready to start\n"); - } -PacketSelectionSerial::~PacketSelectionSerial() -{ - -} - - - int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) { int i; - printf("PacketSelectionSerial in\n"); if (Args(conf, this, errh) .read_p("INTERVAL", IntArg(), interval) - .read_p("FIRSTSTART", IntArg(), first_start) + .read_p("FIRSTSTART1", IntArg(), first_start[0]) + .read_p("FIRSTSTART2", IntArg(), first_start[1]) + .read_p("FIRSTSTART3", IntArg(), first_start[2]) + .read_p("FIRSTSTART4", IntArg(), first_start[3]) .read_p("PRINTINTERVAL", IntArg(), print_interval) .complete() < 0) return -1; - for(i=0; idata()+sizeof(click_ether), &control_content, 2); //ether part - switch(i) - { - case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; - } - + cp_ethernet_address(AP_MAC[i], _ethh->ether_dhost);break; memcpy(p->data(), _ethh, sizeof(click_ether)); + printf("controller reset ap %X\n", i); output(0).push(p); } @@ -143,103 +107,82 @@ void PacketSelectionSerial::reset_ap() void PacketSelectionSerial::push_control(Packet *p_in) { const unsigned char & c = client_ip(p_in); - printf("switch request ack ip: %X.\n", c); - if(c == CLIENT1_IP_SUFFIX) - { - printf("PacketSelection: set client %X state to IDLE\n", c); - state[c-CLIENT1_IP_SUFFIX] = IDLE; - } - else - { - printf("PacketSelection: I didn't find the client you ack\n"); - } - printf("switch request ack.\n"); + state[c-CLIENT_IP_SUFFIX[0]] = IDLE; + + printf("switch request ack, ip: %d.\n", c); p_in -> kill(); } void PacketSelectionSerial::push_status(Packet *p_in) { - //printf("In push status.\n"); - unsigned char a = status_ap(p_in) - 1; - // printf("ap id: %x, score: %x\n", ap_id(p_in), ap_score(p_in)); - // printf("next_score_id[a]: %x\n", next_score_id[a]); + const unsigned char a = status_ap(p_in) - 1; + unsigned char c; + switch(status_mac(p_in)) + { + case CLIENT_MAC_SUFFIX[0]: c = 0;break; + case CLIENT_MAC_SUFFIX[1]: c = 1;break; + case CLIENT_MAC_SUFFIX[2]: c = 2;break; + case CLIENT_MAC_SUFFIX[3]: c = 3;break; + } //since the score are minus, we minus again - score[a][next_score_id[a]] = - status_score(p_in); - next_score_id[a] = (next_score_id[a] + 1)%n_compare; + score[c][a][next_score_id[c][a]] = - status_score(p_in); + next_score_id[c][a] = (next_score_id[c][a] + 1)%n_compare; // able to change state static unsigned int tmp_counter = 0; tmp_counter++; if(!(tmp_counter%print_interval)) { - printf("ap id: %X\n", status_ap(p_in)); - // printf("current mac: %X\n", status_mac(p_in)); - printf("current score: %d\n", status_score(p_in)); - printf("current noise: %d\n", status_noise(p_in)); - printf("current rx_rate: %d.%d MBit/s\n", - status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100); - printf("current tx_rate: %d.%d MBit/s\n", + printf("client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); + printf("signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); + printf("rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", + status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100 status_txrate(p_in) / 1000, status_txrate(p_in) / 100); } gettimeofday(&tv, NULL); double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; - if(now_time - last_time > 1000) - time_lock = false; - + if(now_time - last_time[c] > 1000) + time_lock[c] = false; - if(state[0] == IDLE && !time_lock) + if(state[c] == IDLE && !time_lock[c]) { // printf("state idle\n"); - unsigned char best_ap = find_best_ap(); + unsigned char best_ap = find_best_ap(c); // WGTT if(interval>0) { - best_ap = output_port[0]; + best_ap = output_port[c]; if(!(tmp_counter%interval)) { - best_ap = (best_ap + 1)% N_AP; + best_ap = (best_ap + 1)% 2; printf("prepare manually switch to ap %X\n", best_ap+1); } } - - if(best_ap != output_port[0]) + if(best_ap != output_port[c]) { - // send message // send_meg(best_ap) WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = CLIENT1_IP_SUFFIX; + control_content[0] = CLIENT_IP_SUFFIX[c]; control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - switch(output_port[0]) - { - case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; - } + cp_ethernet_address(AP_MAC[output_port[c]], _ethh->ether_dhost); memcpy(p->data(), _ethh, sizeof(click_ether)); - - printf("controller issu switch to ap %X\n", best_ap+1); - state[0] = SWITCH_REQ; - output_port[0] = best_ap; + printf("Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + state[c] = SWITCH_REQ; + output_port[c] = best_ap; // after issue switch, time lock will be turn on, and turned off after 1 s - time_lock = true; + time_lock[c] = true; gettimeofday(&tv, NULL); - last_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + last_time[c] = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; output(0).push(p); - } } p_in -> kill(); @@ -247,9 +190,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) } // incomplete version, only for 2 ap and 1 client -unsigned char PacketSelectionSerial::find_best_ap() +unsigned char PacketSelectionSerial::find_best_ap(unsigned char c) { - unsigned char ¤t = output_port[0]; + unsigned char ¤t = output_port[c]; // unsigned char potential = (current+1)%2; bool switch_to_left = true, switch_to_right = true; @@ -258,13 +201,13 @@ unsigned char PacketSelectionSerial::find_best_ap() // find potential, can only be left 1 or right one if(current==0) switch_to_left = false; - else if(current == N_AP-1) + else if(current == MAX_N_AP-1) switch_to_right = false; if(switch_to_left) { for(j=0; j=score[current][j]) + if(score[c][current-1][n_compare-j-1]>=score[c][current][j]) { switch_to_left = false; break; @@ -273,7 +216,7 @@ unsigned char PacketSelectionSerial::find_best_ap() if(switch_to_right) { for(j=0; j=score[current][j]) + if(score[c][current+1][n_compare-j-1]>=score[c][current][j]) { switch_to_right = false; break; @@ -284,8 +227,8 @@ unsigned char PacketSelectionSerial::find_best_ap() int sum_left = 0, sum_right = 0; for(j=0; j @@ -10,15 +16,10 @@ CLICK_DECLS - - - - class PacketSelectionSerial : public Element { public: PacketSelectionSerial() CLICK_COLD; - ~PacketSelectionSerial() CLICK_COLD; const char *class_name() const { return "PacketSelectionSerial"; } const char *port_count() const { return "1/1"; } @@ -30,23 +31,32 @@ class PacketSelectionSerial : public Element { public: void push(int port, Packet *p_in); void push_control(Packet *p_in); void push_status(Packet *p_in); - unsigned char find_best_ap(); + // find best ap for client c + unsigned char find_best_ap(unsigned char c); private: - unsigned char *state; + unsigned char state[MAX_N_CLIENT]; static const unsigned char n_compare = 5; - int **score; - unsigned char *next_score_id; - unsigned char *output_port; + // [client, ap, n_compare] + int ***score; + // [client, ap] + unsigned char ** next_score_id; + unsigned char output_port[MAX_N_CLIENT]; unsigned char control_content[2]; + // which ap will first start + unsigned char first_start[MAX_N_CLIENT]; + + // used for debug. + // By setting a positive number, manually switch after every ${interval} pkt + // Between ap 1 - 2 int interval; - int first_start; + // Printing screen after ${print_interval} pkt int print_interval; // after issue switch, a time lock will be set for 1 second - bool time_lock; - double last_time; + bool time_lock[MAX_N_CLIENT]; + double last_time[MAX_N_CLIENT]; struct timeval tv; click_ether * _ethh; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 85bfad0323..b75a4b7379 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -1,5 +1,6 @@ /* - * Definitation of WGTT project, maintained by Zheyu Song: sunnyszy@gmail.com + Parameter of WGTT project, + Created by Zhenyu Song: sunnyszy@gmail.com */ #ifndef _WGTT_H_ #define _WGTT_H_ @@ -18,58 +19,52 @@ #define SWITCH_REQ 1 // client 1 ip -#define N_CLIENT 1 -#define CLIENT1_IP_SUFFIX 135 -#define CLIENT2_IP_SUFFIX 136 +#define MAX_N_CLIENT 4 // ap #define MAX_N_AP 8 -#define N_AP 8 -#define AP1_IP_SUFFIX 1 -#define AP2_IP_SUFFIX 2 -#define AP3_IP_SUFFIX 3 -#define AP4_IP_SUFFIX 4 -#define AP5_IP_SUFFIX 5 -#define AP6_IP_SUFFIX 6 -#define AP7_IP_SUFFIX 7 -#define AP8_IP_SUFFIX 8 // controller #define CONTROLLER_IN_IP_SUFFIX 68 -#define AP1_MAC "70:88:6b:80:60:01" -#define AP2_MAC "70:88:6b:80:60:02" -#define AP3_MAC "70:88:6b:80:60:03" -#define AP4_MAC "70:88:6b:80:60:04" -#define AP5_MAC "70:88:6b:80:60:05" -#define AP6_MAC "70:88:6b:80:60:06" -#define AP7_MAC "70:88:6b:80:60:07" -#define AP8_MAC "70:88:6b:80:60:08" #define CONTROLLER_IN_MAC "70:88:6b:80:60:7d" #define CONTROLLER_IN_MAC_SUFFIX 0x7d #define RING_SIZE 256 +// 1000 ms #define SWITCH_MIN 1000 - - +// content encapsulated in mac header #define RESET_CONTENT 0xff - +// mac header indicates the packet type #define pkt_type(p) *(p->data()+13) #define client_ip(p) *(p->data()+14) -#define status_ap(p) *(p->data()+11) +#define status_ap(p) *(p->data()+11) +// when can use status mac to know client #define status_mac(p) *((unsigned char *)(p->data()+14)) #define status_score(p) *((char *)(p->data()+15)) #define status_noise(p) *((char *)(p->data()+16)) #define status_rxrate(p) *((int *)(p->data()+17)) #define status_txrate(p) *((int *)(p->data()+21)) -#define ip_id(p) *(p->data()+20) +// I think we don't need this +// #define ip_id(p) *(p->data()+20) +// start ap in controll-ap command #define start_ap(p) *(p->data()+15) +// seq number in ap-ap command #define start_seq(p) *(p->data()+15) +// seq in data pkt #define queue_seq(p) *(p->data()+14) -// #define seq(p) *(p->data()+20) + +unsigned char CLIENT_IP_SUFFIX[MAX_N_CLIENT] = {135, 136, 137, 138}; +unsigned short SERVER_PORT[MAX_N_CLIENT] = {5201, 5202, 5203, 5204}; +unsigned char AP_IP_SUFFIX[MAX_N_AP] = {1, 2, 3, 4, 5, 6, 7, 8}; +char *AP_MAC[MAX_N_AP] = {"70:88:6b:80:60:01", "70:88:6b:80:60:02", "70:88:6b:80:60:03" + "70:88:6b:80:60:04", "70:88:6b:80:60:05", "70:88:6b:80:60:06", "70:88:6b:80:60:07" + "70:88:6b:80:60:08"}; +//made up last two client mac +unsigned char CLIENT_MAC_SUFFIX[MAX_N_CLIENT] = {0x07, 0xac, 0x01, 0x02}; #endif /* !_WGTT_H_ */ diff --git a/tcpudp b/tcpudp deleted file mode 120000 index a8c873db21..0000000000 --- a/tcpudp +++ /dev/null @@ -1 +0,0 @@ -/Users/zhenyus/github/click/elements/tcpudp \ No newline at end of file From e82b5e69320492cc5ce375413b12c9122b4bd5eb Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 16 Dec 2016 22:58:32 -0500 Subject: [PATCH 090/171] add support for multi client & ICMP NAT --- elements/ip/csisep.cc | 30 +--- elements/ip/csisep.hh | 10 +- elements/standard/wgttqueue.cc | 177 +++++++++++------------ elements/standard/wgttqueue.hh | 66 +++++---- elements/tcpudp/deduptcppacket.cc | 25 +--- elements/tcpudp/deduptcppacket.hh | 8 +- elements/tcpudp/idadder.cc | 85 ++++------- elements/tcpudp/idadder.hh | 14 +- elements/tcpudp/packetselectionSerial.cc | 41 ++++-- include/clicknet/wgtt.h | 27 ++-- 10 files changed, 231 insertions(+), 252 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index b077ea0171..282a3cdbb9 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -1,20 +1,8 @@ -// -*- c-basic-offset: 4 -*- /* - * ipfragmenter.{cc,hh} -- element fragments IP packets - * Robert Morris, Eddie Kohler - * - * Copyright (c) 1999-2000 Massachusetts Institute of Technology - * Copyright (c) 2002 International Computer Science Institute - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, subject to the conditions - * listed in the Click LICENSE file. These conditions include: you must - * preserve this copyright notice, and you cannot mention the copyright - * holders in advertising related to the Software without their permission. - * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This - * notice is a summary of the Click LICENSE file; the license in that file is - * legally binding. + sample rssi/noise/txrate/rxrate + Input: data pkt + Output: port 0: data pkt, port 1: status + Created by Zhenyu Song: sunnyszy@gmail.com */ #include @@ -23,7 +11,6 @@ #include #include - CLICK_DECLS CSISep::CSISep() @@ -95,9 +82,6 @@ CSISep::fragment(Packet *p_in) uint32_t & rx_rate = (e->rx_rate).rate; uint32_t & tx_rate = (e->tx_rate).rate; - // printf("rx_rate: %d\n", rx_rate); - // printf("rx_rate: %X\n", rx_rate); - // printf("tx_rate: %d\n", tx_rate); memcpy(p_csi->data()+j, &(mac), 1); j += 1; memcpy(p_csi->data()+j, &(signal), 1); @@ -132,8 +116,4 @@ CSISep::push(int, Packet *p) CLICK_ENDDECLS -EXPORT_ELEMENT(CSISep) -// #ifdef __arm__ -// ELEMENT_LIBS(-L/Volumes/BasicWrt/openwrt_linksys/staging_dir/target-arm_cortex-a9+vfpv3_uClibc-0.9.33.2_eabi/usr/lib -liwinfo) -// #endif - +EXPORT_ELEMENT(CSISep) \ No newline at end of file diff --git a/elements/ip/csisep.hh b/elements/ip/csisep.hh index 4e0032dee4..b7af96aff2 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/csisep.hh @@ -1,3 +1,10 @@ +/* + sample rssi/noise/txrate/rxrate + Input: data pkt + Output: port 0: data pkt, port 1: status + Created by Zhenyu Song: sunnyszy@gmail.com + */ + #ifndef CLICK_CSISEP_HH #define CLICK_CSISEP_HH #include @@ -5,9 +12,8 @@ #include #include #include -#include - #ifdef __arm__ +#include extern "C" { #include "iwinfo.h" diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 3c04511e3e..e399e9ba40 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -1,19 +1,8 @@ -// -*- c-basic-offset: 4 -*- /* - * simplequeue.{cc,hh} -- queue element - * Eddie Kohler - * - * Copyright (c) 1999-2000 Massachusetts Institute of Technology - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, subject to the conditions - * listed in the Click LICENSE file. These conditions include: you must - * preserve this copyright notice, and you cannot mention the copyright - * holders in advertising related to the Software without their permission. - * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This - * notice is a summary of the Click LICENSE file; the license in that file is - * legally binding. + A queue store data pkt for each client. Cache the pkt in a ring buffer + Input: data pkt, control pkt + Output: data pkt, control pkt + Created by Zhenyu Song: sunnyszy@gmail.com */ #include @@ -24,10 +13,16 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { - _head = 0; - _tail = 0; + int i; + _q = new Packet **[MAX_N_CLIENT]; + for(i=0; i &conf, ErrorHandler *errh) //printf("In configure\n"); if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) - .read_p("FIRSTSTART", IntArg(), first_start) + .read_p("FIRSTSTART1", IntArg(), first_start[0]) + .read_p("FIRSTSTART2", IntArg(), first_start[1]) + .read_p("FIRSTSTART3", IntArg(), first_start[2]) + .read_p("FIRSTSTART4", IntArg(), first_start[3]) .complete() < 0) return -1; - printf("wgtt configure succeed\n"); return 0; } @@ -52,49 +49,39 @@ int WGTTQueue::initialize(ErrorHandler *errh) { //printf("wgtt in initialize\n"); + int i; + for(i=0; iether_shost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_shost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_shost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_shost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_shost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_shost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_shost);break; } switch(i) { - case 0: cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; - case 1: cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; - case 2: cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; - case 3: cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; - case 4: cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; - case 5: cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; - case 6: cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; - case 7: cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; - case 8: cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_shost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_shost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_shost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_shost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_shost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_shost);break; } } - assert(_head == 0 && _tail == 0); - // printf("wgtt after !_q\n"); if (_q == 0) - return errh->error("out of memory"); + return errh->error("out of memory"); printf("wgtt initialize succeed, ready to start\n"); return 0; } @@ -114,52 +101,55 @@ WGTTQueue::push(int, Packet *p_in) void WGTTQueue::push_control(Packet *p_in) { - if(status_ap(p_in) == CONTROLLER_IN_MAC_SUFFIX)//stop + int i,j; + unsigned char c = client_ip(p_in)- CLIENT1_IP_SUFFIX; //index for client + if(status_ap(p_in) == CONTROLLER_IN_MAC_SUFFIX) //from controller { - if(client_ip(p_in) == RESET_CONTENT) + if(client_ip(p_in) == RESET_CONTENT) //reset { - printf("wgttQueue: receive reset req\n"); - _tail = 0; - _head = 0; - _block = (identity == first_start)? false:true; - for(unsigned int i=0;i<256;i++) - { - if(_q[i] != 0) - _q[i] -> kill(); + printf("wgttQueue: receive reset req for client: %d\n", c+1); + for(i=0; i kill(); + } } } else { - printf("wgttQueue: receive switch req\n"); - _block = true; - const unsigned char & dst_ap = start_ap(p_in); - WritablePacket *p = Packet::make(sizeof(click_ether)+2); - // // data part - control_content[0] = client_ip(p_in); - control_content[1] = _head; - printf("wgttQueue: switch to internal ap: %u\n", dst_ap); - printf("wgttQueue: switch id: %X\n", _head); - memcpy(p->data()+sizeof(click_ether), &control_content, 2); - memcpy(p->data(), &(_ethh[dst_ap]), sizeof(click_ether)); - - p_in -> kill(); - printf("wgttQueue send ap-ap seq\n"); - checked_output_push(1, p); + printf("wgttQueue: receive switch req for client: %d\n", c+1); + _block[c] = true; + const unsigned char & dst_ap = start_ap(p_in); + WritablePacket *p = Packet::make(sizeof(click_ether)+2); + // // data part + control_content[0] = client_ip(p_in); + control_content[1] = _head[c]; + printf("wgttQueue: switch to ap: %d\n", dst_ap+1); + printf("wgttQueue: switch id: %X\n", _head[c]); + memcpy(p->data()+sizeof(click_ether), &control_content, 2); + memcpy(p->data(), &(_ethh[dst_ap]), sizeof(click_ether)); + + p_in -> kill(); + printf("wgttQueue send ap-ap seq\n"); + checked_output_push(1, p); } } - else + else //from ap { + printf("wgttQueue receive ap-ap seq for client: %d\n", c+1); - printf("wgttQueue receive ap-ap seq\n"); - // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); - // printf("wgttQueue in dering-prepare\n"); const unsigned char & start_seq = start_seq(p_in); - while(_head != start_seq) + while(_head[c] != start_seq) { - if(_q[_head] != 0) - _q[_head] -> kill(); - _head = (_head+1)%RING_SIZE; + if(_q[c][_head[c]] != 0) + _q[c][_head[c]] -> kill(); + _head[c] = (_head[c]+1)%RING_SIZE; } printf("wgttQueue finish ap-ap dequeue\n"); @@ -176,33 +166,30 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // printf("ap-c packet push\n"); - _block = false; + _block[c] = false; printf("wgttQueue send switch ack\n"); checked_output_push(1, p); - } } void WGTTQueue::push_data(Packet *p_in) { - printf("wgttQueue in push data\n"); const unsigned char & seq = queue_seq(p_in); - while(_tail != seq) + unsigned char c = data_client(p_in) - 1; + printf("wgttQueue in push data for client: %d\n", c+1); + while(_tail[c] != seq) { - // printf("wgttQueue in enring-prepare\n"); - // printf("wgttQueue _head: %X, _tail: %X\n", _head, _tail); - enRing(0); + enRing(c, 0); } p_in -> pull(15); - printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head, _tail); - enRing(p_in); + printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + enRing(c, p_in); } Packet * WGTTQueue::pull(int port) { return deRing(); - return NULL; } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 5ce609b519..4d25eec12e 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -1,3 +1,9 @@ +/* + idadder program, add id and push for queue ring in ap processing. + Input: [data pkt] + Output:[eth][id][data pkt], id is one Byte + Created by Zhenyu Song: sunnyszy@gmail.com + */ // -*- c-basic-offset: 4 -*- #ifndef CLICK_WGTTQUEUE_HH #define CLICK_WGTTQUEUE_HH @@ -6,17 +12,14 @@ #include #include #include -CLICK_DECLS - - - +CLICK_DECLS class WGTTQueue : public Element, public Storage { public: WGTTQueue() CLICK_COLD; - inline void enRing(Packet*);//flag: whether override + inline void enRing(unsigned char, Packet*);//flag: whether override inline Packet* deRing(); inline void enque(Packet*);//flag: whether override inline Packet* deque(); @@ -35,14 +38,15 @@ class WGTTQueue : public Element, public Storage { public: protected: - Packet* volatile * _q; + Packet** volatile * _q; - volatile unsigned char _head; - volatile unsigned char _tail; + volatile unsigned char _head[MAX_N_CLIENT]; + volatile unsigned char _tail[MAX_N_CLIENT]; + volatile bool _block[MAX_N_CLIENT]; + volatile unsigned char next_client; - volatile bool _block; int identity; - int first_start; + int first_start[MAX_N_CLIENT]; unsigned char control_content[2]; click_ether * _ethh; @@ -50,37 +54,47 @@ class WGTTQueue : public Element, public Storage { public: }; inline void -WGTTQueue::enRing(Packet *p) +WGTTQueue::enRing(unsigned char c, Packet *p) { - if((_tail+1)%RING_SIZE == _head)//override + if((_tail[c]+1)%RING_SIZE == _head[c])//override { // printf("WGTTQueue override\n"); - if(_q[_head] != 0) - _q[_head] -> kill(); - _head = (_head+1)%RING_SIZE; + if(_q[c][_head[c]] != 0) + _q[c][_head[c]] -> kill(); + _head[c] = (_head[c]+1)%RING_SIZE; } // printf("WGTTQueue before _q[_tail] = p\n"); // Packet *tmp = _q[_tail]; // printf("_tail: %x\n", _tail); - _q[_tail] = p; + _q[c][_tail[c]] = p; // printf("WGTTQueue finish _q[_tail] = p\n"); - _tail = (_tail+1)%RING_SIZE; + _tail[c] = (_tail[c]+1)%RING_SIZE; // printf("WGTTQueue finish enRing\n"); } inline Packet * WGTTQueue::deRing() { - if(_block || _head==_tail) + int i; + bool flag = false;//no pick out + Packet *p; + //next_client after function + unsigned char next_client_after = (next_client+1)%MAX_N_CLIENT; + for(i=0; i @@ -32,11 +20,6 @@ DeDupTCPPacket::DeDupTCPPacket() _queue.pop(); } -DeDupTCPPacket::~DeDupTCPPacket() -{ - // Does something need to be here? -} - Packet * diff --git a/elements/tcpudp/deduptcppacket.hh b/elements/tcpudp/deduptcppacket.hh index 2047e71316..a81918772e 100755 --- a/elements/tcpudp/deduptcppacket.hh +++ b/elements/tcpudp/deduptcppacket.hh @@ -1,3 +1,10 @@ +/* + Deduplication. + Input: upload raw data packet (eth+ip+x), must checkIPHeader first + Output: deduplicated data packet + Created by Zhenyu Song: sunnyszy@gmail.com + */ + #ifndef CLICK_DEDUPTCPPACKET_HH #define CLICK_DEDUPTCPPACKET_HH #include @@ -13,7 +20,6 @@ CLICK_DECLS class DeDupTCPPacket : public Element { public: DeDupTCPPacket(); - ~DeDupTCPPacket(); const char *class_name() const { return "DeDupTCPPacket"; } const char *port_count() const { return PORTS_1_1X2; } diff --git a/elements/tcpudp/idadder.cc b/elements/tcpudp/idadder.cc index e558d3be40..1c2fc40798 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/tcpudp/idadder.cc @@ -1,20 +1,8 @@ /* - * udpipencaptun.{cc,hh} -- element encapsulates packet in UDP/IP header - * Benjie Chen, Eddie Kohler, Hansen Qian - * - * Copyright (c) 1999-2000 Massachusetts Institute of Technology - * Copyright (c) 2007 Regents of the University of California - * Copyright (c) 2016 Princeton University - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, subject to the conditions - * listed in the Click LICENSE file. These conditions include: you must - * preserve this copyright notice, and you cannot mention the copyright - * holders in advertising related to the Software without their permission. - * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This - * notice is a summary of the Click LICENSE file; the license in that file is - * legally binding. + idadder program, add id and push for queue ring in ap processing. + Input: [data pkt] + Output:[eth][id][data pkt], id is one Byte + Created by Zhenyu Song: sunnyszy@gmail.com */ #include @@ -23,40 +11,19 @@ #include #include - - CLICK_DECLS - - - +CLICK_DECLS IDAdder::IDAdder() { - // printf("idadder in init\n"); - counter = 0; - + int i; + for(i=0; ipush(sizeof(click_ether)+1); - for(int i = 1;iclone(); WritablePacket *p = p_tmp->uniqueify(); + // data + memcpy(p->data()+sizeof(click_ether), &counter[port], 1); + // eth switch(i) - { - case 0:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh.ether_dhost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh.ether_dhost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh.ether_dhost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh.ether_dhost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh.ether_dhost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh.ether_dhost);break; - } - - memcpy(p->data()+sizeof(click_ether), &counter, 1); + { + case 0:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh.ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh.ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh.ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh.ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh.ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh.ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh.ether_dhost);break; + } memcpy(p->data(), &_ethh, sizeof(click_ether)); // printf("idadder push %dth\n", i); output(0).push(p); } - WritablePacket *p = p_in->uniqueify(); + //data + memcpy(p->data()+sizeof(click_ether), &counter[port], 1); + //eth cp_ethernet_address(AP1_MAC, _ethh.ether_dhost); - memcpy(p->data()+sizeof(click_ether), &counter, 1); memcpy(p->data(), &_ethh, sizeof(click_ether)); - counter ++; + counter[port]++; output(0).push(p); } diff --git a/elements/tcpudp/idadder.hh b/elements/tcpudp/idadder.hh index 0e356edeb4..5dec0f79d7 100755 --- a/elements/tcpudp/idadder.hh +++ b/elements/tcpudp/idadder.hh @@ -1,3 +1,10 @@ +/* + idadder program, add id and push for queue ring in ap processing. + Input: [data pkt] + Output:[eth][id][data pkt], id is one Byte + Created by Zhenyu Song: sunnyszy@gmail.com + */ + #ifndef CLICK_IDADDER_HH #define CLICK_IDADDER_HH #include @@ -13,20 +20,17 @@ class IDAdder : public Element { public: IDAdder() CLICK_COLD; - ~IDAdder() CLICK_COLD; const char *class_name() const { return "IDAdder"; } - const char *port_count() const { return "1/1"; } + const char *port_count() const { return "4/1"; } const char *flags() const { return "A"; } - // int configure(Vector &, ErrorHandler *) CLICK_COLD; - int initialize(ErrorHandler*) CLICK_COLD; void push(int port, Packet *p_in); private: - unsigned char counter; + unsigned char counter[MAX_N_CLIENT]; click_ether _ethh; diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 17b8e21a2b..528e465161 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -95,7 +95,17 @@ void PacketSelectionSerial::reset_ap() // // data part memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - cp_ethernet_address(AP_MAC[i], _ethh->ether_dhost);break; + switch(i) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } memcpy(p->data(), _ethh, sizeof(click_ether)); printf("controller reset ap %X\n", i); @@ -108,7 +118,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) { const unsigned char & c = client_ip(p_in); - state[c-CLIENT_IP_SUFFIX[0]] = IDLE; + state[c-CLIENT1_IP_SUFFIX] = IDLE; printf("switch request ack, ip: %d.\n", c); p_in -> kill(); @@ -120,10 +130,10 @@ void PacketSelectionSerial::push_status(Packet *p_in) unsigned char c; switch(status_mac(p_in)) { - case CLIENT_MAC_SUFFIX[0]: c = 0;break; - case CLIENT_MAC_SUFFIX[1]: c = 1;break; - case CLIENT_MAC_SUFFIX[2]: c = 2;break; - case CLIENT_MAC_SUFFIX[3]: c = 3;break; + case CLIENT1_MAC_SUFFIX: c = 0;break; + case CLIENT2_MAC_SUFFIX: c = 1;break; + case CLIENT3_MAC_SUFFIX: c = 2;break; + case CLIENT4_MAC_SUFFIX: c = 3;break; } //since the score are minus, we minus again score[c][a][next_score_id[c][a]] = - status_score(p_in); @@ -134,11 +144,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) tmp_counter++; if(!(tmp_counter%print_interval)) { + int rx_rate = status_rxrate(p_in); + int tx_rate = status_txrate(p_in); printf("client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); printf("signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); printf("rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", - status_rxrate(p_in) / 1000, status_rxrate(p_in) / 100 - status_txrate(p_in) / 1000, status_txrate(p_in) / 100); + rx_rate / 1000, rx_rate / 100, tx_rate / 1000, tx_rate / 100); } gettimeofday(&tv, NULL); @@ -167,11 +178,21 @@ void PacketSelectionSerial::push_status(Packet *p_in) WritablePacket *p = Packet::make(sizeof(click_ether)+2); // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); // // data part - control_content[0] = CLIENT_IP_SUFFIX[c]; + control_content[0] = CLIENT1_IP_SUFFIX + c; control_content[1] = best_ap; memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - cp_ethernet_address(AP_MAC[output_port[c]], _ethh->ether_dhost); + switch(output_port[c]) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } memcpy(p->data(), _ethh, sizeof(click_ether)); printf("Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index b75a4b7379..f75932c7df 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -21,6 +21,11 @@ // client 1 ip #define MAX_N_CLIENT 4 +#define CLIENT1_MAC_SUFFIX 0x01 +#define CLIENT2_MAC_SUFFIX 0x02 +#define CLIENT3_MAC_SUFFIX 0x03 +#define CLIENT4_MAC_SUFFIX 0x04 + // ap #define MAX_N_AP 8 @@ -56,15 +61,19 @@ #define start_seq(p) *(p->data()+15) // seq in data pkt #define queue_seq(p) *(p->data()+14) +#define data_client(p) *(p->data()+20) -unsigned char CLIENT_IP_SUFFIX[MAX_N_CLIENT] = {135, 136, 137, 138}; -unsigned short SERVER_PORT[MAX_N_CLIENT] = {5201, 5202, 5203, 5204}; -unsigned char AP_IP_SUFFIX[MAX_N_AP] = {1, 2, 3, 4, 5, 6, 7, 8}; -char *AP_MAC[MAX_N_AP] = {"70:88:6b:80:60:01", "70:88:6b:80:60:02", "70:88:6b:80:60:03" - "70:88:6b:80:60:04", "70:88:6b:80:60:05", "70:88:6b:80:60:06", "70:88:6b:80:60:07" - "70:88:6b:80:60:08"}; -//made up last two client mac -unsigned char CLIENT_MAC_SUFFIX[MAX_N_CLIENT] = {0x07, 0xac, 0x01, 0x02}; +#define CLIENT1_IP_SUFFIX 135 +#define AP1_MAC "70:88:6b:80:60:01" +#define AP2_MAC "70:88:6b:80:60:02" +#define AP3_MAC "70:88:6b:80:60:03" +#define AP4_MAC "70:88:6b:80:60:04" +#define AP5_MAC "70:88:6b:80:60:05" +#define AP6_MAC "70:88:6b:80:60:06" +#define AP7_MAC "70:88:6b:80:60:07" +#define AP8_MAC "70:88:6b:80:60:08" +// char *CLIENT_MAC[MAX_N_CLIENT] = {"44:c3:06:31:5b:01", "44:c3:06:31:5b:02", "44:c3:06:31:5b:03", +// "44:c3:06:31:5b:04"}; -#endif /* !_WGTT_H_ */ +#endif _WGTT_H_ From 028a3d9c5c95d3f7dbde5fcb9c01a9b8c947581a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 17 Dec 2016 14:28:36 -0500 Subject: [PATCH 091/171] debug: N_CLIENT in csisep --- elements/ip/csisep.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 282a3cdbb9..0a5e4a05e1 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -72,8 +72,8 @@ CSISep::fragment(Packet *p_in) else { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - WritablePacket *p_csi = Packet::make(11*N_CLIENT); - for (i = 0; i < N_CLIENT; i += sizeof(struct iwinfo_assoclist_entry)) + WritablePacket *p_csi = Packet::make(11*MAX_N_CLIENT); + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { e = (struct iwinfo_assoclist_entry *) &buf[i]; uint8_t & mac = e->mac[5]; From a73e2b06c142b7c2e1de664f67ec9b2d6a58dec2 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 17 Dec 2016 18:47:46 -0500 Subject: [PATCH 092/171] click mac to random --- include/clicknet/wgtt.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index f75932c7df..db9a198754 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -21,10 +21,10 @@ // client 1 ip #define MAX_N_CLIENT 4 -#define CLIENT1_MAC_SUFFIX 0x01 -#define CLIENT2_MAC_SUFFIX 0x02 -#define CLIENT3_MAC_SUFFIX 0x03 -#define CLIENT4_MAC_SUFFIX 0x04 +#define CLIENT1_MAC_SUFFIX 0x07 +#define CLIENT2_MAC_SUFFIX 0x08 +#define CLIENT3_MAC_SUFFIX 0x09 +#define CLIENT4_MAC_SUFFIX 0x0a // ap #define MAX_N_AP 8 From fca508b00ebb45d45a6a808a4728a8e9172bc945 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 17 Dec 2016 19:46:25 -0500 Subject: [PATCH 093/171] packet selection will print switch interval --- elements/ip/csisep.cc | 4 ++-- elements/standard/wgttqueue.cc | 16 ++++++++++++---- elements/standard/wgttqueue.hh | 9 ++++++++- elements/tcpudp/packetselectionSerial.cc | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 0a5e4a05e1..c6b92bd9b8 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -66,9 +66,9 @@ CSISep::fragment(Packet *p_in) sample_counter = 0; if (iw->assoclist(ifname, buf, &len)) - printf("CSISep: can not find associlist\n"); + // printf("CSISep: can not find associlist\n"); else if (len <= 0) - printf("CSISep: associ number < 0\n"); + // printf("CSISep: associ number < 0\n"); else { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index e399e9ba40..8b4f218546 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -151,7 +151,7 @@ void WGTTQueue::push_control(Packet *p_in) _q[c][_head[c]] -> kill(); _head[c] = (_head[c]+1)%RING_SIZE; } - printf("wgttQueue finish ap-ap dequeue\n"); + // printf("wgttQueue finish ap-ap dequeue\n"); WritablePacket *p = Packet::make(sizeof(click_ether)+2); @@ -175,14 +175,22 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { const unsigned char & seq = queue_seq(p_in); - unsigned char c = data_client(p_in) - 1; - printf("wgttQueue in push data for client: %d\n", c+1); + unsigned char c; + switch(data_client(p_in)) + { + case CLIENT1_MAC_SUFFIX: c=0;break; + case CLIENT2_MAC_SUFFIX: c=1;break; + case CLIENT3_MAC_SUFFIX: c=2;break; + case CLIENT4_MAC_SUFFIX: c=3;break; + } + // printf("wgttQueue in push data for client: %d\n", c+1); while(_tail[c] != seq) { + // printf("wgttQueue: before for client: %d\n", c+1); enRing(c, 0); } p_in -> pull(15); - printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + // printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh index 4d25eec12e..c16a80742e 100644 --- a/elements/standard/wgttqueue.hh +++ b/elements/standard/wgttqueue.hh @@ -59,7 +59,7 @@ WGTTQueue::enRing(unsigned char c, Packet *p) if((_tail[c]+1)%RING_SIZE == _head[c])//override { // printf("WGTTQueue override\n"); - if(_q[c][_head[c]] != 0) + if(_q[c][_head[c]]) _q[c][_head[c]] -> kill(); _head[c] = (_head[c]+1)%RING_SIZE; } @@ -84,15 +84,22 @@ WGTTQueue::deRing() { if(_block[next_client] || _head[next_client]==_tail[next_client]) continue; + while((_head[next_client]+1)%MAX_N_CLIENT != _tail[next_client] + && !_head[next_client]) + _head[next_client] = (_head[next_client]+1)%RING_SIZE; flag = true; p = _q[next_client][_head[next_client]]; + _head[next_client] = (_head[next_client]+1)%RING_SIZE; break; } next_client = next_client_after; if(flag) + { + // printf("wgttQueue: deque succeed\n"); return p; + } else return 0; } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index 528e465161..ae6fec8152 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -63,7 +63,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) output_port[i] = first_start[i]-1; } - printf("PacketSelectionSerial out. interval: %d\n", interval); + printf("PacketSelectionSerial out. Switch interval: %d\n", interval); return 0; } From 5a8e00cff348efe8f3ed459095e33e59c8c74e9c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 17 Dec 2016 20:12:47 -0500 Subject: [PATCH 094/171] less print --- elements/ip/csisep.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index c6b92bd9b8..17de550a54 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -65,11 +65,11 @@ CSISep::fragment(Packet *p_in) { sample_counter = 0; - if (iw->assoclist(ifname, buf, &len)) - // printf("CSISep: can not find associlist\n"); - else if (len <= 0) - // printf("CSISep: associ number < 0\n"); - else + if(!(iw->assoclist(ifname, buf, &len))) + // // printf("CSISep: can not find associlist\n"); + // else if (len <= 0) + // // printf("CSISep: associ number < 0\n"); + // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); WritablePacket *p_csi = Packet::make(11*MAX_N_CLIENT); From 16ad944bf7e5dae7c791fb598fa803483eadf41f Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 18 Dec 2016 15:00:42 -0500 Subject: [PATCH 095/171] max client to normal value --- elements/standard/wgttqueue.cc | 13 +++++++++---- elements/tcpudp/packetselectionSerial.cc | 11 ++++++----- include/clicknet/wgtt.h | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 8b4f218546..d6999b2a7d 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -32,14 +32,19 @@ int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { //printf("In configure\n"); + int tmp[4], i; if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) - .read_p("FIRSTSTART1", IntArg(), first_start[0]) - .read_p("FIRSTSTART2", IntArg(), first_start[1]) - .read_p("FIRSTSTART3", IntArg(), first_start[2]) - .read_p("FIRSTSTART4", IntArg(), first_start[3]) + .read_p("FIRSTSTART1", IntArg(), tmp[0]) + .read_p("FIRSTSTART2", IntArg(), tmp[1]) + .read_p("FIRSTSTART3", IntArg(), tmp[2]) + .read_p("FIRSTSTART4", IntArg(), tmp[3]) .complete() < 0) return -1; + for(i=0;i &conf, ErrorHandler *errh) { - int i; + int i,tmp[4]; if (Args(conf, this, errh) .read_p("INTERVAL", IntArg(), interval) - .read_p("FIRSTSTART1", IntArg(), first_start[0]) - .read_p("FIRSTSTART2", IntArg(), first_start[1]) - .read_p("FIRSTSTART3", IntArg(), first_start[2]) - .read_p("FIRSTSTART4", IntArg(), first_start[3]) + .read_p("FIRSTSTART1", IntArg(), tmp[0]) + .read_p("FIRSTSTART2", IntArg(), tmp[1]) + .read_p("FIRSTSTART3", IntArg(), tmp[2]) + .read_p("FIRSTSTART4", IntArg(), tmp[3]) .read_p("PRINTINTERVAL", IntArg(), print_interval) .complete() < 0) return -1; for(i=0; i Date: Sun, 18 Dec 2016 15:35:24 -0500 Subject: [PATCH 096/171] debug: segmentation fault --- elements/standard/wgttqueue.cc | 33 ++++++++++++------------ elements/tcpudp/packetselectionSerial.cc | 2 +- include/clicknet/wgtt.h | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index d6999b2a7d..584dcf9245 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -63,25 +63,26 @@ WGTTQueue::initialize(ErrorHandler *errh) _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); switch(identity-1) { - case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_shost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_shost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_shost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_shost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_shost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_shost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; } switch(i) { - case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_shost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_shost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_shost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_shost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_shost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_shost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_shost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_shost);break; + case 0:cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; + case 8:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; } } diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/tcpudp/packetselectionSerial.cc index df47724b4d..1af13d8eee 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/tcpudp/packetselectionSerial.cc @@ -155,7 +155,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) gettimeofday(&tv, NULL); double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; - if(now_time - last_time[c] > 1000) + if(now_time - last_time[c] > SWITCH_MIN) time_lock[c] = false; if(state[c] == IDLE && !time_lock[c]) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index c7c4a818b8..e8a3a4abb4 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -37,7 +37,7 @@ #define RING_SIZE 256 // 1000 ms -#define SWITCH_MIN 1000 +#define SWITCH_MIN 100000 // content encapsulated in mac header #define RESET_CONTENT 0xff From eb7216a6e824b99f0bb1d2e9a78966c02acf440a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 18 Dec 2016 15:55:42 -0500 Subject: [PATCH 097/171] update mac for client 2 --- include/clicknet/wgtt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index e8a3a4abb4..c3050f94d8 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -22,7 +22,7 @@ #define MAX_N_CLIENT 2 #define CLIENT1_MAC_SUFFIX 0x07 -#define CLIENT2_MAC_SUFFIX 0x08 +#define CLIENT2_MAC_SUFFIX 0xD0 #define CLIENT3_MAC_SUFFIX 0x09 #define CLIENT4_MAC_SUFFIX 0x0a @@ -76,4 +76,4 @@ // char *CLIENT_MAC[MAX_N_CLIENT] = {"44:c3:06:31:5b:01", "44:c3:06:31:5b:02", "44:c3:06:31:5b:03", // "44:c3:06:31:5b:04"}; -#endif _WGTT_H_ +#endif _WGTT_H_ \ No newline at end of file From fdcddd3954a9bbbfb17046ec868113b22ef8c88a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 18 Dec 2016 17:02:51 -0500 Subject: [PATCH 098/171] debug --- elements/standard/wgttqueue.cc | 9 ++++++++- elements/standard/wgttqueue.hh | 7 +++++++ include/clicknet/wgtt.h | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 584dcf9245..9f6858496c 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -56,7 +56,11 @@ WGTTQueue::initialize(ErrorHandler *errh) //printf("wgtt in initialize\n"); int i; for(i=0; i Date: Sun, 18 Dec 2016 20:23:27 -0500 Subject: [PATCH 099/171] debug --- elements/ip/csisep.cc | 14 +++++++------- elements/standard/wgttqueue.cc | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/elements/ip/csisep.cc b/elements/ip/csisep.cc index 17de550a54..04582d6715 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/csisep.cc @@ -59,7 +59,7 @@ void CSISep::fragment(Packet *p_in) { #ifdef __arm__ - int i, j=0; + int i,j; sample_counter ++; if(sample_counter>sample_rate) { @@ -72,9 +72,12 @@ CSISep::fragment(Packet *p_in) // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - WritablePacket *p_csi = Packet::make(11*MAX_N_CLIENT); + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) { + //one pkt per client + WritablePacket *p_csi = Packet::make(11); + j=0; e = (struct iwinfo_assoclist_entry *) &buf[i]; uint8_t & mac = e->mac[5]; int8_t & signal = e->signal; @@ -92,12 +95,9 @@ CSISep::fragment(Packet *p_in) j += 4; memcpy(p_csi->data()+j, &(tx_rate), 4); j += 4; - // printf("RateSignal: %d\n", e->signal); - // printf("RateNoise: %d\n", e->noise); - // printf("RateRXRaw: %d\n", (e->rx_rate).rate); - // printf("RateTXRaw: %d\n", (e->tx_rate).rate); + output(1).push(p_csi); } - output(1).push(p_csi); + } } #endif diff --git a/elements/standard/wgttqueue.cc b/elements/standard/wgttqueue.cc index 9f6858496c..b1aa32edd0 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/standard/wgttqueue.cc @@ -21,6 +21,7 @@ WGTTQueue::WGTTQueue() _head[i] = 0; _tail[i] = 0; } + // 0: controller, 1-MAX_N_AP: ap _ethh = new click_ether[MAX_N_AP+1]; next_client = 0; printf("wgtt init succeed\n"); @@ -78,15 +79,16 @@ WGTTQueue::initialize(ErrorHandler *errh) } switch(i) { - case 0:cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; - case 8:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + case 0:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[i].ether_dhost);break; + case 1:cp_ethernet_address(AP1_MAC, _ethh[i].ether_dhost);break; + case 2:cp_ethernet_address(AP2_MAC, _ethh[i].ether_dhost);break; + case 3:cp_ethernet_address(AP3_MAC, _ethh[i].ether_dhost);break; + case 4:cp_ethernet_address(AP4_MAC, _ethh[i].ether_dhost);break; + case 5:cp_ethernet_address(AP5_MAC, _ethh[i].ether_dhost);break; + case 6:cp_ethernet_address(AP6_MAC, _ethh[i].ether_dhost);break; + case 7:cp_ethernet_address(AP7_MAC, _ethh[i].ether_dhost);break; + case 8:cp_ethernet_address(AP8_MAC, _ethh[i].ether_dhost);break; + } } @@ -142,7 +144,7 @@ void WGTTQueue::push_control(Packet *p_in) printf("wgttQueue: switch to ap: %d\n", dst_ap+1); printf("wgttQueue: switch id: %X\n", _head[c]); memcpy(p->data()+sizeof(click_ether), &control_content, 2); - memcpy(p->data(), &(_ethh[dst_ap]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[dst_ap+1]), sizeof(click_ether)); p_in -> kill(); printf("wgttQueue send ap-ap seq\n"); @@ -172,7 +174,7 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 2); //ether part - memcpy(p->data(), &(_ethh[MAX_N_AP]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[0]), sizeof(click_ether)); p_in -> kill(); // printf("ap-c packet push\n"); From 7fd70466f96006aeeab7d443d4c6d83c03311ccc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 19 Dec 2016 14:54:40 -0500 Subject: [PATCH 100/171] 8 ap --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 64dffb5bef..1ce47da26a 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -27,7 +27,7 @@ #define CLIENT4_MAC_SUFFIX 0x0a // ap -#define MAX_N_AP 2 +#define MAX_N_AP 8 // controller #define CONTROLLER_IN_IP_SUFFIX 68 From 938a2d8bcc8f453fcbd40b49f470243852038ded Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 19 Dec 2016 15:24:35 -0500 Subject: [PATCH 101/171] switch faster --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 1ce47da26a..5e386d2e06 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -37,7 +37,7 @@ #define RING_SIZE 256 // 1000 ms -#define SWITCH_MIN 1000 +#define SWITCH_MIN 500 // content encapsulated in mac header #define RESET_CONTENT 0xff From f6c0e1f583d44fb8b6c654c374ae3a6f560c5f3f Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 22 Dec 2016 15:39:20 -0500 Subject: [PATCH 102/171] change client2 macaddr --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 5e386d2e06..a487f88d3d 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -22,7 +22,7 @@ #define MAX_N_CLIENT 2 #define CLIENT1_MAC_SUFFIX 0x07 -#define CLIENT2_MAC_SUFFIX 0xD0 +#define CLIENT2_MAC_SUFFIX 0xb1 #define CLIENT3_MAC_SUFFIX 0x09 #define CLIENT4_MAC_SUFFIX 0x0a From 8854cb4655725be6cb20121164dee293014a49fe Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 23 Dec 2016 10:08:43 -0500 Subject: [PATCH 103/171] 6 aps --- include/clicknet/wgtt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index a487f88d3d..4d388120ad 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -19,7 +19,7 @@ #define SWITCH_REQ 1 // client 1 ip -#define MAX_N_CLIENT 2 +#define MAX_N_CLIENT 1 #define CLIENT1_MAC_SUFFIX 0x07 #define CLIENT2_MAC_SUFFIX 0xb1 @@ -27,7 +27,7 @@ #define CLIENT4_MAC_SUFFIX 0x0a // ap -#define MAX_N_AP 8 +#define MAX_N_AP 6 // controller #define CONTROLLER_IN_IP_SUFFIX 68 From 9dfa8bd1c47bd5fc9735ed69ff6121ff8ecb21b8 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 30 Dec 2016 16:55:01 -0500 Subject: [PATCH 104/171] add support for 80211r --- elements/ip/80211r/rapcontrol.cc | 207 ++++++++++++++++++ elements/ip/80211r/rapcontrol.hh | 46 ++++ elements/ip/80211r/rclientcontrol.cc | 165 ++++++++++++++ elements/ip/80211r/rclientcontrol.hh | 46 ++++ elements/ip/80211r/rcontrollercontrol.cc | 142 ++++++++++++ elements/ip/80211r/rcontrollercontrol.hh | 41 ++++ elements/ip/80211r/rssibecon.cc | 108 +++++++++ elements/ip/80211r/rssibecon.hh | 54 +++++ elements/ip/{ => wgtt}/csisep.cc | 14 +- elements/ip/{ => wgtt}/csisep.hh | 11 +- .../{tcpudp => ip/wgtt}/deduptcppacket.cc | 12 +- .../{tcpudp => ip/wgtt}/deduptcppacket.hh | 3 +- elements/{tcpudp => ip/wgtt}/idadder.cc | 6 +- elements/{tcpudp => ip/wgtt}/idadder.hh | 2 +- .../wgtt}/packetselectionSerial.cc | 22 +- .../wgtt}/packetselectionSerial.hh | 2 +- elements/{standard => ip/wgtt}/wgttqueue.cc | 101 +++++++-- elements/ip/wgtt/wgttqueue.hh | 61 ++++++ elements/standard/wgttqueue.hh | 117 ---------- .../tcpudp/packetselectionPeriodicSwitch.cc | 88 -------- .../tcpudp/packetselectionPeriodicSwitch.hh | 39 ---- include/clicknet/wgtt.h | 46 ++-- make.sh | 1 + 23 files changed, 1013 insertions(+), 321 deletions(-) create mode 100755 elements/ip/80211r/rapcontrol.cc create mode 100755 elements/ip/80211r/rapcontrol.hh create mode 100755 elements/ip/80211r/rclientcontrol.cc create mode 100755 elements/ip/80211r/rclientcontrol.hh create mode 100755 elements/ip/80211r/rcontrollercontrol.cc create mode 100755 elements/ip/80211r/rcontrollercontrol.hh create mode 100644 elements/ip/80211r/rssibecon.cc create mode 100644 elements/ip/80211r/rssibecon.hh rename elements/ip/{ => wgtt}/csisep.cc (84%) rename elements/ip/{ => wgtt}/csisep.hh (89%) rename elements/{tcpudp => ip/wgtt}/deduptcppacket.cc (84%) rename elements/{tcpudp => ip/wgtt}/deduptcppacket.hh (97%) rename elements/{tcpudp => ip/wgtt}/idadder.cc (92%) rename elements/{tcpudp => ip/wgtt}/idadder.hh (97%) rename elements/{tcpudp => ip/wgtt}/packetselectionSerial.cc (90%) rename elements/{tcpudp => ip/wgtt}/packetselectionSerial.hh (98%) rename elements/{standard => ip/wgtt}/wgttqueue.cc (62%) create mode 100644 elements/ip/wgtt/wgttqueue.hh delete mode 100644 elements/standard/wgttqueue.hh delete mode 100755 elements/tcpudp/packetselectionPeriodicSwitch.cc delete mode 100755 elements/tcpudp/packetselectionPeriodicSwitch.hh diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc new file mode 100755 index 0000000000..f634d2b90b --- /dev/null +++ b/elements/ip/80211r/rapcontrol.cc @@ -0,0 +1,207 @@ +/* + element for 802.11r ap, + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "rapcontrol.hh" +#include +#include +#include +#include +#include + + CLICK_DECLS + +int +RAPControl::configure(Vector &conf, ErrorHandler *errh) +{ + int i, tmp_start[4],tmp_id; + + openlog ("RAPControl", LOG_CONS | LOG_NDELAY, 0); + + _ethh = new click_ether[MAX_N_CLIENT]; + if (Args(conf, this, errh) + .read_p("IDENTITY", IntArg(), tmp_id) + .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) + .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) + .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) + .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) + .complete() < 0) + return -1; + + identity = tmp_id; + for(i=0;idata(), &control_content, 4); + + syslog (LOG_INFO, "ap %d pass deassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + output(0).push(p); + } + else if(state[c-1] == INACTIVE && t == 0x0a && tar == identity - 1) + { + control_content[0] = 0x0b; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(4); + // // data part + memcpy(p->data(), &control_content, 4); + + syslog (LOG_INFO, "ap %d pass reassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + output(0).push(p); + } + p_in -> kill(); + +} + +void RAPControl::push_down_control(Packet*p_in) +{ + const unsigned char & t = r_control_type(p_in); + const unsigned char & c = r_control_client(p_in); + const unsigned char & ori = r_control_ori(p_in); + const unsigned char & tar = r_control_tar(p_in); + + if(state[c-1] == IDLE && t == 0x06 && tar == identity-1) + { + control_content[0] = 0x07; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(4); + // // data part + memcpy(p->data(), &control_content, 4); + + syslog (LOG_INFO, "ap %d ack authetication for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + output(0).push(p); + } + else if(state[c-1] == IDLE && t == 0x08 && ori == identity-1) + { + state[c] = INACTIVE; + control_content[0] = 0x09; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); + syslog (LOG_INFO, "ap %d pass authetication ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + output(1).push(p); + } + else if(state[c-1] == INACTIVE && t == 0x0c && tar == identity-1) + { + state[c] = IDLE; + control_content[0] = 0x0d; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); + syslog (LOG_INFO, "ap %d pass reassociation ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + output(1).push(p); + } + p_in -> kill(); + +} + +void RAPControl::push_down_data(Packet*p_in) +{ + static unsigned char c; + switch(r_dst_mac_suffix(p_in)) + { + case CLIENT1_MAC_SUFFIX: c = 0;break; + case CLIENT2_MAC_SUFFIX: c = 1;break; + case CLIENT3_MAC_SUFFIX: c = 2;break; + case CLIENT4_MAC_SUFFIX: c = 3;break; + } + if(state[c] == INACTIVE) + p_in -> kill(); + else + output(2).push(p_in); + +} + +void RAPControl::push_up_data(Packet*p_in) +{ + static unsigned char c; + switch(r_src_mac_suffix(p_in)) + { + case CLIENT1_MAC_SUFFIX: c = 0;break; + case CLIENT2_MAC_SUFFIX: c = 1;break; + case CLIENT3_MAC_SUFFIX: c = 2;break; + case CLIENT4_MAC_SUFFIX: c = 3;break; + } + if(state[c] == INACTIVE) + p_in -> kill(); + else + output(1).push(p_in); +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(RAPControl) +ELEMENT_MT_SAFE(RAPControl) diff --git a/elements/ip/80211r/rapcontrol.hh b/elements/ip/80211r/rapcontrol.hh new file mode 100755 index 0000000000..79bd2b8499 --- /dev/null +++ b/elements/ip/80211r/rapcontrol.hh @@ -0,0 +1,46 @@ +/* + element for 802.11r ap, + Created by Zhenyu Song: sunnyszy@gmail.com + */ +#ifndef CLICK_RAPCONTROL_HH +#define CLICK_RAPCONTROL_HH +#include +#include +#include +#include +#include +#include + +CLICK_DECLS + + +class RAPControl : public Element { public: + + + const char *class_name() const { return "RAPControl"; } + const char *port_count() const { return "4/3"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *); + void push_up_control(Packet *); + void push_up_data(Packet *); + void push_down_control(Packet *); + void push_down_data(Packet *); + + + private: + unsigned char identity; + unsigned char state[MAX_N_CLIENT]; + unsigned char first_start[MAX_N_CLIENT]; + + click_ether * _ethh; + unsigned char control_content[4]; + + + +}; + +CLICK_ENDDECLS +#endif diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc new file mode 100755 index 0000000000..3805fea246 --- /dev/null +++ b/elements/ip/80211r/rclientcontrol.cc @@ -0,0 +1,165 @@ +/* + element for 802.11r client, + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "rclientcontrol.hh" +#include +#include +#include +#include +#include + + CLICK_DECLS + +int +RClientControl::configure(Vector &conf, ErrorHandler *errh) +{ + int i, tmp_start[4],tmp_id; + for(i=0;iether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); + + switch(identity) + { + case 1: cp_ethernet_address(CLIENT1_MAC, _ethh->ether_shost);break; + } + cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_dhost); + + return 0; +} + +void +RClientControl::push(int port, Packet *p_in) +{ + switch(port) + { + case 0: push_updata(p_in);break; + case 1: push_control(p_in);break; + case 2: push_downdata(p_in);break; + case 3: push_80211(p_in);break; + } +} + + +void RClientControl::push_control(Packet*p_in) +{ + const unsigned char & t = r_control_type(p_in); + const unsigned char & c = r_control_client(p_in); + const unsigned char & ori = r_control_ori(p_in); + const unsigned char & tar = r_control_tar(p_in); + + if(state == ANT && t == 0x09) + { + state = INACTIVE; + control_content[0] = 0x09; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_INFO, "client receive deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + output(0).push(p); + } + else if(state == INACTIVE && t == 0x0d) + { + state = IDLE; + syslog (LOG_INFO, "client become inactive for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + } + p_in -> kill(); + +} + +void RClientControl::push_downdata(Packet*p_in) +{ + if(state == INACTIVE) + p_in -> kill(); + else + output(1).push(p_in); + +} + +void RClientControl::push_updata(Packet*p_in) +{ + if(state == INACTIVE) + p_in -> kill(); + else + output(0).push(p_in); +} +void RClientControl::push_80211(Packet*p_in) +{ + //TODO: filter and parse from click or here? + const char & rssi_this = status_score(p_in); + const unsigned char ap = status_ap(p_in) - 1; + static unsigned char c; + switch(status_mac(p_in)) + { + case CLIENT1_MAC_SUFFIX: c = 1; + case CLIENT2_MAC_SUFFIX: c = 2; + case CLIENT3_MAC_SUFFIX: c = 3; + case CLIENT4_MAC_SUFFIX: c = 4; + } + if(c == identity) + rssi[ap] = rssi_this; + // if IDLE, considering switching + if(c == identity && state == IDLE && rssi[current_ap] < RSSI_THRESHOLD) + { + unsigned i; + unsigned max_id; + char max_rssi = -255; + // find max rssi + for(i=0;i max_rssi) + { + max_rssi = rssi[i]; + max_id = i; + } + if(max_id == current_ap) + return; + + control_content[0] = 0x04; + control_content[1] = identity-1; + control_content[2] = current_ap; + control_content[3] = max_id; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_INFO, "client send anthentication for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap, max_id); + current_ap = max_id; + state = ANT; + output(0).push(p); + } + +} + + +CLICK_ENDDECLS +EXPORT_ELEMENT(RClientControl) +ELEMENT_MT_SAFE(RClientControl) diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh new file mode 100755 index 0000000000..b9a246cf48 --- /dev/null +++ b/elements/ip/80211r/rclientcontrol.hh @@ -0,0 +1,46 @@ +/* + element for 802.11r client, + Created by Zhenyu Song: sunnyszy@gmail.com + */ +#ifndef CLICK_RCLIENTCONTROL_HH +#define CLICK_RCLIENTCONTROL_HH +#include +#include +#include +#include +#include +#include + +CLICK_DECLS + + +class RClientControl : public Element { public: + + + const char *class_name() const { return "RClientControl"; } + const char *port_count() const { return "4/2"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *); + void push_control(Packet *); + void push_80211(Packet *); + void push_downdata(Packet *); + void push_updata(Packet *); + + private: + char rssi[MAX_N_AP]; + unsigned char identity; + unsigned char state; + unsigned char current_ap; + + click_ether * _ethh; + unsigned char control_content[4]; + + + +}; + +CLICK_ENDDECLS +#endif diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc new file mode 100755 index 0000000000..a0c6391d41 --- /dev/null +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -0,0 +1,142 @@ +/* + element for 802.11r ap, + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "rcontrollercontrol.hh" +#include +#include +#include +#include +#include + + CLICK_DECLS + +int +RControlerControl::configure(Vector &conf, ErrorHandler *errh) +{ + + int i, tmp_start[4]; + _ethh = new click_ether[MAX_N_AP]; + if (Args(conf, this, errh) + .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) + .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) + .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) + .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) + .complete() < 0) + return -1; + + for(i=0;idata()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); + + syslog (LOG_INFO, "controller pass deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + output(0).push(p); + } + else if(t == 0x07) + { + control_content[0] = 0x08; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[ori]), sizeof(click_ether)); + + syslog (LOG_INFO, "controller pass deassociation ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + output(0).push(p); + } + else if(t == 0x0b) + { + control_content[0] = 0x0c; + control_content[1] = c; + control_content[2] = ori; + control_content[3] = tar; + + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); + + outport[c] = tar; + syslog (LOG_INFO, "controller ack reassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + output(0).push(p); + } + p_in -> kill(); + +} + +void RControlerControl::push_down_data(Packet*p_in, int port) +{ + WritablePacket *p = p_in->uniqueify(); + p->push(sizeof(click_ether)); + + //eth + memcpy(p->data(), &(_ethh[outport[port-2]]), sizeof(click_ether)); + output(0).push(p); +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(RControlerControl) +ELEMENT_MT_SAFE(RControlerControl) diff --git a/elements/ip/80211r/rcontrollercontrol.hh b/elements/ip/80211r/rcontrollercontrol.hh new file mode 100755 index 0000000000..f70e230f6a --- /dev/null +++ b/elements/ip/80211r/rcontrollercontrol.hh @@ -0,0 +1,41 @@ +/* + element for 802.11r ap, + Created by Zhenyu Song: sunnyszy@gmail.com + */ +#ifndef CLICK_RCONTROLLERCONTROL_HH +#define CLICK_RCONTROLLERCONTROL_HH +#include +#include +#include +#include +#include +#include + +CLICK_DECLS + + +class RControlerControl : public Element { public: + + + const char *class_name() const { return "RControlerControl"; } + const char *port_count() const { return "5/2"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int port, Packet *); + void push_up_control(Packet *); + void push_down_data(Packet *, int); + + + private: + unsigned char outport[MAX_N_CLIENT]; + unsigned char control_content[4]; + click_ether * _ethh; + + + +}; + +CLICK_ENDDECLS +#endif diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc new file mode 100644 index 0000000000..b43d267f1a --- /dev/null +++ b/elements/ip/80211r/rssibecon.cc @@ -0,0 +1,108 @@ +/* + element for 802.11r becon sending, + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "rssibecon.hh" +#include +#include +#include + +CLICK_DECLS + +RSSIBecon::RSSIBecon() +{ +#ifdef __arm__ + syslog (LOG_INFO, "RSSIBecon: finish init\n"); +#endif + +} + +RSSIBecon::~RSSIBecon() +{ +#ifdef __arm__ + iwinfo_finish(); +#endif +} + +int +RSSIBecon::configure(Vector &conf, ErrorHandler *errh) +{ + int wlan_port; + if (Args(conf, this, errh) + .read_p("WLANPORT", IntArg(), wlan_port) + .complete() < 0) + return -1; + +#ifdef __arm__ + if(wlan_port == 0) + strcpy(ifname, "wlan0"); + else if(wlan_port == 1) + strcpy(ifname, "wlan1"); + else + syslog (LOG_INFO, "Invalid wlan_port argument\n"); + iw = iwinfo_backend(ifname); + if (!iw) + syslog (LOG_INFO, "RSSIBecon: can not connect to backend iwinfo\n"); +#endif + syslog (LOG_INFO, "RSSIBecon: finish configure, ready to start\n"); + return 0; +} + +void +RSSIBecon::fragment(Packet *p_in) +{ +#ifdef __arm__ + int i,j; + + if(!(iw->assoclist(ifname, buf, &len))) + // // syslog (LOG_INFO, "RSSIBecon: can not find associlist\n"); + // else if (len <= 0) + // // syslog (LOG_INFO, "RSSIBecon: associ number < 0\n"); + // else if (len) + { + // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); + + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + { + //one pkt per client + WritablePacket *p_csi = Packet::make(11); + j=0; + e = (struct iwinfo_assoclist_entry *) &buf[i]; + uint8_t & mac = e->mac[5]; + int8_t & signal = e->signal; + int8_t & noise = e->noise; + uint32_t & rx_rate = (e->rx_rate).rate; + uint32_t & tx_rate = (e->tx_rate).rate; + + memcpy(p_csi->data()+j, &(mac), 1); + j += 1; + memcpy(p_csi->data()+j, &(signal), 1); + j += 1; + memcpy(p_csi->data()+j, &(noise), 1); + j += 1; + memcpy(p_csi->data()+j, &(rx_rate), 4); + j += 4; + memcpy(p_csi->data()+j, &(tx_rate), 4); + j += 4; + output(0).push(p_csi); + } + + } +#endif + p_in -> kill(); +} + +void +RSSIBecon::push(int, Packet *p) +{ +#ifdef __arm__ + // syslog (LOG_INFO, "RSSIBecon: in push\n"); + fragment(p); +#endif +} + + +CLICK_ENDDECLS +EXPORT_ELEMENT(RSSIBecon) \ No newline at end of file diff --git a/elements/ip/80211r/rssibecon.hh b/elements/ip/80211r/rssibecon.hh new file mode 100644 index 0000000000..e1b586c7db --- /dev/null +++ b/elements/ip/80211r/rssibecon.hh @@ -0,0 +1,54 @@ +/* + element for 802.11r becon sending, + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#ifndef CLICK_RSSIBECON_HH +#define CLICK_RSSIBECON_HH +#include +#include +#include +#include +#include +#include +#ifdef __arm__ +#include +extern "C" +{ + #include "iwinfo.h" +} +#endif + + +CLICK_DECLS + +class RSSIBecon : public Element { public: + + RSSIBecon() CLICK_COLD; + ~RSSIBecon() CLICK_COLD; + + const char *class_name() const { return "RSSIBecon"; } + const char *port_count() const { return "1/1"; } + const char *processing() const { return PUSH; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int, Packet *); + void fragment(Packet *); + + private: + + +#ifdef __arm__ + int len; + const struct iwinfo_ops *iw; + char buf[IWINFO_BUFSIZE]; + char ifname[6]; + struct iwinfo_assoclist_entry *e; +#endif + + +}; + +CLICK_ENDDECLS +#endif diff --git a/elements/ip/csisep.cc b/elements/ip/wgtt/csisep.cc similarity index 84% rename from elements/ip/csisep.cc rename to elements/ip/wgtt/csisep.cc index 04582d6715..a08246896e 100755 --- a/elements/ip/csisep.cc +++ b/elements/ip/wgtt/csisep.cc @@ -16,7 +16,7 @@ CLICK_DECLS CSISep::CSISep() { #ifdef __arm__ - printf("CSISep: finish init\n"); + syslog (LOG_INFO, "CSISep: finish init\n"); // total_msg_cnt = 0; sample_counter = 0; #endif @@ -46,12 +46,12 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - printf("Invalid wlan_port argument\n"); + syslog (LOG_INFO, "Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) - printf("CSISep: can not connect to backend iwinfo\n"); + syslog (LOG_INFO, "CSISep: can not connect to backend iwinfo\n"); #endif - printf("CSISep: finish configure, ready to start\n"); + syslog (LOG_INFO, "CSISep: finish configure, ready to start\n"); return 0; } @@ -66,9 +66,9 @@ CSISep::fragment(Packet *p_in) sample_counter = 0; if(!(iw->assoclist(ifname, buf, &len))) - // // printf("CSISep: can not find associlist\n"); + // // syslog (LOG_INFO, "CSISep: can not find associlist\n"); // else if (len <= 0) - // // printf("CSISep: associ number < 0\n"); + // // syslog (LOG_INFO, "CSISep: associ number < 0\n"); // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); @@ -109,7 +109,7 @@ void CSISep::push(int, Packet *p) { #ifdef __arm__ - // printf("CSISep: in push\n"); + // syslog (LOG_INFO, "CSISep: in push\n"); fragment(p); #endif } diff --git a/elements/ip/csisep.hh b/elements/ip/wgtt/csisep.hh similarity index 89% rename from elements/ip/csisep.hh rename to elements/ip/wgtt/csisep.hh index b7af96aff2..7d0f95582e 100755 --- a/elements/ip/csisep.hh +++ b/elements/ip/wgtt/csisep.hh @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef __arm__ #include extern "C" @@ -21,16 +22,6 @@ extern "C" #endif -struct my_test_struct { - uint8_t mac; - int8_t signal; - int8_t noise; - uint32_t rx_rate; - uint32_t tx_rate; - -}; - - CLICK_DECLS class CSISep : public Element { public: diff --git a/elements/tcpudp/deduptcppacket.cc b/elements/ip/wgtt/deduptcppacket.cc similarity index 84% rename from elements/tcpudp/deduptcppacket.cc rename to elements/ip/wgtt/deduptcppacket.cc index 450ca5e8da..2c7ce3c7a2 100755 --- a/elements/tcpudp/deduptcppacket.cc +++ b/elements/ip/wgtt/deduptcppacket.cc @@ -37,22 +37,22 @@ DeDupTCPPacket::drop(Packet *p) void DeDupTCPPacket::push(int port, Packet *p_in) { - // printf("Packet in\n"); + // syslog (LOG_INFO, "Packet in\n"); // construct link_key WritablePacket *p = p_in->uniqueify(); struct click_ip *iph = p->ip_header(); - // printf("IP id: %x", iph->ip_id); + // syslog (LOG_INFO, "IP id: %x", iph->ip_id); uint64_t tmp_link_key = ((((uint64_t)(iph->ip_id))&0x000000000000ffff)<<32)+ (((uint64_t)((iph->ip_src).s_addr))&0x00000000ffffffff); - // printf("key: %lx\n", tmp_link_key); + // syslog (LOG_INFO, "key: %lx\n", tmp_link_key); std::set::iterator it; it = _set.find(tmp_link_key); if((iph -> ip_id) != 0) { if( it != _set.end()) { - // printf("Packet out.drop\n"); + // syslog (LOG_INFO, "Packet out.drop\n"); drop(p); return; } @@ -61,7 +61,7 @@ DeDupTCPPacket::push(int port, Packet *p_in) //if (_set.size() >= max_elem_num) if (_queue.size() >= max_elem_num) { - // printf("exceed the max size\n"); + // syslog (LOG_INFO, "exceed the max size\n"); uint64_t & link_key_tobe_delete = _queue.front(); _queue.pop(); it = _set.find(link_key_tobe_delete); @@ -72,7 +72,7 @@ DeDupTCPPacket::push(int port, Packet *p_in) _queue.push(tmp_link_key); } } - // printf("Packet out.push\n"); + // syslog (LOG_INFO, "Packet out.push\n"); output(0).push(p); } diff --git a/elements/tcpudp/deduptcppacket.hh b/elements/ip/wgtt/deduptcppacket.hh similarity index 97% rename from elements/tcpudp/deduptcppacket.hh rename to elements/ip/wgtt/deduptcppacket.hh index a81918772e..f5885420d8 100755 --- a/elements/tcpudp/deduptcppacket.hh +++ b/elements/ip/wgtt/deduptcppacket.hh @@ -9,10 +9,9 @@ #define CLICK_DEDUPTCPPACKET_HH #include #include - #include #include - +#include CLICK_DECLS diff --git a/elements/tcpudp/idadder.cc b/elements/ip/wgtt/idadder.cc similarity index 92% rename from elements/tcpudp/idadder.cc rename to elements/ip/wgtt/idadder.cc index 1c2fc40798..c07869ccac 100755 --- a/elements/tcpudp/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -18,7 +18,7 @@ IDAdder::IDAdder() int i; for(i=0; ipush(sizeof(click_ether)+1); for(int i = 1;idata(), &_ethh, sizeof(click_ether)); - // printf("idadder push %dth\n", i); + // syslog (LOG_INFO, "idadder push %dth\n", i); output(0).push(p); } WritablePacket *p = p_in->uniqueify(); diff --git a/elements/tcpudp/idadder.hh b/elements/ip/wgtt/idadder.hh similarity index 97% rename from elements/tcpudp/idadder.hh rename to elements/ip/wgtt/idadder.hh index 5dec0f79d7..55a6ad0f7a 100755 --- a/elements/tcpudp/idadder.hh +++ b/elements/ip/wgtt/idadder.hh @@ -12,7 +12,7 @@ #include #include #include - +#include CLICK_DECLS diff --git a/elements/tcpudp/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc similarity index 90% rename from elements/tcpudp/packetselectionSerial.cc rename to elements/ip/wgtt/packetselectionSerial.cc index 1af13d8eee..30f7cdf9ee 100755 --- a/elements/tcpudp/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -42,7 +42,7 @@ PacketSelectionSerial::PacketSelectionSerial() _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); - printf("Packetselection: init finish, ready to start\n"); + syslog (LOG_INFO, "Packetselection: init finish, ready to start\n"); } int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) @@ -64,7 +64,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) output_port[i] = first_start[i]-1; } - printf("PacketSelectionSerial out. Switch interval: %d\n", interval); + syslog (LOG_INFO, "PacketSelectionSerial out. Switch interval: %d\n", interval); return 0; } @@ -78,7 +78,7 @@ void PacketSelectionSerial::push(int port, Packet *p_in) reset_ap(); } - // printf("pkt_type: %x\n", pkt_type(p_in)); + // syslog (LOG_INFO, "pkt_type: %x\n", pkt_type(p_in)); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; @@ -109,7 +109,7 @@ void PacketSelectionSerial::reset_ap() } memcpy(p->data(), _ethh, sizeof(click_ether)); - printf("controller reset ap %X\n", i); + syslog (LOG_INFO, "controller reset ap %X\n", i); output(0).push(p); } } @@ -121,7 +121,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) state[c-CLIENT1_IP_SUFFIX] = IDLE; - printf("switch request ack, ip: %d.\n", c); + syslog (LOG_INFO, "switch request ack, ip: %d.\n", c); p_in -> kill(); } @@ -147,9 +147,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) { int rx_rate = status_rxrate(p_in); int tx_rate = status_txrate(p_in); - printf("client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); - printf("signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); - printf("rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", + syslog (LOG_INFO, "client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); + syslog (LOG_INFO, "signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); + syslog (LOG_INFO, "rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", rx_rate / 1000, rx_rate / 100, tx_rate / 1000, tx_rate / 100); } @@ -160,7 +160,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(state[c] == IDLE && !time_lock[c]) { - // printf("state idle\n"); + // syslog (LOG_INFO, "state idle\n"); unsigned char best_ap = find_best_ap(c); // WGTT @@ -170,7 +170,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(!(tmp_counter%interval)) { best_ap = (best_ap + 1)% 2; - printf("prepare manually switch to ap %X\n", best_ap+1); + syslog (LOG_INFO, "prepare manually switch to ap %X\n", best_ap+1); } } if(best_ap != output_port[c]) @@ -196,7 +196,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } memcpy(p->data(), _ethh, sizeof(click_ether)); - printf("Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + syslog (LOG_INFO, "Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); state[c] = SWITCH_REQ; output_port[c] = best_ap; diff --git a/elements/tcpudp/packetselectionSerial.hh b/elements/ip/wgtt/packetselectionSerial.hh similarity index 98% rename from elements/tcpudp/packetselectionSerial.hh rename to elements/ip/wgtt/packetselectionSerial.hh index 7257224c97..81a6fa63ff 100755 --- a/elements/tcpudp/packetselectionSerial.hh +++ b/elements/ip/wgtt/packetselectionSerial.hh @@ -13,7 +13,7 @@ #include #include #include - +#include CLICK_DECLS class PacketSelectionSerial : public Element { public: diff --git a/elements/standard/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc similarity index 62% rename from elements/standard/wgttqueue.cc rename to elements/ip/wgtt/wgttqueue.cc index b1aa32edd0..f5c45ffd94 100644 --- a/elements/standard/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -24,7 +24,7 @@ WGTTQueue::WGTTQueue() // 0: controller, 1-MAX_N_AP: ap _ethh = new click_ether[MAX_N_AP+1]; next_client = 0; - printf("wgtt init succeed\n"); + syslog (LOG_INFO, "wgtt init succeed\n"); } @@ -32,7 +32,7 @@ WGTTQueue::WGTTQueue() int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { - //printf("In configure\n"); + //syslog (LOG_INFO, "In configure\n"); int tmp[4], i; if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) @@ -47,20 +47,20 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) first_start[i] = tmp[i]; } - printf("wgtt configure succeed\n"); + syslog (LOG_INFO, "wgtt configure succeed\n"); return 0; } int WGTTQueue::initialize(ErrorHandler *errh) { - //printf("wgtt in initialize\n"); + syslog (LOG_INFO, "wgtt in initialize\n"); int i; for(i=0; ierror("out of memory"); - printf("wgtt initialize succeed, ready to start\n"); + syslog (LOG_INFO, "wgtt initialize succeed, ready to start\n"); return 0; } +inline void +WGTTQueue::enRing(unsigned char c, Packet *p) +{ + if((_tail[c]+1)%RING_SIZE == _head[c])//override + { + // syslog (LOG_INFO, "WGTTQueue override\n"); + if(_q[c][_head[c]]) + _q[c][_head[c]] -> kill(); + _head[c] = (_head[c]+1)%RING_SIZE; + } + // syslog (LOG_INFO, "WGTTQueue before _q[_tail] = p\n"); + // Packet *tmp = _q[_tail]; + // syslog (LOG_INFO, "_tail: %x\n", _tail); + _q[c][_tail[c]] = p; + // syslog (LOG_INFO, "WGTTQueue finish _q[_tail] = p\n"); + _tail[c] = (_tail[c]+1)%RING_SIZE; + // syslog (LOG_INFO, "WGTTQueue finish enRing\n"); +} + +inline Packet * +WGTTQueue::deRing() +{ + int i; + bool flag = false;//no pick out + Packet *p; + //next_client after function + unsigned char next_client_after = (next_client+1)%MAX_N_CLIENT; + for(i=0; idata()+sizeof(click_ether), &control_content, 2); memcpy(p->data(), &(_ethh[dst_ap+1]), sizeof(click_ether)); p_in -> kill(); - printf("wgttQueue send ap-ap seq\n"); + syslog (LOG_INFO, "wgttQueue send ap-ap seq\n"); checked_output_push(1, p); } } else //from ap { - printf("wgttQueue receive ap-ap seq for client: %d\n", c+1); + syslog (LOG_INFO, "wgttQueue receive ap-ap seq for client: %d\n", c+1); const unsigned char & start_seq = start_seq(p_in); while(_head[c] != start_seq) @@ -163,7 +222,7 @@ void WGTTQueue::push_control(Packet *p_in) _q[c][_head[c]] -> kill(); _head[c] = (_head[c]+1)%RING_SIZE; } - // printf("wgttQueue finish ap-ap dequeue\n"); + // syslog (LOG_INFO, "wgttQueue finish ap-ap dequeue\n"); WritablePacket *p = Packet::make(sizeof(click_ether)+2); @@ -177,9 +236,9 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), &(_ethh[0]), sizeof(click_ether)); p_in -> kill(); - // printf("ap-c packet push\n"); + // syslog (LOG_INFO, "ap-c packet push\n"); _block[c] = false; - printf("wgttQueue send switch ack\n"); + syslog (LOG_INFO, "wgttQueue send switch ack\n"); checked_output_push(1, p); } } @@ -196,16 +255,16 @@ void WGTTQueue::push_data(Packet *p_in) case CLIENT4_MAC_SUFFIX: c=3;break; } // if(_tail[c]) - // printf("wgttQueue in push data for active client: %d\n", c+1); + // syslog (LOG_INFO, "wgttQueue in push data for active client: %d\n", c+1); // else - // printf("wgttQueue in push data for inactive client: %d\n", c+1); + // syslog (LOG_INFO, "wgttQueue in push data for inactive client: %d\n", c+1); while(_tail[c] != seq) { - // printf("wgttQueue: before for client: %d\n", c+1); + // syslog (LOG_INFO, "wgttQueue: before for client: %d\n", c+1); enRing(c, 0); } p_in -> pull(15); - // printf("wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + syslog (LOG_INFO, "wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } diff --git a/elements/ip/wgtt/wgttqueue.hh b/elements/ip/wgtt/wgttqueue.hh new file mode 100644 index 0000000000..33ae83b67b --- /dev/null +++ b/elements/ip/wgtt/wgttqueue.hh @@ -0,0 +1,61 @@ +/* + idadder program, add id and push for queue ring in ap processing. + Input: [data pkt] + Output:[eth][id][data pkt], id is one Byte + Created by Zhenyu Song: sunnyszy@gmail.com + */ +// -*- c-basic-offset: 4 -*- +#ifndef CLICK_WGTTQUEUE_HH +#define CLICK_WGTTQUEUE_HH +#include +#include +#include +#include +#include +#include +CLICK_DECLS + +class WGTTQueue : public Element, public Storage { public: + + WGTTQueue() CLICK_COLD; + + inline void enRing(unsigned char, Packet*);//flag: whether override + inline Packet* deRing(); + inline void enque(Packet*);//flag: whether override + inline Packet* deque(); + + const char *class_name() const { return "WGTTQueue"; } + const char *port_count() const { return "1/2"; } + const char *processing() const { return "h/lh"; } + + int configure(Vector&, ErrorHandler*) CLICK_COLD; + int initialize(ErrorHandler*) CLICK_COLD; + + void push(int port, Packet*); + void push_control(Packet *p_in); + void push_data(Packet *p_in); + Packet* pull(int port); + + protected: + + Packet** volatile * _q; + + volatile unsigned char _head[MAX_N_CLIENT]; + volatile unsigned char _tail[MAX_N_CLIENT]; + volatile bool _block[MAX_N_CLIENT]; + volatile unsigned char next_client; + + int identity; + int first_start[MAX_N_CLIENT]; + unsigned char control_content[2]; + + click_ether * _ethh; + +}; + + + + + +CLICK_ENDDECLS +#endif \ No newline at end of file diff --git a/elements/standard/wgttqueue.hh b/elements/standard/wgttqueue.hh deleted file mode 100644 index e7898eeac8..0000000000 --- a/elements/standard/wgttqueue.hh +++ /dev/null @@ -1,117 +0,0 @@ -/* - idadder program, add id and push for queue ring in ap processing. - Input: [data pkt] - Output:[eth][id][data pkt], id is one Byte - Created by Zhenyu Song: sunnyszy@gmail.com - */ -// -*- c-basic-offset: 4 -*- -#ifndef CLICK_WGTTQUEUE_HH -#define CLICK_WGTTQUEUE_HH -#include -#include -#include -#include -#include - -CLICK_DECLS - -class WGTTQueue : public Element, public Storage { public: - - WGTTQueue() CLICK_COLD; - - inline void enRing(unsigned char, Packet*);//flag: whether override - inline Packet* deRing(); - inline void enque(Packet*);//flag: whether override - inline Packet* deque(); - - const char *class_name() const { return "WGTTQueue"; } - const char *port_count() const { return "1/2"; } - const char *processing() const { return "h/lh"; } - - int configure(Vector&, ErrorHandler*) CLICK_COLD; - int initialize(ErrorHandler*) CLICK_COLD; - - void push(int port, Packet*); - void push_control(Packet *p_in); - void push_data(Packet *p_in); - Packet* pull(int port); - - protected: - - Packet** volatile * _q; - - volatile unsigned char _head[MAX_N_CLIENT]; - volatile unsigned char _tail[MAX_N_CLIENT]; - volatile bool _block[MAX_N_CLIENT]; - volatile unsigned char next_client; - - int identity; - int first_start[MAX_N_CLIENT]; - unsigned char control_content[2]; - - click_ether * _ethh; - -}; - -inline void -WGTTQueue::enRing(unsigned char c, Packet *p) -{ - if((_tail[c]+1)%RING_SIZE == _head[c])//override - { - // printf("WGTTQueue override\n"); - if(_q[c][_head[c]]) - _q[c][_head[c]] -> kill(); - _head[c] = (_head[c]+1)%RING_SIZE; - } - // printf("WGTTQueue before _q[_tail] = p\n"); - // Packet *tmp = _q[_tail]; - // printf("_tail: %x\n", _tail); - _q[c][_tail[c]] = p; - // printf("WGTTQueue finish _q[_tail] = p\n"); - _tail[c] = (_tail[c]+1)%RING_SIZE; - // printf("WGTTQueue finish enRing\n"); -} - -inline Packet * -WGTTQueue::deRing() -{ - int i; - bool flag = false;//no pick out - Packet *p; - //next_client after function - unsigned char next_client_after = (next_client+1)%MAX_N_CLIENT; - for(i=0; i -#include "packetselectionPeriodicSwitch.hh" -#include -#include -#include -#include -#include - - CLICK_DECLS - -PacketSelectionPeriodicSwitch::PacketSelectionPeriodicSwitch() -{ - output_port = 0; - switch_counter = 0; - switch_flag = 0xff; - -} - -PacketSelectionPeriodicSwitch::~PacketSelectionPeriodicSwitch() -{ - -} - - - -int -PacketSelectionPeriodicSwitch::configure(Vector &conf, ErrorHandler *errh) -{ - if (Args(conf, this, errh) - .read_p("SWITCHTIME", IntArg(), switch_time) - .complete() < 0) - return -1; - - return 0; -} - -void -PacketSelectionPeriodicSwitch::push(int port, Packet *p_in) -{ - if(port kill(); - else - destination_change(p_in); - -} - - -void -PacketSelectionPeriodicSwitch::destination_change(Packet *p_in) -{ - - WritablePacket *p_master = p_in->uniqueify(); - switch_counter ++; - if(switch_counter >= switch_time) - { - switch_counter = 0; - output_port = (output_port + 1)%n_outport; - } - output(output_port).push(p_master); - - WritablePacket *p_switch_flag = Packet::make(1); - memcpy(p_switch_flag->data(), &switch_flag, 1); - output(output_port).push(p_switch_flag); - -} - -CLICK_ENDDECLS -EXPORT_ELEMENT(PacketSelectionPeriodicSwitch) -ELEMENT_MT_SAFE(PacketSelectionPeriodicSwitch) diff --git a/elements/tcpudp/packetselectionPeriodicSwitch.hh b/elements/tcpudp/packetselectionPeriodicSwitch.hh deleted file mode 100755 index 64d77e9671..0000000000 --- a/elements/tcpudp/packetselectionPeriodicSwitch.hh +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef CLICK_PACKETSELECTIONPERIODICSWITCH_HH -#define CLICK_PACKETSELECTIONPERIODICSWITCH_HH -#include -#include -#include - -CLICK_DECLS - - -class PacketSelectionPeriodicSwitch : public Element { public: - - - PacketSelectionPeriodicSwitch() CLICK_COLD; - ~PacketSelectionPeriodicSwitch() CLICK_COLD; - - const char *class_name() const { return "PacketSelectionPeriodicSwitch"; } - const char *port_count() const { return "4/3"; } - const char *flags() const { return "A"; } - - int configure(Vector &, ErrorHandler *) CLICK_COLD; - - void push(int port, Packet *p_in); - - void destination_change(Packet *); - - - private: - - static const int n_outport = 2; - int output_port; - int switch_time; - int switch_counter; - unsigned char switch_flag; - - -}; - -CLICK_ENDDECLS -#endif diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 4d388120ad..098c51d406 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -5,6 +5,15 @@ #ifndef _WGTT_H_ #define _WGTT_H_ +struct my_test_struct { + uint8_t mac; + int8_t signal; + int8_t noise; + uint32_t rx_rate; + uint32_t tx_rate; + +}; + // ether type #define ETHER_PROTO_BASE 0x0800 #define CONTROL_SUFFIX 0x1 @@ -17,17 +26,29 @@ // controller state #define IDLE 0 #define SWITCH_REQ 1 +#define INACTIVE 2 +#define ANT 3 // client 1 ip -#define MAX_N_CLIENT 1 +#define MAX_N_CLIENT 2 +#define RSSI_THRESHOLD -67 #define CLIENT1_MAC_SUFFIX 0x07 #define CLIENT2_MAC_SUFFIX 0xb1 #define CLIENT3_MAC_SUFFIX 0x09 #define CLIENT4_MAC_SUFFIX 0x0a - +#define CLIENT1_MAC "44:c3:06:31:5b:07" // ap #define MAX_N_AP 6 +#define CLIENT1_IP_SUFFIX 135 +#define AP1_MAC "70:88:6b:80:60:01" +#define AP2_MAC "70:88:6b:80:60:02" +#define AP3_MAC "70:88:6b:80:60:03" +#define AP4_MAC "70:88:6b:80:60:04" +#define AP5_MAC "70:88:6b:80:60:05" +#define AP6_MAC "70:88:6b:80:60:06" +#define AP7_MAC "70:88:6b:80:60:07" +#define AP8_MAC "70:88:6b:80:60:08" // controller #define CONTROLLER_IN_IP_SUFFIX 68 @@ -63,17 +84,12 @@ #define queue_seq(p) *(p->data()+14) #define data_client(p) *(p->data()+20) -#define CLIENT1_IP_SUFFIX 135 -#define AP1_MAC "70:88:6b:80:60:01" -#define AP2_MAC "70:88:6b:80:60:02" -#define AP3_MAC "70:88:6b:80:60:03" -#define AP4_MAC "70:88:6b:80:60:04" -#define AP5_MAC "70:88:6b:80:60:05" -#define AP6_MAC "70:88:6b:80:60:06" -#define AP7_MAC "70:88:6b:80:60:07" -#define AP8_MAC "70:88:6b:80:60:08" - -// char *CLIENT_MAC[MAX_N_CLIENT] = {"44:c3:06:31:5b:01", "44:c3:06:31:5b:02", "44:c3:06:31:5b:03", -// "44:c3:06:31:5b:04"}; +//for 80211r +#define r_control_type(p) *(p->data()+14) +#define r_control_client(p) *(p->data()+15) +#define r_control_ori(p) *(p->data()+16) +#define r_control_tar(p) *(p->data()+17) +#define r_src_mac_suffix(p) *(p->data()+11) +#define r_dst_mac_suffix(p) *(p->data()+5) -#endif _WGTT_H_ \ No newline at end of file +#endif \ No newline at end of file diff --git a/make.sh b/make.sh index 1f2308a919..d8bd5c9a4c 100755 --- a/make.sh +++ b/make.sh @@ -1,5 +1,6 @@ #!/bin/bash sudo rm ./bin/click +sudo make ./elemlist sudo make sudo make install From e52fc61224d20f2239f197baf5b0c6ea9e2c9f60 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 31 Dec 2016 17:33:41 -0500 Subject: [PATCH 105/171] debug --- elements/ip/80211r/rapcontrol.cc | 10 ++-- elements/ip/80211r/rcontrollercontrol.cc | 6 +-- elements/ip/80211r/rssibecon.cc | 14 ++--- elements/ip/wgtt/csisep.cc | 14 ++--- elements/ip/wgtt/deduptcppacket.cc | 12 ++--- elements/ip/wgtt/idadder.cc | 6 +-- elements/ip/wgtt/packetselectionSerial.cc | 22 ++++---- elements/ip/wgtt/wgttqueue.cc | 62 +++++++++++------------ 8 files changed, 73 insertions(+), 73 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index f634d2b90b..7ff1394725 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -89,7 +89,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_INFO, "ap %d pass deassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass deassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == INACTIVE && t == 0x0a && tar == identity - 1) @@ -103,7 +103,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_INFO, "ap %d pass reassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); @@ -128,7 +128,7 @@ void RAPControl::push_down_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_INFO, "ap %d ack authetication for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d ack authetication for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == IDLE && t == 0x08 && ori == identity-1) @@ -144,7 +144,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_INFO, "ap %d pass authetication ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass authetication ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } else if(state[c-1] == INACTIVE && t == 0x0c && tar == identity-1) @@ -160,7 +160,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_INFO, "ap %d pass reassociation ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reassociation ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index a0c6391d41..114a203f77 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -85,7 +85,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); - syslog (LOG_INFO, "controller pass deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x07) @@ -101,7 +101,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[ori]), sizeof(click_ether)); - syslog (LOG_INFO, "controller pass deassociation ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass deassociation ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x0b) @@ -118,7 +118,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); outport[c] = tar; - syslog (LOG_INFO, "controller ack reassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller ack reassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index b43d267f1a..396dc6d01d 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -14,7 +14,7 @@ CLICK_DECLS RSSIBecon::RSSIBecon() { #ifdef __arm__ - syslog (LOG_INFO, "RSSIBecon: finish init\n"); + syslog (LOG_DEBUG, "RSSIBecon: finish init\n"); #endif } @@ -41,12 +41,12 @@ RSSIBecon::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_INFO, "Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) - syslog (LOG_INFO, "RSSIBecon: can not connect to backend iwinfo\n"); + syslog (LOG_DEBUG, "RSSIBecon: can not connect to backend iwinfo\n"); #endif - syslog (LOG_INFO, "RSSIBecon: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "RSSIBecon: finish configure, ready to start\n"); return 0; } @@ -57,9 +57,9 @@ RSSIBecon::fragment(Packet *p_in) int i,j; if(!(iw->assoclist(ifname, buf, &len))) - // // syslog (LOG_INFO, "RSSIBecon: can not find associlist\n"); + // // syslog (LOG_DEBUG, "RSSIBecon: can not find associlist\n"); // else if (len <= 0) - // // syslog (LOG_INFO, "RSSIBecon: associ number < 0\n"); + // // syslog (LOG_DEBUG, "RSSIBecon: associ number < 0\n"); // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); @@ -98,7 +98,7 @@ void RSSIBecon::push(int, Packet *p) { #ifdef __arm__ - // syslog (LOG_INFO, "RSSIBecon: in push\n"); + // syslog (LOG_DEBUG, "RSSIBecon: in push\n"); fragment(p); #endif } diff --git a/elements/ip/wgtt/csisep.cc b/elements/ip/wgtt/csisep.cc index a08246896e..704286dbd2 100755 --- a/elements/ip/wgtt/csisep.cc +++ b/elements/ip/wgtt/csisep.cc @@ -16,7 +16,7 @@ CLICK_DECLS CSISep::CSISep() { #ifdef __arm__ - syslog (LOG_INFO, "CSISep: finish init\n"); + syslog (LOG_DEBUG, "CSISep: finish init\n"); // total_msg_cnt = 0; sample_counter = 0; #endif @@ -46,12 +46,12 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_INFO, "Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) - syslog (LOG_INFO, "CSISep: can not connect to backend iwinfo\n"); + syslog (LOG_DEBUG, "CSISep: can not connect to backend iwinfo\n"); #endif - syslog (LOG_INFO, "CSISep: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "CSISep: finish configure, ready to start\n"); return 0; } @@ -66,9 +66,9 @@ CSISep::fragment(Packet *p_in) sample_counter = 0; if(!(iw->assoclist(ifname, buf, &len))) - // // syslog (LOG_INFO, "CSISep: can not find associlist\n"); + // // syslog (LOG_DEBUG, "CSISep: can not find associlist\n"); // else if (len <= 0) - // // syslog (LOG_INFO, "CSISep: associ number < 0\n"); + // // syslog (LOG_DEBUG, "CSISep: associ number < 0\n"); // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); @@ -109,7 +109,7 @@ void CSISep::push(int, Packet *p) { #ifdef __arm__ - // syslog (LOG_INFO, "CSISep: in push\n"); + // syslog (LOG_DEBUG, "CSISep: in push\n"); fragment(p); #endif } diff --git a/elements/ip/wgtt/deduptcppacket.cc b/elements/ip/wgtt/deduptcppacket.cc index 2c7ce3c7a2..83bbfacd60 100755 --- a/elements/ip/wgtt/deduptcppacket.cc +++ b/elements/ip/wgtt/deduptcppacket.cc @@ -37,22 +37,22 @@ DeDupTCPPacket::drop(Packet *p) void DeDupTCPPacket::push(int port, Packet *p_in) { - // syslog (LOG_INFO, "Packet in\n"); + // syslog (LOG_DEBUG, "Packet in\n"); // construct link_key WritablePacket *p = p_in->uniqueify(); struct click_ip *iph = p->ip_header(); - // syslog (LOG_INFO, "IP id: %x", iph->ip_id); + // syslog (LOG_DEBUG, "IP id: %x", iph->ip_id); uint64_t tmp_link_key = ((((uint64_t)(iph->ip_id))&0x000000000000ffff)<<32)+ (((uint64_t)((iph->ip_src).s_addr))&0x00000000ffffffff); - // syslog (LOG_INFO, "key: %lx\n", tmp_link_key); + // syslog (LOG_DEBUG, "key: %lx\n", tmp_link_key); std::set::iterator it; it = _set.find(tmp_link_key); if((iph -> ip_id) != 0) { if( it != _set.end()) { - // syslog (LOG_INFO, "Packet out.drop\n"); + // syslog (LOG_DEBUG, "Packet out.drop\n"); drop(p); return; } @@ -61,7 +61,7 @@ DeDupTCPPacket::push(int port, Packet *p_in) //if (_set.size() >= max_elem_num) if (_queue.size() >= max_elem_num) { - // syslog (LOG_INFO, "exceed the max size\n"); + // syslog (LOG_DEBUG, "exceed the max size\n"); uint64_t & link_key_tobe_delete = _queue.front(); _queue.pop(); it = _set.find(link_key_tobe_delete); @@ -72,7 +72,7 @@ DeDupTCPPacket::push(int port, Packet *p_in) _queue.push(tmp_link_key); } } - // syslog (LOG_INFO, "Packet out.push\n"); + // syslog (LOG_DEBUG, "Packet out.push\n"); output(0).push(p); } diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index c07869ccac..783ec572ac 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -18,7 +18,7 @@ IDAdder::IDAdder() int i; for(i=0; ipush(sizeof(click_ether)+1); for(int i = 1;idata(), &_ethh, sizeof(click_ether)); - // syslog (LOG_INFO, "idadder push %dth\n", i); + // syslog (LOG_DEBUG, "idadder push %dth\n", i); output(0).push(p); } WritablePacket *p = p_in->uniqueify(); diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 30f7cdf9ee..d5225861ca 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -42,7 +42,7 @@ PacketSelectionSerial::PacketSelectionSerial() _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); - syslog (LOG_INFO, "Packetselection: init finish, ready to start\n"); + syslog (LOG_DEBUG, "Packetselection: init finish, ready to start\n"); } int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) @@ -64,7 +64,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) output_port[i] = first_start[i]-1; } - syslog (LOG_INFO, "PacketSelectionSerial out. Switch interval: %d\n", interval); + syslog (LOG_DEBUG, "PacketSelectionSerial out. Switch interval: %d\n", interval); return 0; } @@ -78,7 +78,7 @@ void PacketSelectionSerial::push(int port, Packet *p_in) reset_ap(); } - // syslog (LOG_INFO, "pkt_type: %x\n", pkt_type(p_in)); + // syslog (LOG_DEBUG, "pkt_type: %x\n", pkt_type(p_in)); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; @@ -109,7 +109,7 @@ void PacketSelectionSerial::reset_ap() } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_INFO, "controller reset ap %X\n", i); + syslog (LOG_DEBUG, "controller reset ap %X\n", i); output(0).push(p); } } @@ -121,7 +121,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) state[c-CLIENT1_IP_SUFFIX] = IDLE; - syslog (LOG_INFO, "switch request ack, ip: %d.\n", c); + syslog (LOG_DEBUG, "switch request ack, ip: %d.\n", c); p_in -> kill(); } @@ -147,9 +147,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) { int rx_rate = status_rxrate(p_in); int tx_rate = status_txrate(p_in); - syslog (LOG_INFO, "client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); - syslog (LOG_INFO, "signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); - syslog (LOG_INFO, "rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", + syslog (LOG_DEBUG, "client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); + syslog (LOG_DEBUG, "signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); + syslog (LOG_DEBUG, "rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", rx_rate / 1000, rx_rate / 100, tx_rate / 1000, tx_rate / 100); } @@ -160,7 +160,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(state[c] == IDLE && !time_lock[c]) { - // syslog (LOG_INFO, "state idle\n"); + // syslog (LOG_DEBUG, "state idle\n"); unsigned char best_ap = find_best_ap(c); // WGTT @@ -170,7 +170,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(!(tmp_counter%interval)) { best_ap = (best_ap + 1)% 2; - syslog (LOG_INFO, "prepare manually switch to ap %X\n", best_ap+1); + syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); } } if(best_ap != output_port[c]) @@ -196,7 +196,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_INFO, "Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + syslog (LOG_DEBUG, "Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); state[c] = SWITCH_REQ; output_port[c] = best_ap; diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index f5c45ffd94..a60d6b3eb9 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -24,7 +24,7 @@ WGTTQueue::WGTTQueue() // 0: controller, 1-MAX_N_AP: ap _ethh = new click_ether[MAX_N_AP+1]; next_client = 0; - syslog (LOG_INFO, "wgtt init succeed\n"); + syslog (LOG_DEBUG, "wgtt init succeed\n"); } @@ -32,7 +32,7 @@ WGTTQueue::WGTTQueue() int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { - //syslog (LOG_INFO, "In configure\n"); + //syslog (LOG_DEBUG, "In configure\n"); int tmp[4], i; if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) @@ -47,20 +47,20 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) first_start[i] = tmp[i]; } - syslog (LOG_INFO, "wgtt configure succeed\n"); + syslog (LOG_DEBUG, "wgtt configure succeed\n"); return 0; } int WGTTQueue::initialize(ErrorHandler *errh) { - syslog (LOG_INFO, "wgtt in initialize\n"); + syslog (LOG_DEBUG, "wgtt in initialize\n"); int i; for(i=0; ierror("out of memory"); - syslog (LOG_INFO, "wgtt initialize succeed, ready to start\n"); + syslog (LOG_DEBUG, "wgtt initialize succeed, ready to start\n"); return 0; } @@ -104,18 +104,18 @@ WGTTQueue::enRing(unsigned char c, Packet *p) { if((_tail[c]+1)%RING_SIZE == _head[c])//override { - // syslog (LOG_INFO, "WGTTQueue override\n"); + // syslog (LOG_DEBUG, "WGTTQueue override\n"); if(_q[c][_head[c]]) _q[c][_head[c]] -> kill(); _head[c] = (_head[c]+1)%RING_SIZE; } - // syslog (LOG_INFO, "WGTTQueue before _q[_tail] = p\n"); + // syslog (LOG_DEBUG, "WGTTQueue before _q[_tail] = p\n"); // Packet *tmp = _q[_tail]; - // syslog (LOG_INFO, "_tail: %x\n", _tail); + // syslog (LOG_DEBUG, "_tail: %x\n", _tail); _q[c][_tail[c]] = p; - // syslog (LOG_INFO, "WGTTQueue finish _q[_tail] = p\n"); + // syslog (LOG_DEBUG, "WGTTQueue finish _q[_tail] = p\n"); _tail[c] = (_tail[c]+1)%RING_SIZE; - // syslog (LOG_INFO, "WGTTQueue finish enRing\n"); + // syslog (LOG_DEBUG, "WGTTQueue finish enRing\n"); } inline Packet * @@ -131,9 +131,9 @@ WGTTQueue::deRing() if(_block[next_client] || _head[next_client]==_tail[next_client]) { // if(_block[next_client]) - // syslog (LOG_INFO, "wgttQueue: queue %d is inactive\n", next_client+1); + // syslog (LOG_DEBUG, "wgttQueue: queue %d is inactive\n", next_client+1); // if(_head[next_client]==_tail[next_client]) - // syslog (LOG_INFO, "wgttQueue: queue %d is empty\n", next_client+1); + // syslog (LOG_DEBUG, "wgttQueue: queue %d is empty\n", next_client+1); continue; } while((_head[next_client]+1)%MAX_N_CLIENT != _tail[next_client] @@ -142,7 +142,7 @@ WGTTQueue::deRing() flag = true; p = _q[next_client][_head[next_client]]; _head[next_client] = (_head[next_client]+1)%RING_SIZE; - syslog (LOG_INFO, "wgttQueue: deque pkt from queue: %d\n", next_client+1); + syslog (LOG_DEBUG, "wgttQueue: deque pkt from queue: %d\n", next_client+1); break; } @@ -150,7 +150,7 @@ WGTTQueue::deRing() if(flag) { - // syslog (LOG_INFO, "wgttQueue: deque succeed\n"); + // syslog (LOG_DEBUG, "wgttQueue: deque succeed\n"); return p; } else @@ -161,13 +161,13 @@ WGTTQueue::deRing() void WGTTQueue::push(int, Packet *p_in) { - syslog (LOG_INFO, "wgttQueue in push\n"); + syslog (LOG_DEBUG, "wgttQueue in push\n"); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; case DATA_SUFFIX: push_data(p_in);break; } - syslog (LOG_INFO, "wgttQueue out push\n"); + syslog (LOG_DEBUG, "wgttQueue out push\n"); } void WGTTQueue::push_control(Packet *p_in) @@ -178,7 +178,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(client_ip(p_in) == RESET_CONTENT) //reset { - syslog (LOG_INFO, "wgttQueue: receive reset req for client: %d\n", c+1); + syslog (LOG_DEBUG, "wgttQueue: receive reset req for client: %d\n", c+1); for(i=0; idata()+sizeof(click_ether), &control_content, 2); memcpy(p->data(), &(_ethh[dst_ap+1]), sizeof(click_ether)); p_in -> kill(); - syslog (LOG_INFO, "wgttQueue send ap-ap seq\n"); + syslog (LOG_DEBUG, "wgttQueue send ap-ap seq\n"); checked_output_push(1, p); } } else //from ap { - syslog (LOG_INFO, "wgttQueue receive ap-ap seq for client: %d\n", c+1); + syslog (LOG_DEBUG, "wgttQueue receive ap-ap seq for client: %d\n", c+1); const unsigned char & start_seq = start_seq(p_in); while(_head[c] != start_seq) @@ -222,7 +222,7 @@ void WGTTQueue::push_control(Packet *p_in) _q[c][_head[c]] -> kill(); _head[c] = (_head[c]+1)%RING_SIZE; } - // syslog (LOG_INFO, "wgttQueue finish ap-ap dequeue\n"); + // syslog (LOG_DEBUG, "wgttQueue finish ap-ap dequeue\n"); WritablePacket *p = Packet::make(sizeof(click_ether)+2); @@ -236,9 +236,9 @@ void WGTTQueue::push_control(Packet *p_in) memcpy(p->data(), &(_ethh[0]), sizeof(click_ether)); p_in -> kill(); - // syslog (LOG_INFO, "ap-c packet push\n"); + // syslog (LOG_DEBUG, "ap-c packet push\n"); _block[c] = false; - syslog (LOG_INFO, "wgttQueue send switch ack\n"); + syslog (LOG_DEBUG, "wgttQueue send switch ack\n"); checked_output_push(1, p); } } @@ -255,16 +255,16 @@ void WGTTQueue::push_data(Packet *p_in) case CLIENT4_MAC_SUFFIX: c=3;break; } // if(_tail[c]) - // syslog (LOG_INFO, "wgttQueue in push data for active client: %d\n", c+1); + // syslog (LOG_DEBUG, "wgttQueue in push data for active client: %d\n", c+1); // else - // syslog (LOG_INFO, "wgttQueue in push data for inactive client: %d\n", c+1); + // syslog (LOG_DEBUG, "wgttQueue in push data for inactive client: %d\n", c+1); while(_tail[c] != seq) { - // syslog (LOG_INFO, "wgttQueue: before for client: %d\n", c+1); + // syslog (LOG_DEBUG, "wgttQueue: before for client: %d\n", c+1); enRing(c, 0); } p_in -> pull(15); - syslog (LOG_INFO, "wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + syslog (LOG_DEBUG, "wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } From 11f89a8e689484fcc4f13635cc95fa4783802337 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 31 Dec 2016 20:52:04 -0500 Subject: [PATCH 106/171] debug, fix data tunneling --- elements/ip/80211r/rapcontrol.cc | 56 +++++++++++++++++------- elements/ip/80211r/rclientcontrol.cc | 6 +-- elements/ip/80211r/rcontrollercontrol.cc | 23 ++++++++-- include/clicknet/wgtt.h | 3 +- 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 7ff1394725..fae5e9e9bb 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -20,7 +20,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) openlog ("RAPControl", LOG_CONS | LOG_NDELAY, 0); - _ethh = new click_ether[MAX_N_CLIENT]; + _ethh = new click_ether[MAX_N_CLIENT+1];//first MAX_N_CLIENT: ap->client; ap->controller if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), tmp_id) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) @@ -37,21 +37,40 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) state[i] = (identity==tmp_start[i])? IDLE:INACTIVE; _ethh[i].ether_type = htons(ETHER_PROTO_BASE+CONTROL_SUFFIX); switch(identity-1) - { - case 0:cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; - case 1:cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; - case 2:cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; - case 3:cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; - case 4:cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; - case 5:cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; - case 6:cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; - case 7:cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; - } - switch(i) - { - case 0:cp_ethernet_address(CLIENT1_MAC, _ethh[i].ether_dhost);break; - } + { + case 0:cp_ethernet_address(AP1_MAC, _ethh[i].ether_shost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh[i].ether_shost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh[i].ether_shost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh[i].ether_shost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh[i].ether_shost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh[i].ether_shost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh[i].ether_shost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh[i].ether_shost);break; } + switch(i) + { + case 0:cp_ethernet_address(CLIENT1_MAC, _ethh[i].ether_dhost);break; + } + } + + _ethh[i].ether_type = htons(ETHER_PROTO_BASE+DATA_SUFFIX); + switch(identity-1) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; + } + switch(i) + { + case 0:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[MAX_N_CLIENT].ether_dhost);break; + } + + return 0; @@ -197,7 +216,12 @@ void RAPControl::push_up_data(Packet*p_in) if(state[c] == INACTIVE) p_in -> kill(); else - output(1).push(p_in); + { + WritablePacket *p = p_in->uniqueify(); + p->push(sizeof(click_ether)); + memcpy(p->data(), &(_ethh[MAX_N_CLIENT]), sizeof(click_ether)); + output(1).push(p); + } } diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 3805fea246..8ca6baa208 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -19,7 +19,7 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) int i, tmp_start[4],tmp_id; for(i=0;i max_rssi) diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index 114a203f77..602b4814b3 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -18,7 +18,7 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) { int i, tmp_start[4]; - _ethh = new click_ether[MAX_N_AP]; + _ethh = new click_ether[MAX_N_AP*2]; if (Args(conf, this, errh) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) @@ -33,7 +33,7 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) } - for(i=0;i &conf, ErrorHandler *errh) } } + for(i=MAX_N_AP;ipush(sizeof(click_ether)); //eth - memcpy(p->data(), &(_ethh[outport[port-2]]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[outport[port-2]+MAX_N_AP]), sizeof(click_ether)); output(0).push(p); } diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 098c51d406..ab1f7a9efb 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -31,7 +31,8 @@ struct my_test_struct { // client 1 ip #define MAX_N_CLIENT 2 -#define RSSI_THRESHOLD -67 +//currently unused +// #define RSSI_THRESHOLD -67 #define CLIENT1_MAC_SUFFIX 0x07 #define CLIENT2_MAC_SUFFIX 0xb1 From d76b1871f09c89e83c7309c31a8294656de3c917 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 31 Dec 2016 21:44:27 -0500 Subject: [PATCH 107/171] debug: correct output # --- elements/ip/80211r/rcontrollercontrol.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index 602b4814b3..51b1276833 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -148,7 +148,7 @@ void RControlerControl::push_down_data(Packet*p_in, int port) p->push(sizeof(click_ether)); //eth - memcpy(p->data(), &(_ethh[outport[port-2]+MAX_N_AP]), sizeof(click_ether)); + memcpy(p->data(), &(_ethh[outport[port-1]+MAX_N_AP]), sizeof(click_ether)); output(0).push(p); } From ab99ddcf03d4ac91dd07ed6767cd9f0515f58125 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 31 Dec 2016 21:50:01 -0500 Subject: [PATCH 108/171] debug --- elements/ip/80211r/rapcontrol.cc | 2 +- elements/ip/80211r/rcontrollercontrol.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index fae5e9e9bb..83d752c51a 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -53,7 +53,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) } } - _ethh[i].ether_type = htons(ETHER_PROTO_BASE+DATA_SUFFIX); + _ethh[MAX_N_CLIENT].ether_type = htons(ETHER_PROTO_BASE+DATA_SUFFIX); switch(identity-1) { case 0:cp_ethernet_address(AP1_MAC, _ethh[MAX_N_CLIENT].ether_shost);break; diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index 51b1276833..290276679a 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -149,6 +149,8 @@ void RControlerControl::push_down_data(Packet*p_in, int port) //eth memcpy(p->data(), &(_ethh[outport[port-1]+MAX_N_AP]), sizeof(click_ether)); + syslog (LOG_DEBUG, "port: %d\n", port); + syslog (LOG_DEBUG, "outport: %d\n", outport[port-1]); output(0).push(p); } From 30f1328a932a14da02fa5bd86c8bab659796da1a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 31 Dec 2016 21:53:26 -0500 Subject: [PATCH 109/171] debug --- elements/ip/80211r/rcontrollercontrol.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index 290276679a..e90974db84 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -29,7 +29,7 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) for(i=0;i &conf, ErrorHandler *errh) } } - for(i=MAX_N_AP;i Date: Sun, 1 Jan 2017 10:49:39 -0500 Subject: [PATCH 110/171] debug: change eth type for download data --- elements/ip/80211r/rclientcontrol.cc | 11 +++++++++-- elements/ip/80211r/rclientcontrol.hh | 2 ++ include/clicknet/wgtt.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 8ca6baa208..c617bad1d1 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -95,10 +95,17 @@ void RClientControl::push_control(Packet*p_in) void RClientControl::push_downdata(Packet*p_in) { + WritablePacket *p = p_in->uniqueify(); + printf("RClientControl: ether type: %u\n", r_ether_type_suffix(p)); + if(r_ether_type_suffix(p) == 0x03) + { + memcpy(p->data()+13, ðer_type_ip_suffix, 1); + } + if(state == INACTIVE) - p_in -> kill(); + p -> kill(); else - output(1).push(p_in); + output(1).push(p); } diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index b9a246cf48..783516e220 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -38,6 +38,8 @@ class RClientControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; + const unsigned char ether_type_ip_suffix = 0x00; + }; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index ab1f7a9efb..62e8ff2cbf 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -92,5 +92,6 @@ struct my_test_struct { #define r_control_tar(p) *(p->data()+17) #define r_src_mac_suffix(p) *(p->data()+11) #define r_dst_mac_suffix(p) *(p->data()+5) +#define r_ether_type_suffix(p) *(p->data()+13) #endif \ No newline at end of file From 9cf6f3cdfb4726561bc4631ed66258a6809df31d Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 11:51:12 -0500 Subject: [PATCH 111/171] debug --- elements/ip/80211r/rapcontrol.cc | 12 ++++++------ elements/ip/80211r/rclientcontrol.cc | 17 ++++++++++------- elements/ip/80211r/rcontrollercontrol.cc | 11 ++++++----- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 83d752c51a..2d7435223d 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -70,7 +70,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) case 0:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[MAX_N_CLIENT].ether_dhost);break; } - + syslog (LOG_DEBUG, "RAPControl: finish configure, ready to start\n"); return 0; @@ -108,7 +108,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d pass deassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == INACTIVE && t == 0x0a && tar == identity - 1) @@ -122,7 +122,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d pass reassociation for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); @@ -147,7 +147,7 @@ void RAPControl::push_down_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d ack authetication for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d send ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == IDLE && t == 0x08 && ori == identity-1) @@ -163,7 +163,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "ap %d pass authetication ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } else if(state[c-1] == INACTIVE && t == 0x0c && tar == identity-1) @@ -179,7 +179,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "ap %d pass reassociation ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index c617bad1d1..dba4e319c4 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -31,7 +31,7 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) return -1; identity = tmp_id; - current_ap = tmp_start[identity-1]; + current_ap = tmp_start[identity-1] - 1; state = IDLE; @@ -43,7 +43,7 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) case 1: cp_ethernet_address(CLIENT1_MAC, _ethh->ether_shost);break; } cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_dhost); - + syslog (LOG_DEBUG, "RClientControl: finish configure, ready to start\n"); return 0; } @@ -70,7 +70,7 @@ void RClientControl::push_control(Packet*p_in) if(state == ANT && t == 0x09) { state = INACTIVE; - control_content[0] = 0x09; + control_content[0] = 0x0a; control_content[1] = c; control_content[2] = ori; control_content[3] = tar; @@ -81,13 +81,13 @@ void RClientControl::push_control(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_INFO, "client receive deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "client send reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(state == INACTIVE && t == 0x0d) { state = IDLE; - syslog (LOG_INFO, "client become inactive for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "client finish reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); } p_in -> kill(); @@ -96,7 +96,7 @@ void RClientControl::push_control(Packet*p_in) void RClientControl::push_downdata(Packet*p_in) { WritablePacket *p = p_in->uniqueify(); - printf("RClientControl: ether type: %u\n", r_ether_type_suffix(p)); + //printf("RClientControl: ether type: %u\n", r_ether_type_suffix(p)); if(r_ether_type_suffix(p) == 0x03) { memcpy(p->data()+13, ðer_type_ip_suffix, 1); @@ -129,11 +129,14 @@ void RClientControl::push_80211(Packet*p_in) case CLIENT3_MAC_SUFFIX: c = 3; case CLIENT4_MAC_SUFFIX: c = 4; } + syslog (LOG_DEBUG, "RClientControl: receive becon, ap %d, client %d, rssi %d\n", + ap+1, c, rssi_this); if(c == identity) rssi[ap] = rssi_this; // if IDLE, considering switching if(c == identity && state == IDLE && rssi[current_ap] < -67) { + syslog (LOG_DEBUG, "Considering to switch\n"); unsigned i; unsigned max_id; char max_rssi = -127; @@ -158,7 +161,7 @@ void RClientControl::push_80211(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_INFO, "client send anthentication for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap, max_id); + syslog (LOG_DEBUG, "client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); current_ap = max_id; state = ANT; output(0).push(p); diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index e90974db84..f6b16741cf 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -66,6 +66,7 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) case 7:cp_ethernet_address(AP8_MAC, _ethh[i+MAX_N_AP].ether_dhost);break; } } + syslog (LOG_DEBUG, "RControllerControl: finish configure, ready to start\n"); return 0; } @@ -102,7 +103,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); - syslog (LOG_DEBUG, "controller pass deassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass ant req for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x07) @@ -118,7 +119,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[ori]), sizeof(click_ether)); - syslog (LOG_DEBUG, "controller pass deassociation ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass ant ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x0b) @@ -135,7 +136,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); outport[c] = tar; - syslog (LOG_DEBUG, "controller ack reassociation for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); @@ -149,8 +150,8 @@ void RControlerControl::push_down_data(Packet*p_in, int port) //eth memcpy(p->data(), &(_ethh[outport[port-1]+MAX_N_AP]), sizeof(click_ether)); - syslog (LOG_DEBUG, "port: %d\n", port); - syslog (LOG_DEBUG, "outport: %d\n", outport[port-1]); + //syslog (LOG_DEBUG, "port: %d\n", port); + //syslog (LOG_DEBUG, "outport: %d\n", outport[port-1]); output(0).push(p); } From 29113b12e79cb56e9180bc5fb289894a7dce463d Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 12:01:33 -0500 Subject: [PATCH 112/171] debug: forget break in case --- elements/ip/80211r/rclientcontrol.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index dba4e319c4..7483a53f50 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -124,10 +124,10 @@ void RClientControl::push_80211(Packet*p_in) static unsigned char c; switch(status_mac(p_in)) { - case CLIENT1_MAC_SUFFIX: c = 1; - case CLIENT2_MAC_SUFFIX: c = 2; - case CLIENT3_MAC_SUFFIX: c = 3; - case CLIENT4_MAC_SUFFIX: c = 4; + case CLIENT1_MAC_SUFFIX: c = 1;break; + case CLIENT2_MAC_SUFFIX: c = 2;break; + case CLIENT3_MAC_SUFFIX: c = 3;break; + case CLIENT4_MAC_SUFFIX: c = 4;break; } syslog (LOG_DEBUG, "RClientControl: receive becon, ap %d, client %d, rssi %d\n", ap+1, c, rssi_this); From ee89de847b954e2d17065536f248be50b4dd01f8 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 13:56:40 -0500 Subject: [PATCH 113/171] add print_interval & switch_interval --- elements/ip/80211r/rclientcontrol.cc | 45 +++++++++++++++++++++------- elements/ip/80211r/rclientcontrol.hh | 2 ++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 7483a53f50..10b926d689 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -27,6 +27,8 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) + .read_p("INTERVAL", IntArg(), interval) + .read_p("PRINTINTERVAL", IntArg(), print_interval) .complete() < 0) return -1; @@ -129,27 +131,48 @@ void RClientControl::push_80211(Packet*p_in) case CLIENT3_MAC_SUFFIX: c = 3;break; case CLIENT4_MAC_SUFFIX: c = 4;break; } - syslog (LOG_DEBUG, "RClientControl: receive becon, ap %d, client %d, rssi %d\n", - ap+1, c, rssi_this); + if(c == identity) rssi[ap] = rssi_this; // if IDLE, considering switching - if(c == identity && state == IDLE && rssi[current_ap] < -67) + static unsigned int tmp_counter = 0; + tmp_counter++; + if(!(tmp_counter%print_interval)) + { + syslog (LOG_DEBUG, "RClientControl: receive becon, ap %d, client %d, rssi %d\n", + ap+1, c, rssi_this); + } + + + if(c == identity && state == IDLE) { - syslog (LOG_DEBUG, "Considering to switch\n"); unsigned i; unsigned max_id; - char max_rssi = -127; - // find max rssi - for(i=0;i max_rssi) + + if(interval > 0) + { + max_id = current_ap; + if(!(tmp_counter%interval)) { - max_rssi = rssi[i]; - max_id = i; + max_id = (max_id + 1)% 2; + syslog (LOG_DEBUG, "RClientControl: manually switch to ap %X\n", max_id+1); } + } + else + { + + char max_rssi = -127; + // find max rssi + for(i=0;i max_rssi) + { + max_rssi = rssi[i]; + max_id = i; + } + } if(max_id == current_ap) return; - + syslog (LOG_DEBUG, "RClientControl: Considering to switch\n"); control_content[0] = 0x04; control_content[1] = identity-1; control_content[2] = current_ap; diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index 783516e220..8c05e6d54f 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -37,6 +37,8 @@ class RClientControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; + int interval; + int print_interval const unsigned char ether_type_ip_suffix = 0x00; From 5cd1a2931b0bd5f568b777942433cdda2bc4321c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 13:58:04 -0500 Subject: [PATCH 114/171] debug --- elements/ip/80211r/rclientcontrol.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index 8c05e6d54f..a78d924373 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -38,7 +38,7 @@ class RClientControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; int interval; - int print_interval + int print_interval; const unsigned char ether_type_ip_suffix = 0x00; From f6f65939db336b4a5592efaaf5fbd7d252292b33 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 14:03:56 -0500 Subject: [PATCH 115/171] add min_time switch --- elements/ip/80211r/rclientcontrol.cc | 14 +++++++++++++- elements/ip/80211r/rclientcontrol.hh | 11 +++++++++-- include/clicknet/wgtt.h | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 10b926d689..8123a1e080 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -45,6 +45,9 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) case 1: cp_ethernet_address(CLIENT1_MAC, _ethh->ether_shost);break; } cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_dhost); + + time_lock = false; + last_time = 0; syslog (LOG_DEBUG, "RClientControl: finish configure, ready to start\n"); return 0; } @@ -143,6 +146,11 @@ void RClientControl::push_80211(Packet*p_in) ap+1, c, rssi_this); } + gettimeofday(&tv, NULL); + double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + if(now_time - last_time > SWITCH_MIN) + time_lock = false; + if(c == identity && state == IDLE) { @@ -170,7 +178,7 @@ void RClientControl::push_80211(Packet*p_in) max_id = i; } } - if(max_id == current_ap) + if(max_id == current_ap || time_lock) return; syslog (LOG_DEBUG, "RClientControl: Considering to switch\n"); control_content[0] = 0x04; @@ -187,6 +195,10 @@ void RClientControl::push_80211(Packet*p_in) syslog (LOG_DEBUG, "client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); current_ap = max_id; state = ANT; + time_lock = true; + gettimeofday(&tv, NULL); + last_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; + output(0).push(p); } diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index a78d924373..82e56d5117 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -10,6 +10,7 @@ #include #include #include +#include CLICK_DECLS @@ -37,10 +38,16 @@ class RClientControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; + + const unsigned char ether_type_ip_suffix = 0x00; + + int interval; int print_interval; - - const unsigned char ether_type_ip_suffix = 0x00; + // after issue switch, a time lock will be set for 1 second + bool time_lock; + double last_time; + struct timeval tv; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 62e8ff2cbf..ea5fa70834 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -58,8 +58,8 @@ struct my_test_struct { #define CONTROLLER_IN_MAC_SUFFIX 0x7d #define RING_SIZE 256 -// 1000 ms -#define SWITCH_MIN 500 +// unit ms +#define SWITCH_MIN 100000 // content encapsulated in mac header #define RESET_CONTENT 0xff From 2466d04a48bad5ad383f640592cc287adb7c78e0 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 14:06:55 -0500 Subject: [PATCH 116/171] add log header --- elements/ip/80211r/rapcontrol.cc | 10 +++++----- elements/ip/80211r/rclientcontrol.cc | 6 +++--- elements/ip/80211r/rcontrollercontrol.cc | 6 +++--- elements/ip/80211r/rssibecon.cc | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 2d7435223d..e816a4456c 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -108,7 +108,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RAPControl: ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == INACTIVE && t == 0x0a && tar == identity - 1) @@ -122,7 +122,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RAPControl: ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); @@ -147,7 +147,7 @@ void RAPControl::push_down_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "ap %d send ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RAPControl: ap %d send ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c-1] == IDLE && t == 0x08 && ori == identity-1) @@ -163,7 +163,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RAPControl: ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } else if(state[c-1] == INACTIVE && t == 0x0c && tar == identity-1) @@ -179,7 +179,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RAPControl: ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(1).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 8123a1e080..026f602df5 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -86,13 +86,13 @@ void RClientControl::push_control(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "client send reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RClientControl: client send reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(state == INACTIVE && t == 0x0d) { state = IDLE; - syslog (LOG_DEBUG, "client finish reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RClientControl: client finish reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); } p_in -> kill(); @@ -192,7 +192,7 @@ void RClientControl::push_80211(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); + syslog (LOG_DEBUG, "RClientControl: client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); current_ap = max_id; state = ANT; time_lock = true; diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index f6b16741cf..30e24f3ce5 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -103,7 +103,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); - syslog (LOG_DEBUG, "controller pass ant req for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RControllerControl: controller pass ant req for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x07) @@ -119,7 +119,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[ori]), sizeof(click_ether)); - syslog (LOG_DEBUG, "controller pass ant ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RControllerControl: controller pass ant ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x0b) @@ -136,7 +136,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); outport[c] = tar; - syslog (LOG_DEBUG, "controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "RControllerControl: controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index 396dc6d01d..05f12e7749 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -41,7 +41,7 @@ RSSIBecon::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "RSSIBecon: Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) syslog (LOG_DEBUG, "RSSIBecon: can not connect to backend iwinfo\n"); From d7fc774c9345ed3afe9a508efeac129a77bd52d2 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 14:59:29 -0500 Subject: [PATCH 117/171] debug --- elements/ip/80211r/rapcontrol.cc | 20 +++++++++++--------- elements/ip/80211r/rclientcontrol.cc | 6 ++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index e816a4456c..3693bb1e9f 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -30,6 +30,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) .complete() < 0) return -1; + //down control pkt identity = tmp_id; for(i=0;idata(), &(_ethh[c]), sizeof(click_ether)); syslog (LOG_DEBUG, "RAPControl: ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); - output(1).push(p); + output(2).push(p); } - else if(state[c-1] == INACTIVE && t == 0x0c && tar == identity-1) + else if(state[c] == INACTIVE && t == 0x0c && tar == identity-1) { state[c] = IDLE; control_content[0] = 0x0d; @@ -180,7 +183,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); syslog (LOG_DEBUG, "RAPControl: ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); - output(1).push(p); + output(2).push(p); } p_in -> kill(); @@ -200,7 +203,6 @@ void RAPControl::push_down_data(Packet*p_in) p_in -> kill(); else output(2).push(p_in); - } void RAPControl::push_up_data(Packet*p_in) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 026f602df5..24fd1a59ca 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -137,6 +137,8 @@ void RClientControl::push_80211(Packet*p_in) if(c == identity) rssi[ap] = rssi_this; + else + return; // if IDLE, considering switching static unsigned int tmp_counter = 0; tmp_counter++; @@ -152,7 +154,7 @@ void RClientControl::push_80211(Packet*p_in) time_lock = false; - if(c == identity && state == IDLE) + if(c == identity && state == IDLE && !time_lock) { unsigned i; unsigned max_id; @@ -178,7 +180,7 @@ void RClientControl::push_80211(Packet*p_in) max_id = i; } } - if(max_id == current_ap || time_lock) + if(max_id == current_ap) return; syslog (LOG_DEBUG, "RClientControl: Considering to switch\n"); control_content[0] = 0x04; From 57d4a0933bde61563efec6876e476b6cdd31f9fc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 18:10:13 -0500 Subject: [PATCH 118/171] log will also print --- elements/ip/80211r/rapcontrol.cc | 2 +- elements/ip/80211r/rclientcontrol.cc | 1 + elements/ip/80211r/rcontrollercontrol.cc | 2 +- elements/ip/80211r/rssibecon.cc | 1 + elements/ip/wgtt/csisep.cc | 3 +- elements/ip/wgtt/idadder.cc | 3 +- elements/ip/wgtt/packetselectionSerial.cc | 17 +++++------ elements/ip/wgtt/wgttqueue.cc | 35 +++++++++++------------ 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 3693bb1e9f..72ed102f6d 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -18,7 +18,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) { int i, tmp_start[4],tmp_id; - openlog ("RAPControl", LOG_CONS | LOG_NDELAY, 0); + openlog("RAPControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _ethh = new click_ether[MAX_N_CLIENT+1];//first MAX_N_CLIENT: ap->client; ap->controller if (Args(conf, this, errh) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 24fd1a59ca..5248cc80da 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -17,6 +17,7 @@ int RClientControl::configure(Vector &conf, ErrorHandler *errh) { int i, tmp_start[4],tmp_id; + openlog("RClientControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); for(i=0;i &conf, ErrorHandler *errh) { - int i, tmp_start[4]; + openlog("RControlerControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _ethh = new click_ether[MAX_N_AP*2]; if (Args(conf, this, errh) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index 05f12e7749..43d9430365 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -14,6 +14,7 @@ CLICK_DECLS RSSIBecon::RSSIBecon() { #ifdef __arm__ + openlog("RSSIBecon", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); syslog (LOG_DEBUG, "RSSIBecon: finish init\n"); #endif diff --git a/elements/ip/wgtt/csisep.cc b/elements/ip/wgtt/csisep.cc index 704286dbd2..e7a278ca2d 100755 --- a/elements/ip/wgtt/csisep.cc +++ b/elements/ip/wgtt/csisep.cc @@ -16,6 +16,7 @@ CLICK_DECLS CSISep::CSISep() { #ifdef __arm__ + openlog("CSISep", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); syslog (LOG_DEBUG, "CSISep: finish init\n"); // total_msg_cnt = 0; sample_counter = 0; @@ -46,7 +47,7 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "CSISep: Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) syslog (LOG_DEBUG, "CSISep: can not connect to backend iwinfo\n"); diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index 783ec572ac..df4bd43927 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -16,9 +16,10 @@ CLICK_DECLS IDAdder::IDAdder() { int i; + openlog("IDAdder", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); for(i=0; i &conf, ErrorHandler *errh) output_port[i] = first_start[i]-1; } - syslog (LOG_DEBUG, "PacketSelectionSerial out. Switch interval: %d\n", interval); + syslog (LOG_DEBUG, "Packetselection: finish configure. Switch interval: %d\n", interval); return 0; } @@ -109,7 +110,7 @@ void PacketSelectionSerial::reset_ap() } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "controller reset ap %X\n", i); + syslog (LOG_DEBUG, "Packetselection: controller reset ap %X\n", i); output(0).push(p); } } @@ -121,7 +122,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) state[c-CLIENT1_IP_SUFFIX] = IDLE; - syslog (LOG_DEBUG, "switch request ack, ip: %d.\n", c); + syslog (LOG_DEBUG, "Packetselection: switch request ack, ip: %d.\n", c); p_in -> kill(); } @@ -147,9 +148,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) { int rx_rate = status_rxrate(p_in); int tx_rate = status_txrate(p_in); - syslog (LOG_DEBUG, "client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); - syslog (LOG_DEBUG, "signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); - syslog (LOG_DEBUG, "rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", + syslog (LOG_DEBUG, "Packetselection: client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); + syslog (LOG_DEBUG, "Packetselection: signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); + syslog (LOG_DEBUG, "Packetselection: rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", rx_rate / 1000, rx_rate / 100, tx_rate / 1000, tx_rate / 100); } @@ -170,7 +171,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(!(tmp_counter%interval)) { best_ap = (best_ap + 1)% 2; - syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); + syslog (LOG_DEBUG, "Packetselection: prepare manually switch to ap %X\n", best_ap+1); } } if(best_ap != output_port[c]) @@ -196,7 +197,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + syslog (LOG_DEBUG, "Packetselection: Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); state[c] = SWITCH_REQ; output_port[c] = best_ap; diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index a60d6b3eb9..b1b674cddf 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -14,6 +14,7 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { int i; + openlog("WGTTQueue", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _q = new Packet **[MAX_N_CLIENT]; for(i=0; i &conf, ErrorHandler *errh) { - //syslog (LOG_DEBUG, "In configure\n"); int tmp[4], i; if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) @@ -47,20 +47,19 @@ WGTTQueue::configure(Vector &conf, ErrorHandler *errh) first_start[i] = tmp[i]; } - syslog (LOG_DEBUG, "wgtt configure succeed\n"); + syslog (LOG_DEBUG, "WGTTQueue: configure succeed\n"); return 0; } int WGTTQueue::initialize(ErrorHandler *errh) { - syslog (LOG_DEBUG, "wgtt in initialize\n"); int i; for(i=0; ierror("out of memory"); - syslog (LOG_DEBUG, "wgtt initialize succeed, ready to start\n"); + syslog (LOG_DEBUG, "WGTTQueue: initialize succeed, ready to start\n"); return 0; } @@ -142,7 +141,7 @@ WGTTQueue::deRing() flag = true; p = _q[next_client][_head[next_client]]; _head[next_client] = (_head[next_client]+1)%RING_SIZE; - syslog (LOG_DEBUG, "wgttQueue: deque pkt from queue: %d\n", next_client+1); + syslog (LOG_DEBUG, "WGTTQueue: deque pkt from queue: %d\n", next_client+1); break; } @@ -161,13 +160,13 @@ WGTTQueue::deRing() void WGTTQueue::push(int, Packet *p_in) { - syslog (LOG_DEBUG, "wgttQueue in push\n"); + syslog (LOG_DEBUG, "WGTTQueue: in push\n"); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; case DATA_SUFFIX: push_data(p_in);break; } - syslog (LOG_DEBUG, "wgttQueue out push\n"); + syslog (LOG_DEBUG, "WGTTQueue: out push\n"); } void WGTTQueue::push_control(Packet *p_in) @@ -178,7 +177,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(client_ip(p_in) == RESET_CONTENT) //reset { - syslog (LOG_DEBUG, "wgttQueue: receive reset req for client: %d\n", c+1); + syslog (LOG_DEBUG, "WGTTQueue: receive reset req for client: %d\n", c+1); for(i=0; idata()+sizeof(click_ether), &control_content, 2); memcpy(p->data(), &(_ethh[dst_ap+1]), sizeof(click_ether)); p_in -> kill(); - syslog (LOG_DEBUG, "wgttQueue send ap-ap seq\n"); + syslog (LOG_DEBUG, "WGTTQueue: send ap-ap seq\n"); checked_output_push(1, p); } } else //from ap { - syslog (LOG_DEBUG, "wgttQueue receive ap-ap seq for client: %d\n", c+1); + syslog (LOG_DEBUG, "WGTTQueue: receive ap-ap seq for client: %d\n", c+1); const unsigned char & start_seq = start_seq(p_in); while(_head[c] != start_seq) @@ -238,7 +237,7 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // syslog (LOG_DEBUG, "ap-c packet push\n"); _block[c] = false; - syslog (LOG_DEBUG, "wgttQueue send switch ack\n"); + syslog (LOG_DEBUG, "WGTTQueue: send switch ack\n"); checked_output_push(1, p); } } @@ -264,7 +263,7 @@ void WGTTQueue::push_data(Packet *p_in) enRing(c, 0); } p_in -> pull(15); - syslog (LOG_DEBUG, "wgttQueue after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + syslog (LOG_DEBUG, "WGTTQueue: after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } From 8e23a48ffe0e0a67afb7e1ed83d88ea178520ca7 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 19:04:33 -0500 Subject: [PATCH 119/171] debug --- elements/ip/wgtt/idadder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index df4bd43927..c7f10af359 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -26,7 +26,7 @@ void IDAdder::push(int port, Packet *p_in) { // a bug here, can not set ether net type, src at initialization static bool lock = false; - if(!false) + if(!lock) { lock = true; _ethh.ether_type = htons(ETHER_PROTO_BASE+DATA_SUFFIX); From 54077474524825b3c431ff70bd4d3e7af6661c4a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 19:31:18 -0500 Subject: [PATCH 120/171] debug, switch lower than -70dBm --- elements/ip/80211r/rclientcontrol.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 5248cc80da..00fec0219e 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -171,7 +171,8 @@ void RClientControl::push_80211(Packet*p_in) } else { - + if(rssi[current_ap] >= -70) + return; char max_rssi = -127; // find max rssi for(i=0;i Date: Sun, 1 Jan 2017 19:32:05 -0500 Subject: [PATCH 121/171] debug: switch interval smaller --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index ea5fa70834..6cf3062bed 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -59,7 +59,7 @@ struct my_test_struct { #define RING_SIZE 256 // unit ms -#define SWITCH_MIN 100000 +#define SWITCH_MIN 1000 // content encapsulated in mac header #define RESET_CONTENT 0xff From 38305e8db6c19291818dfa32b6bb04dfd1993318 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 19:41:30 -0500 Subject: [PATCH 122/171] simple log --- elements/ip/80211r/rapcontrol.cc | 16 ++++++++-------- elements/ip/80211r/rclientcontrol.cc | 16 ++++++++-------- elements/ip/80211r/rcontrollercontrol.cc | 8 ++++---- elements/ip/80211r/rssibecon.cc | 14 +++++++------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 72ed102f6d..6863c7997a 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -71,7 +71,7 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) case 0:cp_ethernet_address(CONTROLLER_IN_MAC, _ethh[MAX_N_CLIENT].ether_dhost);break; } - syslog (LOG_DEBUG, "RAPControl: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "finish configure, ready to start\n"); return 0; @@ -98,7 +98,7 @@ void RAPControl::push_up_control(Packet*p_in) const unsigned char & c = r_control_client(p_in); const unsigned char & ori = r_control_ori(p_in); const unsigned char & tar = r_control_tar(p_in); - syslog (LOG_DEBUG, "RAPControl: AP %d receive up control: state %d, type %X, client %d, ap_ori %d, ap_tar %d\n", identity, state[c], t, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "AP %d receive up control: state %d, type %X, client %d, ap_ori %d, ap_tar %d\n", identity, state[c], t, c+1, ori+1, tar+1); if(state[c] == IDLE && t == 0x04 && ori == identity - 1) { control_content[0] = 0x05; @@ -110,7 +110,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "RAPControl: ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c] == INACTIVE && t == 0x0a && tar == identity - 1) @@ -124,7 +124,7 @@ void RAPControl::push_up_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "RAPControl: ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); @@ -137,7 +137,7 @@ void RAPControl::push_down_control(Packet*p_in) const unsigned char & c = r_control_client(p_in); const unsigned char & ori = r_control_ori(p_in); const unsigned char & tar = r_control_tar(p_in); - syslog (LOG_DEBUG, "RAPControl: AP %d receive down control: state %d, type %X, client %d, ap_ori %d, ap_tar %d\n", identity, state[c], t, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "AP %d receive down control: state %d, type %X, client %d, ap_ori %d, ap_tar %d\n", identity, state[c], t, c+1, ori+1, tar+1); if(state[c] == INACTIVE && t == 0x06 && tar == identity-1) { @@ -150,7 +150,7 @@ void RAPControl::push_down_control(Packet*p_in) // // data part memcpy(p->data(), &control_content, 4); - syslog (LOG_DEBUG, "RAPControl: ap %d send ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d send ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } else if(state[c] == IDLE && t == 0x08 && ori == identity-1) @@ -166,7 +166,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "RAPControl: ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass ant ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(2).push(p); } else if(state[c] == INACTIVE && t == 0x0c && tar == identity-1) @@ -182,7 +182,7 @@ void RAPControl::push_down_control(Packet*p_in) memcpy(p->data()+sizeof(click_ether), &control_content, 4); memcpy(p->data(), &(_ethh[c]), sizeof(click_ether)); - syslog (LOG_DEBUG, "RAPControl: ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(2).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 00fec0219e..5b17700659 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -49,7 +49,7 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) time_lock = false; last_time = 0; - syslog (LOG_DEBUG, "RClientControl: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "finish configure, ready to start\n"); return 0; } @@ -87,13 +87,13 @@ void RClientControl::push_control(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "RClientControl: client send reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "client send reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(state == INACTIVE && t == 0x0d) { state = IDLE; - syslog (LOG_DEBUG, "RClientControl: client finish reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "client finish reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); } p_in -> kill(); @@ -102,7 +102,7 @@ void RClientControl::push_control(Packet*p_in) void RClientControl::push_downdata(Packet*p_in) { WritablePacket *p = p_in->uniqueify(); - //printf("RClientControl: ether type: %u\n", r_ether_type_suffix(p)); + //printf("ether type: %u\n", r_ether_type_suffix(p)); if(r_ether_type_suffix(p) == 0x03) { memcpy(p->data()+13, ðer_type_ip_suffix, 1); @@ -145,7 +145,7 @@ void RClientControl::push_80211(Packet*p_in) tmp_counter++; if(!(tmp_counter%print_interval)) { - syslog (LOG_DEBUG, "RClientControl: receive becon, ap %d, client %d, rssi %d\n", + syslog (LOG_DEBUG, "receive becon, ap %d, client %d, rssi %d\n", ap+1, c, rssi_this); } @@ -166,7 +166,7 @@ void RClientControl::push_80211(Packet*p_in) if(!(tmp_counter%interval)) { max_id = (max_id + 1)% 2; - syslog (LOG_DEBUG, "RClientControl: manually switch to ap %X\n", max_id+1); + syslog (LOG_DEBUG, "manually switch to ap %X\n", max_id+1); } } else @@ -184,7 +184,7 @@ void RClientControl::push_80211(Packet*p_in) } if(max_id == current_ap) return; - syslog (LOG_DEBUG, "RClientControl: Considering to switch\n"); + syslog (LOG_DEBUG, "Considering to switch\n"); control_content[0] = 0x04; control_content[1] = identity-1; control_content[2] = current_ap; @@ -196,7 +196,7 @@ void RClientControl::push_80211(Packet*p_in) memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "RClientControl: client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); + syslog (LOG_DEBUG, "client send ant req for client %d, ap_ori %d, ap_tar %d\n", identity, current_ap+1, max_id+1); current_ap = max_id; state = ANT; time_lock = true; diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index b6b3057e90..e4ef6bbd82 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -66,7 +66,7 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) case 7:cp_ethernet_address(AP8_MAC, _ethh[i+MAX_N_AP].ether_dhost);break; } } - syslog (LOG_DEBUG, "RControllerControl: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "finish configure, ready to start\n"); return 0; } @@ -103,7 +103,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); - syslog (LOG_DEBUG, "RControllerControl: controller pass ant req for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass ant req for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x07) @@ -119,7 +119,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[ori]), sizeof(click_ether)); - syslog (LOG_DEBUG, "RControllerControl: controller pass ant ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller pass ant ack for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } else if(t == 0x0b) @@ -136,7 +136,7 @@ void RControlerControl::push_up_control(Packet*p_in) memcpy(p->data(), &(_ethh[tar]), sizeof(click_ether)); outport[c] = tar; - syslog (LOG_DEBUG, "RControllerControl: controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); + syslog (LOG_DEBUG, "controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } p_in -> kill(); diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index 43d9430365..12a69f9c68 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -15,7 +15,7 @@ RSSIBecon::RSSIBecon() { #ifdef __arm__ openlog("RSSIBecon", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); - syslog (LOG_DEBUG, "RSSIBecon: finish init\n"); + syslog (LOG_DEBUG, "finish init\n"); #endif } @@ -42,12 +42,12 @@ RSSIBecon::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_DEBUG, "RSSIBecon: Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) - syslog (LOG_DEBUG, "RSSIBecon: can not connect to backend iwinfo\n"); + syslog (LOG_DEBUG, "can not connect to backend iwinfo\n"); #endif - syslog (LOG_DEBUG, "RSSIBecon: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "finish configure, ready to start\n"); return 0; } @@ -58,9 +58,9 @@ RSSIBecon::fragment(Packet *p_in) int i,j; if(!(iw->assoclist(ifname, buf, &len))) - // // syslog (LOG_DEBUG, "RSSIBecon: can not find associlist\n"); + // // syslog (LOG_DEBUG, "can not find associlist\n"); // else if (len <= 0) - // // syslog (LOG_DEBUG, "RSSIBecon: associ number < 0\n"); + // // syslog (LOG_DEBUG, "associ number < 0\n"); // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); @@ -99,7 +99,7 @@ void RSSIBecon::push(int, Packet *p) { #ifdef __arm__ - // syslog (LOG_DEBUG, "RSSIBecon: in push\n"); + // syslog (LOG_DEBUG, "in push\n"); fragment(p); #endif } From 390dc3fb8662c2f2c7849abd93fba46a3201e7c0 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 19:50:30 -0500 Subject: [PATCH 123/171] debug: print rssi when switching --- elements/ip/80211r/rclientcontrol.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 5b17700659..965c3b9010 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -173,6 +173,7 @@ void RClientControl::push_80211(Packet*p_in) { if(rssi[current_ap] >= -70) return; + char max_rssi = -127; // find max rssi for(i=0;i Date: Sun, 1 Jan 2017 19:56:28 -0500 Subject: [PATCH 124/171] debug: first update and then switch --- elements/ip/80211r/rclientcontrol.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 965c3b9010..e7592fa915 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -140,6 +140,10 @@ void RClientControl::push_80211(Packet*p_in) rssi[ap] = rssi_this; else return; + + //if not update, return + if(rssi[current]==-127) + return; // if IDLE, considering switching static unsigned int tmp_counter = 0; tmp_counter++; From 5c985caed84f98095a8f23161533f74d96535a64 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 19:57:24 -0500 Subject: [PATCH 125/171] debug --- elements/ip/80211r/rclientcontrol.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index e7592fa915..0cfdb18133 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -142,7 +142,7 @@ void RClientControl::push_80211(Packet*p_in) return; //if not update, return - if(rssi[current]==-127) + if(rssi[current_ap]==-127) return; // if IDLE, considering switching static unsigned int tmp_counter = 0; From 0a07c3fae5f09ceba6d39a38f69f01b1da2989fc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 1 Jan 2017 20:01:25 -0500 Subject: [PATCH 126/171] debug: lower switching threshold --- elements/ip/80211r/rclientcontrol.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 0cfdb18133..fb1ae6354b 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -175,7 +175,7 @@ void RClientControl::push_80211(Packet*p_in) } else { - if(rssi[current_ap] >= -70) + if(rssi[current_ap] >= -68) return; char max_rssi = -127; From 5d399a35ac93a1e190a4db7d9c26c054577f4d59 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 3 Jan 2017 19:25:24 -0500 Subject: [PATCH 127/171] tolerate for ap forwarding up --- elements/ip/80211r/rapcontrol.cc | 5 +++-- include/clicknet/wgtt.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 6863c7997a..030ac3e0a5 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -99,7 +99,8 @@ void RAPControl::push_up_control(Packet*p_in) const unsigned char & ori = r_control_ori(p_in); const unsigned char & tar = r_control_tar(p_in); syslog (LOG_DEBUG, "AP %d receive up control: state %d, type %X, client %d, ap_ori %d, ap_tar %d\n", identity, state[c], t, c+1, ori+1, tar+1); - if(state[c] == IDLE && t == 0x04 && ori == identity - 1) + //if(state[c] == IDLE && t == 0x04 && ori == identity - 1) + if(t == 0x04) { control_content[0] = 0x05; control_content[1] = c; @@ -113,7 +114,7 @@ void RAPControl::push_up_control(Packet*p_in) syslog (LOG_DEBUG, "ap %d pass ant req for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); } - else if(state[c] == INACTIVE && t == 0x0a && tar == identity - 1) + else if(t == 0x0a) //(state[c] == INACTIVE && t == 0x0a && tar == identity - 1) { control_content[0] = 0x0b; control_content[1] = c; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 6cf3062bed..62d50b4a71 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -40,7 +40,7 @@ struct my_test_struct { #define CLIENT4_MAC_SUFFIX 0x0a #define CLIENT1_MAC "44:c3:06:31:5b:07" // ap -#define MAX_N_AP 6 +#define MAX_N_AP 8 #define CLIENT1_IP_SUFFIX 135 #define AP1_MAC "70:88:6b:80:60:01" #define AP2_MAC "70:88:6b:80:60:02" From 9999a5646933e1ab1c39344cad9b4e62aac742dc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 3 Jan 2017 19:39:49 -0500 Subject: [PATCH 128/171] simplify log --- elements/ip/wgtt/csisep.cc | 10 +++---- elements/ip/wgtt/idadder.cc | 2 +- elements/ip/wgtt/packetselectionSerial.cc | 18 ++++++------ elements/ip/wgtt/wgttqueue.cc | 34 +++++++++++------------ 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/elements/ip/wgtt/csisep.cc b/elements/ip/wgtt/csisep.cc index e7a278ca2d..23c06297e5 100755 --- a/elements/ip/wgtt/csisep.cc +++ b/elements/ip/wgtt/csisep.cc @@ -16,8 +16,8 @@ CLICK_DECLS CSISep::CSISep() { #ifdef __arm__ - openlog("CSISep", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); - syslog (LOG_DEBUG, "CSISep: finish init\n"); + openlog("APControl_CSISep", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + syslog (LOG_DEBUG, "finish init\n"); // total_msg_cnt = 0; sample_counter = 0; #endif @@ -47,12 +47,12 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) else if(wlan_port == 1) strcpy(ifname, "wlan1"); else - syslog (LOG_DEBUG, "CSISep: Invalid wlan_port argument\n"); + syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); iw = iwinfo_backend(ifname); if (!iw) - syslog (LOG_DEBUG, "CSISep: can not connect to backend iwinfo\n"); + syslog (LOG_DEBUG, "Can not connect to backend iwinfo\n"); #endif - syslog (LOG_DEBUG, "CSISep: finish configure, ready to start\n"); + syslog (LOG_DEBUG, "Finish configure, ready to start\n"); return 0; } diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index c7f10af359..542d1f6d7d 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -19,7 +19,7 @@ IDAdder::IDAdder() openlog("IDAdder", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); for(i=0; iether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); - syslog (LOG_DEBUG, "Packetselection: init finish, ready to start\n"); + syslog (LOG_DEBUG, "Init finish, ready to start\n"); } int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) @@ -65,7 +65,7 @@ int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) output_port[i] = first_start[i]-1; } - syslog (LOG_DEBUG, "Packetselection: finish configure. Switch interval: %d\n", interval); + syslog (LOG_DEBUG, "Finish configure. Switch interval: %d\n", interval); return 0; } @@ -110,7 +110,7 @@ void PacketSelectionSerial::reset_ap() } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "Packetselection: controller reset ap %X\n", i); + syslog (LOG_DEBUG, "Controller reset ap %X\n", i); output(0).push(p); } } @@ -122,7 +122,7 @@ void PacketSelectionSerial::push_control(Packet *p_in) state[c-CLIENT1_IP_SUFFIX] = IDLE; - syslog (LOG_DEBUG, "Packetselection: switch request ack, ip: %d.\n", c); + syslog (LOG_DEBUG, "Switch request ack, ip: %d.\n", c); p_in -> kill(); } @@ -148,9 +148,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) { int rx_rate = status_rxrate(p_in); int tx_rate = status_txrate(p_in); - syslog (LOG_DEBUG, "Packetselection: client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); - syslog (LOG_DEBUG, "Packetselection: signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); - syslog (LOG_DEBUG, "Packetselection: rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", + syslog (LOG_DEBUG, "client mac: %X, ap id: %X\n", status_mac(p_in), status_ap(p_in)); + syslog (LOG_DEBUG, "signal: %d, noise: %d\n", status_score(p_in), status_noise(p_in)); + syslog (LOG_DEBUG, "rx_rate: %d.%dMb/s, tx_rate: %d.%d Mb/s\n", rx_rate / 1000, rx_rate / 100, tx_rate / 1000, tx_rate / 100); } @@ -171,7 +171,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(!(tmp_counter%interval)) { best_ap = (best_ap + 1)% 2; - syslog (LOG_DEBUG, "Packetselection: prepare manually switch to ap %X\n", best_ap+1); + syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); } } if(best_ap != output_port[c]) @@ -197,7 +197,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "Packetselection: Issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); state[c] = SWITCH_REQ; output_port[c] = best_ap; diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index b1b674cddf..dad901ddec 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -14,7 +14,7 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { int i; - openlog("WGTTQueue", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + openlog("APControl_WGTTQueue", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _q = new Packet **[MAX_N_CLIENT]; for(i=0; i &conf, ErrorHandler *errh) first_start[i] = tmp[i]; } - syslog (LOG_DEBUG, "WGTTQueue: configure succeed\n"); + syslog (LOG_DEBUG, "configure succeed\n"); return 0; } @@ -58,8 +58,8 @@ WGTTQueue::initialize(ErrorHandler *errh) for(i=0; ierror("out of memory"); - syslog (LOG_DEBUG, "WGTTQueue: initialize succeed, ready to start\n"); + syslog (LOG_DEBUG, "initialize succeed, ready to start\n"); return 0; } @@ -141,7 +141,7 @@ WGTTQueue::deRing() flag = true; p = _q[next_client][_head[next_client]]; _head[next_client] = (_head[next_client]+1)%RING_SIZE; - syslog (LOG_DEBUG, "WGTTQueue: deque pkt from queue: %d\n", next_client+1); + syslog (LOG_DEBUG, "deque pkt from queue: %d\n", next_client+1); break; } @@ -160,13 +160,13 @@ WGTTQueue::deRing() void WGTTQueue::push(int, Packet *p_in) { - syslog (LOG_DEBUG, "WGTTQueue: in push\n"); + syslog (LOG_DEBUG, "in push\n"); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; case DATA_SUFFIX: push_data(p_in);break; } - syslog (LOG_DEBUG, "WGTTQueue: out push\n"); + syslog (LOG_DEBUG, "out push\n"); } void WGTTQueue::push_control(Packet *p_in) @@ -177,7 +177,7 @@ void WGTTQueue::push_control(Packet *p_in) { if(client_ip(p_in) == RESET_CONTENT) //reset { - syslog (LOG_DEBUG, "WGTTQueue: receive reset req for client: %d\n", c+1); + syslog (LOG_DEBUG, "receive reset req for client: %d\n", c+1); for(i=0; idata()+sizeof(click_ether), &control_content, 2); memcpy(p->data(), &(_ethh[dst_ap+1]), sizeof(click_ether)); p_in -> kill(); - syslog (LOG_DEBUG, "WGTTQueue: send ap-ap seq\n"); + syslog (LOG_DEBUG, "send ap-ap seq\n"); checked_output_push(1, p); } } else //from ap { - syslog (LOG_DEBUG, "WGTTQueue: receive ap-ap seq for client: %d\n", c+1); + syslog (LOG_DEBUG, "receive ap-ap seq for client: %d\n", c+1); const unsigned char & start_seq = start_seq(p_in); while(_head[c] != start_seq) @@ -237,7 +237,7 @@ void WGTTQueue::push_control(Packet *p_in) p_in -> kill(); // syslog (LOG_DEBUG, "ap-c packet push\n"); _block[c] = false; - syslog (LOG_DEBUG, "WGTTQueue: send switch ack\n"); + syslog (LOG_DEBUG, "send switch ack\n"); checked_output_push(1, p); } } @@ -263,7 +263,7 @@ void WGTTQueue::push_data(Packet *p_in) enRing(c, 0); } p_in -> pull(15); - syslog (LOG_DEBUG, "WGTTQueue: after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + syslog (LOG_DEBUG, "after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } From 47a5a77ffc9561879706fad6241c9904a769a07c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 3 Jan 2017 19:55:10 -0500 Subject: [PATCH 129/171] debug for switching --- elements/ip/wgtt/packetselectionSerial.cc | 5 +++-- elements/ip/wgtt/wgttqueue.cc | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 9c76baec60..ae15ac203f 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -110,7 +110,7 @@ void PacketSelectionSerial::reset_ap() } memcpy(p->data(), _ethh, sizeof(click_ether)); - syslog (LOG_DEBUG, "Controller reset ap %X\n", i); + syslog (LOG_DEBUG, "Controller reset ap %X\n", i+1); output(0).push(p); } } @@ -159,11 +159,12 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(now_time - last_time[c] > SWITCH_MIN) time_lock[c] = false; + if(state[c] == IDLE && !time_lock[c]) { // syslog (LOG_DEBUG, "state idle\n"); unsigned char best_ap = find_best_ap(c); - + syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); // WGTT if(interval>0) { diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index dad901ddec..1acc0c78ee 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -141,7 +141,7 @@ WGTTQueue::deRing() flag = true; p = _q[next_client][_head[next_client]]; _head[next_client] = (_head[next_client]+1)%RING_SIZE; - syslog (LOG_DEBUG, "deque pkt from queue: %d\n", next_client+1); + // syslog (LOG_DEBUG, "deque pkt from queue: %d\n", next_client+1); break; } @@ -160,13 +160,13 @@ WGTTQueue::deRing() void WGTTQueue::push(int, Packet *p_in) { - syslog (LOG_DEBUG, "in push\n"); + // syslog (LOG_DEBUG, "in push\n"); switch(pkt_type(p_in)) { case CONTROL_SUFFIX: push_control(p_in);break; case DATA_SUFFIX: push_data(p_in);break; } - syslog (LOG_DEBUG, "out push\n"); + // syslog (LOG_DEBUG, "out push\n"); } void WGTTQueue::push_control(Packet *p_in) @@ -263,7 +263,7 @@ void WGTTQueue::push_data(Packet *p_in) enRing(c, 0); } p_in -> pull(15); - syslog (LOG_DEBUG, "after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + // syslog (LOG_DEBUG, "after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } From 816d58445c961fcc38ff0ba918e89e80b4a1aee6 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 3 Jan 2017 20:29:21 -0500 Subject: [PATCH 130/171] add global switching scheme --- elements/ip/wgtt/packetselectionSerial.cc | 31 ++++++++++++++++++++--- elements/ip/wgtt/packetselectionSerial.hh | 3 ++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index ae15ac203f..f1d0773ad8 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -163,8 +163,8 @@ void PacketSelectionSerial::push_status(Packet *p_in) if(state[c] == IDLE && !time_lock[c]) { // syslog (LOG_DEBUG, "state idle\n"); - unsigned char best_ap = find_best_ap(c); - syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); + unsigned char best_ap; + // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); // WGTT if(interval>0) { @@ -175,6 +175,9 @@ void PacketSelectionSerial::push_status(Packet *p_in) syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); } } + else + best_ap = find_best_ap_global(c); + if(best_ap != output_port[c]) { // send_meg(best_ap) @@ -214,7 +217,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } // incomplete version, only for 2 ap and 1 client -unsigned char PacketSelectionSerial::find_best_ap(unsigned char c) +unsigned char PacketSelectionSerial::find_best_ap_neighbor(unsigned char c) { unsigned char ¤t = output_port[c]; @@ -269,6 +272,28 @@ unsigned char PacketSelectionSerial::find_best_ap(unsigned char c) return current; } +// incomplete version, only for 2 ap and 1 client +unsigned char PacketSelectionSerial::find_best_ap_global(unsigned char c) +{ + int min_id, min_value = 9999; + unsigned char i, j; + for(i=0; i Date: Tue, 3 Jan 2017 20:30:51 -0500 Subject: [PATCH 131/171] debug --- elements/ip/wgtt/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index f1d0773ad8..af439fff23 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -290,7 +290,7 @@ unsigned char PacketSelectionSerial::find_best_ap_global(unsigned char c) min_value = sum; } } - return i; + return min_id; } From b3f5fb523840f03301d6040dc13af2878702d784 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Tue, 3 Jan 2017 20:31:56 -0500 Subject: [PATCH 132/171] debug --- elements/ip/wgtt/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index af439fff23..a8311075aa 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -275,7 +275,7 @@ unsigned char PacketSelectionSerial::find_best_ap_neighbor(unsigned char c) // incomplete version, only for 2 ap and 1 client unsigned char PacketSelectionSerial::find_best_ap_global(unsigned char c) { - int min_id, min_value = 9999; + int min_id = 0, min_value = 9999; unsigned char i, j; for(i=0; i Date: Tue, 10 Jan 2017 21:49:42 -0500 Subject: [PATCH 133/171] normal the csi, status collection --- elements/ip/wgtt/csicollect.cc | 130 ++++++++++++++++++ elements/ip/wgtt/csicollect.hh | 59 ++++++++ .../ip/wgtt/{csisep.cc => statuscollect.cc} | 22 +-- .../ip/wgtt/{csisep.hh => statuscollect.hh} | 12 +- 4 files changed, 206 insertions(+), 17 deletions(-) create mode 100755 elements/ip/wgtt/csicollect.cc create mode 100755 elements/ip/wgtt/csicollect.hh rename elements/ip/wgtt/{csisep.cc => statuscollect.cc} (81%) rename elements/ip/wgtt/{csisep.hh => statuscollect.hh} (78%) diff --git a/elements/ip/wgtt/csicollect.cc b/elements/ip/wgtt/csicollect.cc new file mode 100755 index 0000000000..2244ee6200 --- /dev/null +++ b/elements/ip/wgtt/csicollect.cc @@ -0,0 +1,130 @@ +/* + sample csi, rssi from TP-Link router + Input: data pkt + Output: port 0: csi pkt, port 1: rssi pkt + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "csicollect.hh" +#include +#include +#include + +CLICK_DECLS + +CSICollect::CSICollect() +{ +#ifdef __mips__ + openlog("APControl_CSICollect", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + syslog (LOG_DEBUG, "finish init\n"); + // total_msg_cnt = 0; + sample_counter = 0; +#endif + +} + +CSICollect::~CSICollect() +{ +#ifdef __mips__ + iwinfo_finish(); +#endif +} + +int +CSICollect::configure(Vector &conf, ErrorHandler *errh) +{ + int wlan_port; + int tmp_len; + if (Args(conf, this, errh) + .read_p("SAMPLERATE", IntArg(), sample_rate) + .read_p("WLANPORT", IntArg(), wlan_port) + .read_p("PACKETLENGTH", IntArg(), tmp_len) + .complete() < 0) + return -1; + +#ifdef __mips__ + packet_length = tmp_len; + if(wlan_port == 0) + strcpy(ifname, "wlan0"); + else if(wlan_port == 1) + strcpy(ifname, "wlan1"); + else + syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); + iw = iwinfo_backend(ifname); + if (!iw) + syslog (LOG_DEBUG, "Can not connect to backend iwinfo\n"); +#endif + syslog (LOG_DEBUG, "Finish configure, ready to start\n"); + return 0; +} + +void +CSICollect::fragment(Packet *p_in) +{ +#ifdef __mips__ + int i,j; + sample_counter ++; + if(sample_counter>sample_rate) + { + sample_counter = 0; + + if(!(iw->assoclist(ifname, buf, &len))) + // // syslog (LOG_DEBUG, "CSICollect: can not find associlist\n"); + // else if (len <= 0) + // // syslog (LOG_DEBUG, "CSICollect: associ number < 0\n"); + // else if (len) + { + // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); + + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + { + //one pkt per client + WritablePacket *p_csi = Packet::make(11); + j=0; + e = (struct iwinfo_assoclist_entry *) &buf[i]; + uint8_t & mac = e->mac[5]; + int8_t & signal = e->signal; + int8_t & noise = e->noise; + uint32_t & rx_rate = (e->rx_rate).rate; + uint32_t & tx_rate = (e->tx_rate).rate; + + memcpy(p_csi->data()+j, &(mac), 1); + j += 1; + memcpy(p_csi->data()+j, &(signal), 1); + j += 1; + memcpy(p_csi->data()+j, &(noise), 1); + j += 1; + memcpy(p_csi->data()+j, &(rx_rate), 4); + j += 4; + memcpy(p_csi->data()+j, &(tx_rate), 4); + j += 4; + output(1).push(p_csi); + } + + } + } + + if(p_in->length() > packet_length) + { + p_in->pull(p_in->length() - 140); + output(0).push(p_in); + } + else + p_in -> kill(); + +#endif +} + +void +CSICollect::push(int, Packet *p) +{ +#ifdef __mips__ + // syslog (LOG_DEBUG, "CSICollect: in push\n"); + fragment(p); +#endif +} + + +CLICK_ENDDECLS +EXPORT_ELEMENT(CSICollect) \ No newline at end of file diff --git a/elements/ip/wgtt/csicollect.hh b/elements/ip/wgtt/csicollect.hh new file mode 100755 index 0000000000..ae945d9b01 --- /dev/null +++ b/elements/ip/wgtt/csicollect.hh @@ -0,0 +1,59 @@ +/* + sample csi, rssi from TP-Link router + Input: data pkt + Output: port 0: csi pkt, port 1: rssi pkt + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#ifndef CLICK_CSICOLLECT_HH +#define CLICK_CSICOLLECT_HH +#include +#include +#include +#include +#include +#include +#ifdef __mips__ +#include +extern "C" +{ + #include "iwinfo.h" +} +#endif + + +CLICK_DECLS + +class CSICollect : public Element { public: + + CSICollect() CLICK_COLD; + ~CSICollect() CLICK_COLD; + + const char *class_name() const { return "CSICollect"; } + const char *port_count() const { return PORTS_1_1X2; } + const char *processing() const { return PUSH; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void push(int, Packet *); + void fragment(Packet *); + + private: + + int sample_rate; + int sample_counter; + +#ifdef __mips__ + int len; + const struct iwinfo_ops *iw; + char buf[IWINFO_BUFSIZE]; + char ifname[6]; + struct iwinfo_assoclist_entry *e; + unsigned int packet_length; +#endif + + +}; + +CLICK_ENDDECLS +#endif diff --git a/elements/ip/wgtt/csisep.cc b/elements/ip/wgtt/statuscollect.cc similarity index 81% rename from elements/ip/wgtt/csisep.cc rename to elements/ip/wgtt/statuscollect.cc index 23c06297e5..51305b1ed8 100755 --- a/elements/ip/wgtt/csisep.cc +++ b/elements/ip/wgtt/statuscollect.cc @@ -6,17 +6,17 @@ */ #include -#include "csisep.hh" +#include "statuscollect.hh" #include #include #include CLICK_DECLS -CSISep::CSISep() +StatusCollect::StatusCollect() { #ifdef __arm__ - openlog("APControl_CSISep", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + openlog("APControl_StatusCollect", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); syslog (LOG_DEBUG, "finish init\n"); // total_msg_cnt = 0; sample_counter = 0; @@ -24,7 +24,7 @@ CSISep::CSISep() } -CSISep::~CSISep() +StatusCollect::~StatusCollect() { #ifdef __arm__ iwinfo_finish(); @@ -32,7 +32,7 @@ CSISep::~CSISep() } int -CSISep::configure(Vector &conf, ErrorHandler *errh) +StatusCollect::configure(Vector &conf, ErrorHandler *errh) { int wlan_port; if (Args(conf, this, errh) @@ -57,7 +57,7 @@ CSISep::configure(Vector &conf, ErrorHandler *errh) } void -CSISep::fragment(Packet *p_in) +StatusCollect::fragment(Packet *p_in) { #ifdef __arm__ int i,j; @@ -67,9 +67,9 @@ CSISep::fragment(Packet *p_in) sample_counter = 0; if(!(iw->assoclist(ifname, buf, &len))) - // // syslog (LOG_DEBUG, "CSISep: can not find associlist\n"); + // // syslog (LOG_DEBUG, "StatusCollect: can not find associlist\n"); // else if (len <= 0) - // // syslog (LOG_DEBUG, "CSISep: associ number < 0\n"); + // // syslog (LOG_DEBUG, "StatusCollect: associ number < 0\n"); // else if (len) { // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); @@ -107,14 +107,14 @@ CSISep::fragment(Packet *p_in) } void -CSISep::push(int, Packet *p) +StatusCollect::push(int, Packet *p) { #ifdef __arm__ - // syslog (LOG_DEBUG, "CSISep: in push\n"); + // syslog (LOG_DEBUG, "StatusCollect: in push\n"); fragment(p); #endif } CLICK_ENDDECLS -EXPORT_ELEMENT(CSISep) \ No newline at end of file +EXPORT_ELEMENT(StatusCollect) \ No newline at end of file diff --git a/elements/ip/wgtt/csisep.hh b/elements/ip/wgtt/statuscollect.hh similarity index 78% rename from elements/ip/wgtt/csisep.hh rename to elements/ip/wgtt/statuscollect.hh index 7d0f95582e..7ec0990fcc 100755 --- a/elements/ip/wgtt/csisep.hh +++ b/elements/ip/wgtt/statuscollect.hh @@ -5,8 +5,8 @@ Created by Zhenyu Song: sunnyszy@gmail.com */ -#ifndef CLICK_CSISEP_HH -#define CLICK_CSISEP_HH +#ifndef CLICK_STATUSCOLLECT_HH +#define CLICK_STATUSCOLLECT_HH #include #include #include @@ -24,12 +24,12 @@ extern "C" CLICK_DECLS -class CSISep : public Element { public: +class StatusCollect : public Element { public: - CSISep() CLICK_COLD; - ~CSISep() CLICK_COLD; + StatusCollect() CLICK_COLD; + ~StatusCollect() CLICK_COLD; - const char *class_name() const { return "CSISep"; } + const char *class_name() const { return "StatusCollect"; } const char *port_count() const { return PORTS_1_1X2; } const char *processing() const { return PUSH; } From 95a7cb23b868f538edf126d1ce5125ef5a7b7a96 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 16:19:46 -0500 Subject: [PATCH 134/171] add a simple switch only controller --- elements/ip/wgtt/csicollect.cc | 5 +- elements/ip/wgtt/csicollect.hh | 1 - elements/ip/wgtt/simpleControllerSwitch.cc | 142 +++++++++++++++++++++ elements/ip/wgtt/simpleControllerSwitch.hh | 54 ++++++++ 4 files changed, 197 insertions(+), 5 deletions(-) create mode 100755 elements/ip/wgtt/simpleControllerSwitch.cc create mode 100755 elements/ip/wgtt/simpleControllerSwitch.hh diff --git a/elements/ip/wgtt/csicollect.cc b/elements/ip/wgtt/csicollect.cc index 2244ee6200..c2929b31d6 100755 --- a/elements/ip/wgtt/csicollect.cc +++ b/elements/ip/wgtt/csicollect.cc @@ -35,16 +35,13 @@ int CSICollect::configure(Vector &conf, ErrorHandler *errh) { int wlan_port; - int tmp_len; if (Args(conf, this, errh) .read_p("SAMPLERATE", IntArg(), sample_rate) .read_p("WLANPORT", IntArg(), wlan_port) - .read_p("PACKETLENGTH", IntArg(), tmp_len) .complete() < 0) return -1; #ifdef __mips__ - packet_length = tmp_len; if(wlan_port == 0) strcpy(ifname, "wlan0"); else if(wlan_port == 1) @@ -105,7 +102,7 @@ CSICollect::fragment(Packet *p_in) } } - if(p_in->length() > packet_length) + if(p_in->length() > 141) { p_in->pull(p_in->length() - 140); output(0).push(p_in); diff --git a/elements/ip/wgtt/csicollect.hh b/elements/ip/wgtt/csicollect.hh index ae945d9b01..4f0717a5dd 100755 --- a/elements/ip/wgtt/csicollect.hh +++ b/elements/ip/wgtt/csicollect.hh @@ -49,7 +49,6 @@ class CSICollect : public Element { public: char buf[IWINFO_BUFSIZE]; char ifname[6]; struct iwinfo_assoclist_entry *e; - unsigned int packet_length; #endif diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc new file mode 100755 index 0000000000..85ac16da1e --- /dev/null +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -0,0 +1,142 @@ +/* + Controller program, generate simple data and switch control + Input: trigger packet + Output: control & data + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "simpleControllerSwitch.hh" +#include +#include +#include +#include + +CLICK_DECLS + +SimpleControllerSwitch::SimpleControllerSwitch() +{ + openlog("SimpleControllerSwitch", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + + _ethh = new click_ether; + _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); + cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); + output_port = 3; + + syslog (LOG_DEBUG, "Init finish, ready to start\n"); +} + +int SimpleControllerSwitch::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("SWITCHINTERVAL", IntArg(), interval) + .complete() < 0) + return -1; + + syslog (LOG_DEBUG, "Finish configure. Switch interval: %d\n", interval); + return 0; +} + +void SimpleControllerSwitch::push(int port, Packet *p_in) +{ + // here is a small bug, I can not put the reset function in the initial function + static unsigned char lock = 0; + if(!lock) + { + lock++; + reset_ap(); + } + + // syslog (LOG_DEBUG, "pkt_type: %x\n", pkt_type(p_in)); + push_status(p_in); + +} + +void SimpleControllerSwitch::reset_ap() +{ + control_content[0] = RESET_CONTENT; + control_content[1] = RESET_CONTENT; + for(int i=0;idata()+sizeof(click_ether), &control_content, 2); + //ether part + switch(i) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_DEBUG, "Controller reset ap %X\n", i+1); + output(0).push(p); + } +} + +void SimpleControllerSwitch::push_status(Packet *p_in) +{ + const unsigned char a = status_ap(p_in) - 1; + unsigned char c = 0; + static unsigned int tmp_counter = 0; + tmp_counter++; + + p_in -> kill(); + // syslog (LOG_DEBUG, "state idle\n"); + unsigned char best_ap; + // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); + // WGTT + + + if(!(tmp_counter%interval)) + { + best_ap = output_port; + best_ap = 7 - best_ap; //only switch between 3,4 + syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); + + // send_meg(best_ap) + WritablePacket *p = Packet::make(sizeof(click_ether)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = CLIENT1_IP_SUFFIX + c; + control_content[1] = best_ap; + memcpy(p->data()+sizeof(click_ether), &control_content, 2); + //ether part + switch(output_port) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + output_port = best_ap; + + output(1).push(p); + } + + //data packet + WritablePacket *p_data = Packet::make(4); + memcpy(p_data->data(), &tmp_counter, 4); + //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + //output_port = best_ap; + output(0).push(p_data); + +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(SimpleControllerSwitch) +ELEMENT_MT_SAFE(SimpleControllerSwitch) diff --git a/elements/ip/wgtt/simpleControllerSwitch.hh b/elements/ip/wgtt/simpleControllerSwitch.hh new file mode 100755 index 0000000000..3476440e83 --- /dev/null +++ b/elements/ip/wgtt/simpleControllerSwitch.hh @@ -0,0 +1,54 @@ +/* + Controller program, generate simple data and switch control + Input: trigger packet + Output: control & data + Created by Zhenyu Song: sunnyszy@gmail.com + */ +#ifndef CLICK_SIMPLECONTROLLERSWITCH_HH +#define CLICK_SIMPLECONTROLLERSWITCH_HH +#include +#include +#include +#include +#include +#include +#include +#include +CLICK_DECLS + +class SimpleControllerSwitch : public Element { public: + + + SimpleControllerSwitch() CLICK_COLD; + + const char *class_name() const { return "SimpleControllerSwitch"; } + const char *port_count() const { return "1/2"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void reset_ap(); + void push(int port, Packet *p_in); + + void push_status(Packet *p_in); + + private: + + unsigned char output_port; + unsigned char control_content[2]; + + // used for debug. + // By setting a positive number, manually switch after every ${interval} pkt + // Between ap 1 - 2 + int interval; + + click_ether * _ethh; + + +}; + + + + +CLICK_ENDDECLS +#endif From d78cad63579524a3b57086d87cd3403dd112c0d3 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 16:26:02 -0500 Subject: [PATCH 135/171] debug --- elements/ip/wgtt/simpleControllerSwitch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 85ac16da1e..05447534f4 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -75,7 +75,7 @@ void SimpleControllerSwitch::reset_ap() memcpy(p->data(), _ethh, sizeof(click_ether)); syslog (LOG_DEBUG, "Controller reset ap %X\n", i+1); - output(0).push(p); + output(1).push(p); } } From 701840c3e2b50145a5cfdb9effcbbc5d8e9c5850 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 16:57:08 -0500 Subject: [PATCH 136/171] add length to 1100 --- elements/ip/wgtt/simpleControllerSwitch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 05447534f4..366d9b0835 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -127,7 +127,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) } //data packet - WritablePacket *p_data = Packet::make(4); + WritablePacket *p_data = Packet::make(1100); memcpy(p_data->data(), &tmp_counter, 4); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; From 4db5662f742d4116be6f3ab0b12bafa191a9191c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 17:13:23 -0500 Subject: [PATCH 137/171] update counter to longlong --- elements/ip/wgtt/simpleControllerSwitch.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 366d9b0835..90ab705def 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -83,7 +83,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) { const unsigned char a = status_ap(p_in) - 1; unsigned char c = 0; - static unsigned int tmp_counter = 0; + static unsigned long long tmp_counter = 0; tmp_counter++; p_in -> kill(); @@ -128,7 +128,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) //data packet WritablePacket *p_data = Packet::make(1100); - memcpy(p_data->data(), &tmp_counter, 4); + memcpy(p_data->data(), &tmp_counter, 8); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; output(0).push(p_data); From 2a23ad37884a031fdee27708315882ad36e5010c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 20:05:24 -0500 Subject: [PATCH 138/171] send tcp pkt --- elements/ip/wgtt/simpleControllerSwitch.cc | 5 +++-- elements/ip/wgtt/simpleControllerSwitch.hh | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 90ab705def..0fffb3cc14 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -83,7 +83,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) { const unsigned char a = status_ap(p_in) - 1; unsigned char c = 0; - static unsigned long long tmp_counter = 0; + static uint32_t tmp_counter = 0; tmp_counter++; p_in -> kill(); @@ -128,7 +128,8 @@ void SimpleControllerSwitch::push_status(Packet *p_in) //data packet WritablePacket *p_data = Packet::make(1100); - memcpy(p_data->data(), &tmp_counter, 8); + _tcp.th_seq = tmp_counter; + memcpy(p_data->data(), &_tcp, sizeof(_tcp)); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; output(0).push(p_data); diff --git a/elements/ip/wgtt/simpleControllerSwitch.hh b/elements/ip/wgtt/simpleControllerSwitch.hh index 3476440e83..5761ab01e3 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.hh +++ b/elements/ip/wgtt/simpleControllerSwitch.hh @@ -12,6 +12,7 @@ #include #include #include +#include #include #include CLICK_DECLS @@ -43,6 +44,7 @@ class SimpleControllerSwitch : public Element { public: int interval; click_ether * _ethh; + click_tcp _tcp; }; From 889d80e01c5ea7c2acdc374d7487ffe6e8c03895 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 12 Jan 2017 20:40:44 -0500 Subject: [PATCH 139/171] debug: htol --- elements/ip/wgtt/simpleControllerSwitch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 0fffb3cc14..9b729277f6 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -128,7 +128,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) //data packet WritablePacket *p_data = Packet::make(1100); - _tcp.th_seq = tmp_counter; + _tcp.th_seq = htonl(tmp_counter); memcpy(p_data->data(), &_tcp, sizeof(_tcp)); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; From abe25df5fa784d509eba9b8d60ac0da7a8b05e23 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 13 Jan 2017 19:40:44 -0500 Subject: [PATCH 140/171] debug: increase packet len --- elements/ip/wgtt/simpleControllerSwitch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index 9b729277f6..c4721d2c5d 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -127,7 +127,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) } //data packet - WritablePacket *p_data = Packet::make(1100); + WritablePacket *p_data = Packet::make(1400); _tcp.th_seq = htonl(tmp_counter); memcpy(p_data->data(), &_tcp, sizeof(_tcp)); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); From fc9b91067d168d9b001c6d1a4d6f968be88c9c31 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 18 Jan 2017 21:54:07 -0500 Subject: [PATCH 141/171] switch min_t: 100 ms --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 62d50b4a71..7855c29485 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -59,7 +59,7 @@ struct my_test_struct { #define RING_SIZE 256 // unit ms -#define SWITCH_MIN 1000 +#define SWITCH_MIN 100 // content encapsulated in mac header #define RESET_CONTENT 0xff From a8c5e36ed8c4e8cbcfb931fb530a2f66024b038a Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 19 Jan 2017 21:11:36 -0500 Subject: [PATCH 142/171] switch: majority vote --- elements/ip/wgtt/packetselectionSerial.cc | 71 +++++++++++++++++------ elements/ip/wgtt/packetselectionSerial.hh | 9 ++- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index a8311075aa..1789f5586c 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -14,6 +14,18 @@ CLICK_DECLS +int comp (const void * elem1, const void * elem2) +{ + int f = *((int*)elem1); + int s = *((int*)elem2); + if (f > s) return 1; + if (f < s) return -1; + return 0; +} + + + + PacketSelectionSerial::PacketSelectionSerial() { int i,j,k; @@ -38,6 +50,9 @@ PacketSelectionSerial::PacketSelectionSerial() time_lock[i] = false; last_time[i] = 0; } + tmp_score = new int*[3]; + for(i=0;i<3;i++) + tmp_score[i] = new int[n_compare]; _ethh = new click_ether; _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); @@ -138,6 +153,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) case CLIENT4_MAC_SUFFIX: c = 3;break; } //since the score are minus, we minus again + //TODO: smaller is better? score[c][a][next_score_id[c][a]] = - status_score(p_in); next_score_id[c][a] = (next_score_id[c][a] + 1)%n_compare; // able to change state @@ -176,7 +192,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } } else - best_ap = find_best_ap_global(c); + best_ap = find_best_ap_neighbor(c); if(best_ap != output_port[c]) { @@ -220,10 +236,15 @@ void PacketSelectionSerial::push_status(Packet *p_in) unsigned char PacketSelectionSerial::find_best_ap_neighbor(unsigned char c) { unsigned char ¤t = output_port[c]; - - // unsigned char potential = (current+1)%2; bool switch_to_left = true, switch_to_right = true; - int j; + int i,j; + int num_bigger; + // copy to tmp: current, sort + for(i=0; i=score[c][current][j]) + if(tmp_score[0][j] < tmp_score[1][j]) { - switch_to_left = false; - break; + num_bigger ++; } + if(num_bigger < MAJOR) + switch_to_left = false; } if(switch_to_right) { + //copy to tmp: right, sort + for(i=0; i=score[c][current][j]) + if(tmp_score[2][j] < tmp_score[1][j]) { - switch_to_right = false; - break; + num_bigger ++; } + if(num_bigger < MAJOR) + switch_to_right = false; } if(switch_to_left && switch_to_right) { - int sum_left = 0, sum_right = 0; + num_bigger = 0; for(j=0; j #include #include +#include +#include CLICK_DECLS +int comp (const void *, const void *); + class PacketSelectionSerial : public Element { public: @@ -26,7 +30,8 @@ class PacketSelectionSerial : public Element { public: const char *flags() const { return "A"; } int configure(Vector &, ErrorHandler *) CLICK_COLD; - + + void reset_ap(); void push(int port, Packet *p_in); void push_control(Packet *p_in); @@ -39,8 +44,10 @@ class PacketSelectionSerial : public Element { public: unsigned char state[MAX_N_CLIENT]; static const unsigned char n_compare = 5; + static const unsigned char MAJOR = 3; // [client, ap, n_compare] int ***score; + int **tmp_score; //every time just need 3 ap * n_compare // [client, ap] unsigned char ** next_score_id; unsigned char output_port[MAX_N_CLIENT]; From f0626929358bb087f54f50bae70459904242efef Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 19 Jan 2017 21:15:24 -0500 Subject: [PATCH 143/171] debug: remove print --- elements/ip/wgtt/packetselectionSerial.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 1789f5586c..38a7eb4667 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -243,8 +243,8 @@ unsigned char PacketSelectionSerial::find_best_ap_neighbor(unsigned char c) for(i=0; i Date: Thu, 19 Jan 2017 21:22:28 -0500 Subject: [PATCH 144/171] debug: faster, more sensitive switch --- elements/ip/wgtt/packetselectionSerial.cc | 6 +++--- include/clicknet/wgtt.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 38a7eb4667..91be5e0048 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -261,7 +261,7 @@ unsigned char PacketSelectionSerial::find_best_ap_neighbor(unsigned char c) num_bigger = 0; for(j=0; j Date: Thu, 19 Jan 2017 21:37:18 -0500 Subject: [PATCH 145/171] debug: still global is preferred --- elements/ip/wgtt/packetselectionSerial.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 91be5e0048..4af5c0b476 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -192,7 +192,7 @@ void PacketSelectionSerial::push_status(Packet *p_in) } } else - best_ap = find_best_ap_neighbor(c); + best_ap = find_best_ap_global(c); if(best_ap != output_port[c]) { From 9985147fa17db5175a3f5d755b91c5af90d74a89 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 20 Jan 2017 20:07:53 -0500 Subject: [PATCH 146/171] median switch --- elements/ip/wgtt/packetselectionSerial.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 4af5c0b476..cc18397099 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -51,7 +51,7 @@ PacketSelectionSerial::PacketSelectionSerial() last_time[i] = 0; } tmp_score = new int*[3]; - for(i=0;i<3;i++) + for(i=0;i Date: Fri, 20 Jan 2017 20:52:27 -0500 Subject: [PATCH 147/171] Debug --- doc/testie.1 | 347 ++++++++++++---------- elements/ip/wgtt/packetselectionSerial.cc | 2 +- 2 files changed, 187 insertions(+), 162 deletions(-) diff --git a/doc/testie.1 b/doc/testie.1 index d368d591fa..99dd5f0af1 100644 --- a/doc/testie.1 +++ b/doc/testie.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== @@ -38,6 +38,8 @@ . ds PI \(*p . ds L" `` . ds R" '' +. ds C` +. ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. @@ -48,17 +50,24 @@ .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.ie \nF \{\ -. de IX -. tm Index:\\$1\t\\n%\t"\\$2" +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX .. -. nr % 0 -. rr F -.\} -.el \{\ -. de IX +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" .. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} .\} +.rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -124,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TESTIE 1" -.TH TESTIE 1 "2013-06-19" "perl v5.14.2" "" +.TH TESTIE 1 "2017-01-18" "perl v5.18.2" "" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,214 +142,230 @@ testie \- simple test harness .SH "SYNOPSIS" .IX Header "SYNOPSIS" -.Vb 1 -\& testie [OPTIONS] [FILE]... -.Ve +testie [\s-1OPTIONS\s0] [\s-1FILE\s0]... .SH "DESCRIPTION" .IX Header "DESCRIPTION" -Testie is a simple test harness. Each testie test file incorporates a shell -script to be run and, optionally, input and expected output files for that -script. Testie runs the script; the test fails if any of the script -commands fail, or if the script generates unexpected output. +Testie is a simple test harness. A testie test comprises a shell +script and, optionally, input and expected output files for that +script. Testie runs the script; the test succeeds if all of the script +commands succeed, and the actual output files match expectations. .PP -To run testie, pass it one or more test filenames. It will print useful -error messages for failed tests. Alternatively, give it directory names; -the directories are recursively searched for '\fI*.testie\fR' files. +Testie accepts test filenames and directories as arguments. +Directories are recursively searched for \fI*.testie\fR files. It +reports problems for failed tests, plus a summary. .PP -Return status is 0 if all tests succeed, 1 if any test fails, and 2 if a -test fails due to an internal error. Tests whose \f(CW%require\fR prerequisites -fail do not affect the return status, except that if all tests' -prerequisites fail, the return status is 1 instead of 0. +Testie exits with status 0 if all tests succeed, 1 if any test fails, +and 2 if a test fails due to an internal error. Tests whose \fB\f(CB%require\fB\fR +prerequisites fail do not affect the exit status, except that if all +tests' prerequisites fail, the return status is 1 instead of 0. .SH "OPTIONS" .IX Header "OPTIONS" +.IP "\fB\-j\fR\fIN\fR, \fB\-\-jobs\fR=\fIN\fR" 8 +.IX Item "-jN, --jobs=N" +Run up to \fIN\fR tests simultaneously. Like Make's \fB\-j\fR option. .IP "\fI\s-1VARIABLE\s0\fR=\fI\s-1VALUE\s0\fR" 8 .IX Item "VARIABLE=VALUE" Provide an environment variable setting for \fI\s-1VARIABLE\s0\fR within the script. -.IP "\-V, \-\-verbose" 8 +.IP "\fB\-s\fR, \fB\-\-show\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-s, --show FILE" +Echo the contents of \fI\s-1FILE\s0\fR on completion. \fI\s-1FILE\s0\fR should be one of the +filenames specified by \fB\f(CB%file\fB\fR or \fB\f(CB%expect\fB\fR, or \fBstdout\fR or \fBstderr\fR. +Leaves out any ignored lines. +.IP "\fB\-S\fR, \fB\-\-show\-raw\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-S, --show-raw FILE" +Like \fB\-\-show\fR, but includes any ignored lines. +.IP "\fB\-\-show\-all\fR" 8 +.IX Item "--show-all" +Calls \fB\-\-show\fR for all filenames specified by any \fB\f(CB%expect\fB\fR, plus \fBstdout\fR +and \fBstderr\fR. Leaves out any ignored lines. +.IP "\fB\-\-show\-all\-raw\fR" 8 +.IX Item "--show-all-raw" +Like \fB\-\-show\-all\fR, but includes any ignored lines. +.IP "\fB\-e\fR, \fB\-\-expand\fR" 8 +.IX Item "-e, --expand" +Don't run the given test; instead, expand its files into the current +directory. The script is stored in a file called \fI\f(CI%script\fI\fR. +.IP "\fB\-\-preserve\-temporaries\fR" 8 +.IX Item "--preserve-temporaries" +Preserve temporary test directories. Testie runs each test in its own +subdirectory of the current directory. Test directories are named +\&\fItestieNNNNN\fR, and are typically removed on test completion. +Examining the contents of a test directory can be useful when +debugging a test. +.IP "\fB\-p\fR, \fB\-\-path\fR \fI\s-1DIR\s0\fR" 8 +.IX Item "-p, --path DIR" +Prepend \fI\s-1DIR\s0\fR to the \f(CW\*(C`PATH\*(C'\fR environment variable before running the +test script. +.IP "\fB\-V\fR, \fB\-\-verbose\fR" 8 .IX Item "-V, --verbose" Print information to standard error about successful tests as well as unsuccessful tests. -.IP "\-VV, \-\-superverbose" 8 +.IP "\fB\-VV\fR, \fB\-\-superverbose\fR" 8 .IX Item "-VV, --superverbose" -Like \-\-verbose, but use a slightly different format, and additionally print -every test's \f(CW%info\fR section before the test results. -.IP "\-q, \-\-quiet" 8 +Like \fB\-\-verbose\fR, but use a slightly different format, and +additionally print every test's \fB\f(CB%info\fB\fR section before the test results. +.IP "\fB\-q\fR, \fB\-\-quiet\fR" 8 .IX Item "-q, --quiet" Don't print information to the terminal while running multiple tests. -.IP "\-v, \-\-version" 8 +.IP "\fB\-v\fR, \fB\-\-version\fR" 8 .IX Item "-v, --version" Print version number information and exit. -.IP "\-\-help" 8 +.IP "\fB\-\-help\fR" 8 .IX Item "--help" Print help information and exit. -.IP "\-\-preserve\-temporaries" 8 -.IX Item "--preserve-temporaries" -Preserve the temporary directory created for the test. -.IP "\-s, \-\-show \s-1FILE\s0" 8 -.IX Item "-s, --show FILE" -Echo the contents of \s-1FILE\s0 on completion. \s-1FILE\s0 should be one of the -filenames specified by \f(CW%file\fR or \f(CW%expect\fR*, or 'stdout' or 'stderr'. -Leaves out any ignored lines. -.IP "\-S, \-\-show\-raw \s-1FILE\s0" 8 -.IX Item "-S, --show-raw FILE" -Like \-\-show, but includes any ignored lines. -.IP "\-\-show\-all" 8 -.IX Item "--show-all" -Like '\-\-show' for all filenames specified by any \f(CW%expect\fR*, plus 'stdout' -and 'stderr'. Leaves out any ignored lines. -.IP "\-\-show\-all\-raw" 8 -.IX Item "--show-all-raw" -Like '\-\-show\-raw' for all filenames specified by any \f(CW%expect\fR*, -plus 'stdout' and 'stderr'. Includes any ignored lines. -.IP "\-e, \-\-expand" 8 -.IX Item "-e, --expand" -Don't run the given test; instead, expand its files into the current -directory. The script is stored in a file called '+script+'. -.IP "\-j\fIN\fR, \-\-jobs=\fIN\fR" 8 -.IX Item "-jN, --jobs=N" -Run up to \fIN\fR tests simultaneously. Like Make's '\-j' option. .SH "FILE FORMAT" .IX Header "FILE FORMAT" Testie test files consist of several sections, each introduced by a line -starting with %. There must be, at least, a \f(CW%script\fR section. -.PP -The \f(CW%file\fR and \f(CW%expect\fR* sections define input and/or output files by -name. Testie runs its script in a private directory in \fI/tmp\fR; any files -mentioned in \f(CW%file\fR or \f(CW%expect\fR* are placed in that directory. -.ie n .IP "%script" 8 -.el .IP "\f(CW%script\fR" 8 +starting with \fB%\fR. There must be, at least, a \fB\f(CB%script\fB\fR section. +The \fB\f(CB%file\fB\fR and \fB\f(CB%expect\fB\fR sections define input and output files by +name. +.ie n .IP "\fB\fB%script\fB\fR" 8 +.el .IP "\fB\f(CB%script\fB\fR" 8 .IX Item "%script" -The shell script (in sh syntax) that controls the test. Testie will run -each command in sequence. Every command in the script must succeed, with -exit status 0, or the test will fail. Use \f(CW%file\fR sections to define script -input files and \f(CW%expect\fR* sections to check script output files for expected -values. +The \fBsh\fR shell script that controls the test. Testie will run each +command in sequence. Every command in the script must succeed, with +exit status 0, or the test will fail. Use \fB\f(CB%file\fB\fR sections to define +script input files and \fB\f(CB%expect\fB\fR sections to check script output files +for expected values. +.Sp +The \fB\f(CB%script\fB\fR section can contain subtests. To start a new subtest, +execute a command like \f(CW\*(C`testie_subtest\ SECTIONNAME\*(C'\fR. Testie will +report the problematic \f(CW\*(C`SECTIONNAME\*(C'\fR when standard output or error +doesn't match an expected value. .Sp -The \f(CW%script\fR section can contain multiple subtests. To start a new subtest, -execute a command like \*(L"testie_subtest \s-1SECTIONNAME\s0\*(R". Testie will report the -offending \s-1SECTIONNAME\s0 when standard output or error doesn't match an -expected value. -.ie n .IP "%require [\-q]" 8 -.el .IP "\f(CW%require\fR [\-q]" 8 +The script's environment is populated with any \fI\s-1VARIABLE\s0\fRs set on the +testie command line with \fB\f(BI\s-1VARIABLE\s0\fB=\f(BI\s-1VALUE\s0\fB\fR syntax. Also, the +\&\fB\f(CB$rundir\fB\fR environment variable is set to the directory in which +testie was originally run. +.ie n .IP "\fB\fB%require\fB [\-q]\fR" 8 +.el .IP "\fB\f(CB%require\fB [\-q]\fR" 8 .IX Item "%require [-q]" -A shell script (in sh syntax) defining prerequisites that must be satisfied +An \fBsh\fR shell script defining prerequisites that must be satisfied before the test can run. Every command in the script must succeed, with exit status 0, for the test to run. Standard output and error are not -checked, however. The \f(CW\*(C`\-q\*(C'\fR flag tells testie not to print an error message +checked, however. The \fB\-q\fR flag tells testie not to print an error message if a requirement fails. .Sp Testie runs the requirement script before creating any other test files. -For example, contents of \f(CW%file\fR sections are not available. -.ie n .IP "%info" 8 -.el .IP "\f(CW%info\fR" 8 +For example, contents of \fB\f(CB%file\fB\fR sections are not available. +.ie n .IP "\fB\fB%info\fB\fR" 8 +.el .IP "\fB\f(CB%info\fB\fR" 8 .IX Item "%info" -A short description of the test. In \-\-superverbose mode, the first +A short description of the test. In \fB\-\-superverbose\fR mode, the first paragraph of its contents is printed before the test results. -.ie n .IP "%cut" 8 -.el .IP "\f(CW%cut\fR" 8 +.ie n .IP "\fB\fB%cut\fB\fR" 8 +.el .IP "\fB\f(CB%cut\fB\fR" 8 .IX Item "%cut" This section is ignored. It is intended to comment out obsolete parts of the test. -.ie n .IP "%file [\-d] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%file\fR [\-d] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%file [-d] [+LENGTH] FILENAME..." -Create an input file for the script. \s-1FILENAME\s0 can be 'stdin', which sets -the script's standard input. If \s-1LENGTH\s0 is provided, the file data consists -of the \s-1LENGTH\s0 bytes following this line. Otherwise, it consists of the data -up to the next section. The \f(CW\*(C`\-d\*(C'\fR flag tells testie to delete the -first character of each line in the section; this makes it possible to -include files that have lines that start with %. -.ie n .IP "%expectv [\-ad] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expectv\fR [\-ad] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%expectv [-ad] [+LENGTH] FILENAME..." -An expected output file for the script. \s-1FILENAME\s0 can be 'stdout', for -standard output. If \s-1LENGTH\s0 is provided, the file data consists of the -\&\s-1LENGTH\s0 bytes following this line; otherwise, it consists of the data up to -the next section. +.ie n .IP "\fB\fB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%file [-de] [+LENGTH] FILENAME..." +Create an input file for the script. \fI\s-1FILENAME\s0\fR can be \fBstdin\fR, +which sets the script's standard input. If \fB+\fR\fI\s-1LENGTH\s0\fR is provided, +the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this line; +otherwise, it consists of the data up to the next section. The \fB\-d\fR +flag tells testie to delete the first character of each line in the +section. The \fB\-e\fR flag indicates that the section was \s-1MIME\s0 +Base64\-encoded (see \fIbase64\fR\|(1)); it is decoded before use. To +include a file with lines that start with \fB%\fR (which would normally +start a new section), use \fB\-d\fR and preface each line of the file with +a space, or use \fB\-e\fR. +.ie n .IP "\fB\fB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expect [-adeiw] [+LENGTH] FILENAME..." +Define an expected output file. Differences between the script's +output \fI\s-1FILENAME\s0\fR and the contents of the \fB\f(CB%expect\fB\fR section will +cause the test to fail. .Sp -Testie will run the script, then compare the script's output file with the -provided data. They must match exactly or the test fails. +\&\fI\s-1FILENAME\s0\fR can be \fBstdout\fR, for standard output. If \fB+\fR\fI\s-1LENGTH\s0\fR is +provided, the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this +line; otherwise, it consists of the data up to the next section. .Sp -The \f(CW\*(C`\-a\*(C'\fR flag marks this expected output as an alternate. Testie will -compare the script's output file with each provided alternate; the test -succeeds if any of the alternates match. The \f(CW\*(C`\-d\*(C'\fR flag behaves as in -\&\f(CW%file\fR. -.ie n .IP "%expect [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expect\fR [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%expect [-adiw] [+LENGTH] FILENAME..." -An expected output file for the script. Arguments are as for \f(CW%expectv\fR. +After running the script, testie compares the \fI\s-1FILENAME\s0\fR generated by +the script with the provided data. The files are compared +line-by-line. Testie ignores blank lines, differences in trailing +whitespace, and lines in the script output that match \fB\f(CB%ignore\fB\fR +patterns (see below). The \fB\-w\fR flag causes testie to ignore +differences in amount of whitespace within each line. .Sp -Testie will run the script, then compare the file generated by script -with the provided data. The files are compared line-by-line. Testie -ignores blank lines and trailing whitespace on each line. It also -ignores lines in the script output that match \f(CW%ignore\fR patterns (see below). -\&\f(CW%expect\fR lines can contain Perl regular expressions, enclosed by two -sets of braces; so the \f(CW%expect\fR line +\&\fB\f(CB%expect\fB\fR lines can contain Perl regular expressions, enclosed by two +sets of braces. The \fB\f(CB%expect\fB\fR line .Sp .Vb 1 \& foo{{(bar)?}} .Ve .Sp -matches either 'foo' or 'foobar'. +matches either \f(CW\*(C`foo\*(C'\fR or \f(CW\*(C`foobar\*(C'\fR. The \fB\-i\fR flag makes all such +regular expressions case-insensitive. (Text outside of regular +expressions must match case.) .Sp -Document an \f(CW%expect\fR line with \*(L"{{?comment}}\*(R" blocks. For example: +Document an \fB\f(CB%expect\fB\fR line with \f(CW\*(C`{{?comment}}\*(C'\fR blocks. For example: .Sp .Vb 1 \& foo {{? the sort was in the right order}} .Ve .Sp -Testie ignores whitespace before and after the \*(L"{{?comment}}\*(R" block, and if +Testie ignores whitespace before and after the \f(CW\*(C`{{?comment}}\*(C'\fR block, and if the actual output differs from this expected line, it prints the comment in addition to the line differences. .Sp -The \f(CW\*(C`\-a\*(C'\fR and \f(CW\*(C`\-d\*(C'\fR flags may also be used for \f(CW%expect\fR sections. Also, the -\&\f(CW\*(C`\-i\*(C'\fR flag makes any regular expressions case-insensitive (text outside of -regular expressions must match case), and the \f(CW\*(C`\-w\*(C'\fR flag ignores any -differences in amount of whitespace within a line. -.ie n .IP "%expectx [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expectx\fR [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 +The \fB\-a\fR flag marks this expected output as an alternate. Testie will +compare the script's output file with each provided alternate; the +test succeeds if any of the alternates match. The \fB\-d\fR flag behaves +as in \fB\f(CB%file\fB\fR. +.ie n .IP "\fB\fB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expectv [-ade] [+LENGTH] FILENAME..." +Define a literal expected output file. This behaves like \fB\f(CB%expect\fB\fR, +except that the script's output file must match the provided data +\&\fIexactly\fR: \fB\f(CB%expectv\fB\fR never ignores whitespace differences, does not +treat \f(CW\*(C`{{}}\*(C'\fR blocks as regular expressions, and does not parse +\&\fB\f(CB%ignore\fB\fR patterns. +.ie n .IP "\fB\fB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 .IX Item "%expectx [-adiw] [+LENGTH] FILENAME..." -\&\f(CW%expectx\fR is just like \f(CW%expect\fR, except that every line is treated as a -regular expression. The input is parsed for \*(L"{{?comment}}\*(R" blocks, but -other brace pairs are treated according to the normal regular expression -rules. -.ie n .IP "%stdin [+LENGTH]" 8 -.el .IP "\f(CW%stdin\fR [+LENGTH]" 8 -.IX Item "%stdin [+LENGTH]" -Same as '%file stdin [\s-1ARGS\s0]'. -.ie n .IP "%stdout [\-adiw] [+LENGTH]" 8 -.el .IP "\f(CW%stdout\fR [\-adiw] [+LENGTH]" 8 -.IX Item "%stdout [-adiw] [+LENGTH]" -Same as '%expect stdout'. -.ie n .IP "%stderr [\-adiw] [+LENGTH]" 8 -.el .IP "\f(CW%stderr\fR [\-adiw] [+LENGTH]" 8 -.IX Item "%stderr [-adiw] [+LENGTH]" -Same as '%expect stderr'. -.ie n .IP "%ignorex [\-di] [+LENGTH] [\s-1FILENAME\s0]" 8 -.el .IP "\f(CW%ignorex\fR [\-di] [+LENGTH] [\s-1FILENAME\s0]" 8 +Define a regular-expression expected output file. This behaves like +\&\fB\f(CB%expect\fB\fR, except that every line is treated as a regular expression. +\&\f(CW\*(C`{{?comment}}\*(C'\fR blocks are ignored, but other brace pairs are treated +according to the normal regular expression rules. +.ie n .IP "\fB\fB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdin [-de] [+LENGTH]" +Same as \fB\f(CB%file\fB stdin\fR. +.ie n .IP "\fB\fB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdout [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stdout\fR. +.ie n .IP "\fB\fB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stderr [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stderr\fR. +.ie n .IP "\fB\fB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 .IX Item "%ignorex [-di] [+LENGTH] [FILENAME]" -Each line in the \f(CW%ignorex\fR section is a Perl regular expression. Lines in -the supplied \s-1FILENAME\s0 that match any of those regular expressions will not -be considered when comparing files with \f(CW%expect\fR data. The regular -expression must match the whole line. \s-1FILENAME\s0 may be 'all', in which case -the regular expressions will apply to all \f(CW%expect\fR files. \*(L"{{?comment}}\*(R" +Each line in the \fB\f(CB%ignorex\fB\fR section is a Perl regular expression. Lines in +the supplied \fI\s-1FILENAME\s0\fR that match any of those regular expressions will not +be considered when comparing files with \fB\f(CB%expect\fB\fR data. The regular +expression must match the whole line. \fI\s-1FILENAME\s0\fR may be \fBall\fR, in which case +the regular expressions will apply to all \fB\f(CB%expect\fB\fR files. \f(CW\*(C`{{?comment}}\*(C'\fR blocks are ignored. -.ie n .IP "%ignore, %ignorev" 8 -.el .IP "\f(CW%ignore\fR, \f(CW%ignorev\fR" 8 -.IX Item "%ignore, %ignorev" -Like '%ignorex', but '%ignore' parses regular expressions only inside -double braces (\*(L"{{ }}\*(R"), and '%ignorev' lines must match exactly. -.ie n .IP "%include \s-1FILENAME\s0" 8 -.el .IP "\f(CW%include\fR \s-1FILENAME\s0" 8 +.ie n .IP "\fB\fB%ignore\fB\fR, \fB\fB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignore\fB\fR, \fB\f(CB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.IX Item "%ignore, %ignorev [-adeiw] [+LENGTH] [FILENAME]" +Like \fB\f(CB%ignorex\fB\fR, but \fB\f(CB%ignore\fB\fR parses regular expressions only inside +double braces (\f(CW\*(C`{{ }}\*(C'\fR), and \fB\f(CB%ignorev\fB\fR lines must match exactly. +.ie n .IP "\fB\fB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 +.el .IP "\fB\f(CB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 .IX Item "%include FILENAME" Interpolate the contents of another testie file. -.ie n .IP "%eot" 8 -.el .IP "\f(CW%eot\fR" 8 +.ie n .IP "\fB\fB%eot\fB\fR" 8 +.el .IP "\fB\f(CB%eot\fB\fR" 8 .IX Item "%eot" -Marks the end of the current test. The rest of the file will be parsed for +Marks the end of the current test. The rest of the file will be parsed for additional tests. -.ie n .IP "%eof" 8 -.el .IP "\f(CW%eof\fR" 8 +.ie n .IP "\fB\fB%eof\fB\fR" 8 +.el .IP "\fB\f(CB%eof\fB\fR" 8 .IX Item "%eof" The rest of the file is ignored. .SH "EXAMPLE" @@ -360,8 +385,8 @@ file. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" By default, testie sets the \f(CW\*(C`LC_ALL\*(C'\fR environment variable to \*(L"C\*(R"; without -this setting commands like 'sort' have unpredictable effects. To set -\&\f(CW\*(C`LC_ALL\*(C'\fR to another value, set it in the \f(CW%script\fR section. +this setting commands like \fBsort\fR have unpredictable effects. To set +\&\f(CW\*(C`LC_ALL\*(C'\fR to another value, set it in the \fB\f(CB%script\fB\fR section. .SH "AUTHOR" .IX Header "AUTHOR" Eddie Kohler, diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index cc18397099..80fb03df6e 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -50,7 +50,7 @@ PacketSelectionSerial::PacketSelectionSerial() time_lock[i] = false; last_time[i] = 0; } - tmp_score = new int*[3]; + tmp_score = new int*[MAX_N_AP]; for(i=0;i Date: Fri, 20 Jan 2017 21:00:45 -0500 Subject: [PATCH 148/171] debug --- doc/testie.1 | 347 +++++++++++---------- elements/ip/80211r/rclientcontrol.cc | 1 + elements/ip/wgtt/simpleControllerSwitch.cc | 2 +- fake.sh | 7 + 4 files changed, 195 insertions(+), 162 deletions(-) create mode 100755 fake.sh diff --git a/doc/testie.1 b/doc/testie.1 index d368d591fa..6973732395 100644 --- a/doc/testie.1 +++ b/doc/testie.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== @@ -38,6 +38,8 @@ . ds PI \(*p . ds L" `` . ds R" '' +. ds C` +. ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. @@ -48,17 +50,24 @@ .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.ie \nF \{\ -. de IX -. tm Index:\\$1\t\\n%\t"\\$2" +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX .. -. nr % 0 -. rr F -.\} -.el \{\ -. de IX +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" .. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} .\} +.rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -124,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TESTIE 1" -.TH TESTIE 1 "2013-06-19" "perl v5.14.2" "" +.TH TESTIE 1 "2016-12-31" "perl v5.18.2" "" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,214 +142,230 @@ testie \- simple test harness .SH "SYNOPSIS" .IX Header "SYNOPSIS" -.Vb 1 -\& testie [OPTIONS] [FILE]... -.Ve +testie [\s-1OPTIONS\s0] [\s-1FILE\s0]... .SH "DESCRIPTION" .IX Header "DESCRIPTION" -Testie is a simple test harness. Each testie test file incorporates a shell -script to be run and, optionally, input and expected output files for that -script. Testie runs the script; the test fails if any of the script -commands fail, or if the script generates unexpected output. +Testie is a simple test harness. A testie test comprises a shell +script and, optionally, input and expected output files for that +script. Testie runs the script; the test succeeds if all of the script +commands succeed, and the actual output files match expectations. .PP -To run testie, pass it one or more test filenames. It will print useful -error messages for failed tests. Alternatively, give it directory names; -the directories are recursively searched for '\fI*.testie\fR' files. +Testie accepts test filenames and directories as arguments. +Directories are recursively searched for \fI*.testie\fR files. It +reports problems for failed tests, plus a summary. .PP -Return status is 0 if all tests succeed, 1 if any test fails, and 2 if a -test fails due to an internal error. Tests whose \f(CW%require\fR prerequisites -fail do not affect the return status, except that if all tests' -prerequisites fail, the return status is 1 instead of 0. +Testie exits with status 0 if all tests succeed, 1 if any test fails, +and 2 if a test fails due to an internal error. Tests whose \fB\f(CB%require\fB\fR +prerequisites fail do not affect the exit status, except that if all +tests' prerequisites fail, the return status is 1 instead of 0. .SH "OPTIONS" .IX Header "OPTIONS" +.IP "\fB\-j\fR\fIN\fR, \fB\-\-jobs\fR=\fIN\fR" 8 +.IX Item "-jN, --jobs=N" +Run up to \fIN\fR tests simultaneously. Like Make's \fB\-j\fR option. .IP "\fI\s-1VARIABLE\s0\fR=\fI\s-1VALUE\s0\fR" 8 .IX Item "VARIABLE=VALUE" Provide an environment variable setting for \fI\s-1VARIABLE\s0\fR within the script. -.IP "\-V, \-\-verbose" 8 +.IP "\fB\-s\fR, \fB\-\-show\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-s, --show FILE" +Echo the contents of \fI\s-1FILE\s0\fR on completion. \fI\s-1FILE\s0\fR should be one of the +filenames specified by \fB\f(CB%file\fB\fR or \fB\f(CB%expect\fB\fR, or \fBstdout\fR or \fBstderr\fR. +Leaves out any ignored lines. +.IP "\fB\-S\fR, \fB\-\-show\-raw\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-S, --show-raw FILE" +Like \fB\-\-show\fR, but includes any ignored lines. +.IP "\fB\-\-show\-all\fR" 8 +.IX Item "--show-all" +Calls \fB\-\-show\fR for all filenames specified by any \fB\f(CB%expect\fB\fR, plus \fBstdout\fR +and \fBstderr\fR. Leaves out any ignored lines. +.IP "\fB\-\-show\-all\-raw\fR" 8 +.IX Item "--show-all-raw" +Like \fB\-\-show\-all\fR, but includes any ignored lines. +.IP "\fB\-e\fR, \fB\-\-expand\fR" 8 +.IX Item "-e, --expand" +Don't run the given test; instead, expand its files into the current +directory. The script is stored in a file called \fI\f(CI%script\fI\fR. +.IP "\fB\-\-preserve\-temporaries\fR" 8 +.IX Item "--preserve-temporaries" +Preserve temporary test directories. Testie runs each test in its own +subdirectory of the current directory. Test directories are named +\&\fItestieNNNNN\fR, and are typically removed on test completion. +Examining the contents of a test directory can be useful when +debugging a test. +.IP "\fB\-p\fR, \fB\-\-path\fR \fI\s-1DIR\s0\fR" 8 +.IX Item "-p, --path DIR" +Prepend \fI\s-1DIR\s0\fR to the \f(CW\*(C`PATH\*(C'\fR environment variable before running the +test script. +.IP "\fB\-V\fR, \fB\-\-verbose\fR" 8 .IX Item "-V, --verbose" Print information to standard error about successful tests as well as unsuccessful tests. -.IP "\-VV, \-\-superverbose" 8 +.IP "\fB\-VV\fR, \fB\-\-superverbose\fR" 8 .IX Item "-VV, --superverbose" -Like \-\-verbose, but use a slightly different format, and additionally print -every test's \f(CW%info\fR section before the test results. -.IP "\-q, \-\-quiet" 8 +Like \fB\-\-verbose\fR, but use a slightly different format, and +additionally print every test's \fB\f(CB%info\fB\fR section before the test results. +.IP "\fB\-q\fR, \fB\-\-quiet\fR" 8 .IX Item "-q, --quiet" Don't print information to the terminal while running multiple tests. -.IP "\-v, \-\-version" 8 +.IP "\fB\-v\fR, \fB\-\-version\fR" 8 .IX Item "-v, --version" Print version number information and exit. -.IP "\-\-help" 8 +.IP "\fB\-\-help\fR" 8 .IX Item "--help" Print help information and exit. -.IP "\-\-preserve\-temporaries" 8 -.IX Item "--preserve-temporaries" -Preserve the temporary directory created for the test. -.IP "\-s, \-\-show \s-1FILE\s0" 8 -.IX Item "-s, --show FILE" -Echo the contents of \s-1FILE\s0 on completion. \s-1FILE\s0 should be one of the -filenames specified by \f(CW%file\fR or \f(CW%expect\fR*, or 'stdout' or 'stderr'. -Leaves out any ignored lines. -.IP "\-S, \-\-show\-raw \s-1FILE\s0" 8 -.IX Item "-S, --show-raw FILE" -Like \-\-show, but includes any ignored lines. -.IP "\-\-show\-all" 8 -.IX Item "--show-all" -Like '\-\-show' for all filenames specified by any \f(CW%expect\fR*, plus 'stdout' -and 'stderr'. Leaves out any ignored lines. -.IP "\-\-show\-all\-raw" 8 -.IX Item "--show-all-raw" -Like '\-\-show\-raw' for all filenames specified by any \f(CW%expect\fR*, -plus 'stdout' and 'stderr'. Includes any ignored lines. -.IP "\-e, \-\-expand" 8 -.IX Item "-e, --expand" -Don't run the given test; instead, expand its files into the current -directory. The script is stored in a file called '+script+'. -.IP "\-j\fIN\fR, \-\-jobs=\fIN\fR" 8 -.IX Item "-jN, --jobs=N" -Run up to \fIN\fR tests simultaneously. Like Make's '\-j' option. .SH "FILE FORMAT" .IX Header "FILE FORMAT" Testie test files consist of several sections, each introduced by a line -starting with %. There must be, at least, a \f(CW%script\fR section. -.PP -The \f(CW%file\fR and \f(CW%expect\fR* sections define input and/or output files by -name. Testie runs its script in a private directory in \fI/tmp\fR; any files -mentioned in \f(CW%file\fR or \f(CW%expect\fR* are placed in that directory. -.ie n .IP "%script" 8 -.el .IP "\f(CW%script\fR" 8 +starting with \fB%\fR. There must be, at least, a \fB\f(CB%script\fB\fR section. +The \fB\f(CB%file\fB\fR and \fB\f(CB%expect\fB\fR sections define input and output files by +name. +.ie n .IP "\fB\fB%script\fB\fR" 8 +.el .IP "\fB\f(CB%script\fB\fR" 8 .IX Item "%script" -The shell script (in sh syntax) that controls the test. Testie will run -each command in sequence. Every command in the script must succeed, with -exit status 0, or the test will fail. Use \f(CW%file\fR sections to define script -input files and \f(CW%expect\fR* sections to check script output files for expected -values. +The \fBsh\fR shell script that controls the test. Testie will run each +command in sequence. Every command in the script must succeed, with +exit status 0, or the test will fail. Use \fB\f(CB%file\fB\fR sections to define +script input files and \fB\f(CB%expect\fB\fR sections to check script output files +for expected values. +.Sp +The \fB\f(CB%script\fB\fR section can contain subtests. To start a new subtest, +execute a command like \f(CW\*(C`testie_subtest\ SECTIONNAME\*(C'\fR. Testie will +report the problematic \f(CW\*(C`SECTIONNAME\*(C'\fR when standard output or error +doesn't match an expected value. .Sp -The \f(CW%script\fR section can contain multiple subtests. To start a new subtest, -execute a command like \*(L"testie_subtest \s-1SECTIONNAME\s0\*(R". Testie will report the -offending \s-1SECTIONNAME\s0 when standard output or error doesn't match an -expected value. -.ie n .IP "%require [\-q]" 8 -.el .IP "\f(CW%require\fR [\-q]" 8 +The script's environment is populated with any \fI\s-1VARIABLE\s0\fRs set on the +testie command line with \fB\f(BI\s-1VARIABLE\s0\fB=\f(BI\s-1VALUE\s0\fB\fR syntax. Also, the +\&\fB\f(CB$rundir\fB\fR environment variable is set to the directory in which +testie was originally run. +.ie n .IP "\fB\fB%require\fB [\-q]\fR" 8 +.el .IP "\fB\f(CB%require\fB [\-q]\fR" 8 .IX Item "%require [-q]" -A shell script (in sh syntax) defining prerequisites that must be satisfied +An \fBsh\fR shell script defining prerequisites that must be satisfied before the test can run. Every command in the script must succeed, with exit status 0, for the test to run. Standard output and error are not -checked, however. The \f(CW\*(C`\-q\*(C'\fR flag tells testie not to print an error message +checked, however. The \fB\-q\fR flag tells testie not to print an error message if a requirement fails. .Sp Testie runs the requirement script before creating any other test files. -For example, contents of \f(CW%file\fR sections are not available. -.ie n .IP "%info" 8 -.el .IP "\f(CW%info\fR" 8 +For example, contents of \fB\f(CB%file\fB\fR sections are not available. +.ie n .IP "\fB\fB%info\fB\fR" 8 +.el .IP "\fB\f(CB%info\fB\fR" 8 .IX Item "%info" -A short description of the test. In \-\-superverbose mode, the first +A short description of the test. In \fB\-\-superverbose\fR mode, the first paragraph of its contents is printed before the test results. -.ie n .IP "%cut" 8 -.el .IP "\f(CW%cut\fR" 8 +.ie n .IP "\fB\fB%cut\fB\fR" 8 +.el .IP "\fB\f(CB%cut\fB\fR" 8 .IX Item "%cut" This section is ignored. It is intended to comment out obsolete parts of the test. -.ie n .IP "%file [\-d] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%file\fR [\-d] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%file [-d] [+LENGTH] FILENAME..." -Create an input file for the script. \s-1FILENAME\s0 can be 'stdin', which sets -the script's standard input. If \s-1LENGTH\s0 is provided, the file data consists -of the \s-1LENGTH\s0 bytes following this line. Otherwise, it consists of the data -up to the next section. The \f(CW\*(C`\-d\*(C'\fR flag tells testie to delete the -first character of each line in the section; this makes it possible to -include files that have lines that start with %. -.ie n .IP "%expectv [\-ad] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expectv\fR [\-ad] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%expectv [-ad] [+LENGTH] FILENAME..." -An expected output file for the script. \s-1FILENAME\s0 can be 'stdout', for -standard output. If \s-1LENGTH\s0 is provided, the file data consists of the -\&\s-1LENGTH\s0 bytes following this line; otherwise, it consists of the data up to -the next section. +.ie n .IP "\fB\fB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%file [-de] [+LENGTH] FILENAME..." +Create an input file for the script. \fI\s-1FILENAME\s0\fR can be \fBstdin\fR, +which sets the script's standard input. If \fB+\fR\fI\s-1LENGTH\s0\fR is provided, +the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this line; +otherwise, it consists of the data up to the next section. The \fB\-d\fR +flag tells testie to delete the first character of each line in the +section. The \fB\-e\fR flag indicates that the section was \s-1MIME\s0 +Base64\-encoded (see \fIbase64\fR\|(1)); it is decoded before use. To +include a file with lines that start with \fB%\fR (which would normally +start a new section), use \fB\-d\fR and preface each line of the file with +a space, or use \fB\-e\fR. +.ie n .IP "\fB\fB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expect [-adeiw] [+LENGTH] FILENAME..." +Define an expected output file. Differences between the script's +output \fI\s-1FILENAME\s0\fR and the contents of the \fB\f(CB%expect\fB\fR section will +cause the test to fail. .Sp -Testie will run the script, then compare the script's output file with the -provided data. They must match exactly or the test fails. +\&\fI\s-1FILENAME\s0\fR can be \fBstdout\fR, for standard output. If \fB+\fR\fI\s-1LENGTH\s0\fR is +provided, the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this +line; otherwise, it consists of the data up to the next section. .Sp -The \f(CW\*(C`\-a\*(C'\fR flag marks this expected output as an alternate. Testie will -compare the script's output file with each provided alternate; the test -succeeds if any of the alternates match. The \f(CW\*(C`\-d\*(C'\fR flag behaves as in -\&\f(CW%file\fR. -.ie n .IP "%expect [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expect\fR [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.IX Item "%expect [-adiw] [+LENGTH] FILENAME..." -An expected output file for the script. Arguments are as for \f(CW%expectv\fR. +After running the script, testie compares the \fI\s-1FILENAME\s0\fR generated by +the script with the provided data. The files are compared +line-by-line. Testie ignores blank lines, differences in trailing +whitespace, and lines in the script output that match \fB\f(CB%ignore\fB\fR +patterns (see below). The \fB\-w\fR flag causes testie to ignore +differences in amount of whitespace within each line. .Sp -Testie will run the script, then compare the file generated by script -with the provided data. The files are compared line-by-line. Testie -ignores blank lines and trailing whitespace on each line. It also -ignores lines in the script output that match \f(CW%ignore\fR patterns (see below). -\&\f(CW%expect\fR lines can contain Perl regular expressions, enclosed by two -sets of braces; so the \f(CW%expect\fR line +\&\fB\f(CB%expect\fB\fR lines can contain Perl regular expressions, enclosed by two +sets of braces. The \fB\f(CB%expect\fB\fR line .Sp .Vb 1 \& foo{{(bar)?}} .Ve .Sp -matches either 'foo' or 'foobar'. +matches either \f(CW\*(C`foo\*(C'\fR or \f(CW\*(C`foobar\*(C'\fR. The \fB\-i\fR flag makes all such +regular expressions case-insensitive. (Text outside of regular +expressions must match case.) .Sp -Document an \f(CW%expect\fR line with \*(L"{{?comment}}\*(R" blocks. For example: +Document an \fB\f(CB%expect\fB\fR line with \f(CW\*(C`{{?comment}}\*(C'\fR blocks. For example: .Sp .Vb 1 \& foo {{? the sort was in the right order}} .Ve .Sp -Testie ignores whitespace before and after the \*(L"{{?comment}}\*(R" block, and if +Testie ignores whitespace before and after the \f(CW\*(C`{{?comment}}\*(C'\fR block, and if the actual output differs from this expected line, it prints the comment in addition to the line differences. .Sp -The \f(CW\*(C`\-a\*(C'\fR and \f(CW\*(C`\-d\*(C'\fR flags may also be used for \f(CW%expect\fR sections. Also, the -\&\f(CW\*(C`\-i\*(C'\fR flag makes any regular expressions case-insensitive (text outside of -regular expressions must match case), and the \f(CW\*(C`\-w\*(C'\fR flag ignores any -differences in amount of whitespace within a line. -.ie n .IP "%expectx [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 -.el .IP "\f(CW%expectx\fR [\-adiw] [+LENGTH] \s-1FILENAME\s0..." 8 +The \fB\-a\fR flag marks this expected output as an alternate. Testie will +compare the script's output file with each provided alternate; the +test succeeds if any of the alternates match. The \fB\-d\fR flag behaves +as in \fB\f(CB%file\fB\fR. +.ie n .IP "\fB\fB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expectv [-ade] [+LENGTH] FILENAME..." +Define a literal expected output file. This behaves like \fB\f(CB%expect\fB\fR, +except that the script's output file must match the provided data +\&\fIexactly\fR: \fB\f(CB%expectv\fB\fR never ignores whitespace differences, does not +treat \f(CW\*(C`{{}}\*(C'\fR blocks as regular expressions, and does not parse +\&\fB\f(CB%ignore\fB\fR patterns. +.ie n .IP "\fB\fB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 .IX Item "%expectx [-adiw] [+LENGTH] FILENAME..." -\&\f(CW%expectx\fR is just like \f(CW%expect\fR, except that every line is treated as a -regular expression. The input is parsed for \*(L"{{?comment}}\*(R" blocks, but -other brace pairs are treated according to the normal regular expression -rules. -.ie n .IP "%stdin [+LENGTH]" 8 -.el .IP "\f(CW%stdin\fR [+LENGTH]" 8 -.IX Item "%stdin [+LENGTH]" -Same as '%file stdin [\s-1ARGS\s0]'. -.ie n .IP "%stdout [\-adiw] [+LENGTH]" 8 -.el .IP "\f(CW%stdout\fR [\-adiw] [+LENGTH]" 8 -.IX Item "%stdout [-adiw] [+LENGTH]" -Same as '%expect stdout'. -.ie n .IP "%stderr [\-adiw] [+LENGTH]" 8 -.el .IP "\f(CW%stderr\fR [\-adiw] [+LENGTH]" 8 -.IX Item "%stderr [-adiw] [+LENGTH]" -Same as '%expect stderr'. -.ie n .IP "%ignorex [\-di] [+LENGTH] [\s-1FILENAME\s0]" 8 -.el .IP "\f(CW%ignorex\fR [\-di] [+LENGTH] [\s-1FILENAME\s0]" 8 +Define a regular-expression expected output file. This behaves like +\&\fB\f(CB%expect\fB\fR, except that every line is treated as a regular expression. +\&\f(CW\*(C`{{?comment}}\*(C'\fR blocks are ignored, but other brace pairs are treated +according to the normal regular expression rules. +.ie n .IP "\fB\fB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdin [-de] [+LENGTH]" +Same as \fB\f(CB%file\fB stdin\fR. +.ie n .IP "\fB\fB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdout [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stdout\fR. +.ie n .IP "\fB\fB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stderr [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stderr\fR. +.ie n .IP "\fB\fB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 .IX Item "%ignorex [-di] [+LENGTH] [FILENAME]" -Each line in the \f(CW%ignorex\fR section is a Perl regular expression. Lines in -the supplied \s-1FILENAME\s0 that match any of those regular expressions will not -be considered when comparing files with \f(CW%expect\fR data. The regular -expression must match the whole line. \s-1FILENAME\s0 may be 'all', in which case -the regular expressions will apply to all \f(CW%expect\fR files. \*(L"{{?comment}}\*(R" +Each line in the \fB\f(CB%ignorex\fB\fR section is a Perl regular expression. Lines in +the supplied \fI\s-1FILENAME\s0\fR that match any of those regular expressions will not +be considered when comparing files with \fB\f(CB%expect\fB\fR data. The regular +expression must match the whole line. \fI\s-1FILENAME\s0\fR may be \fBall\fR, in which case +the regular expressions will apply to all \fB\f(CB%expect\fB\fR files. \f(CW\*(C`{{?comment}}\*(C'\fR blocks are ignored. -.ie n .IP "%ignore, %ignorev" 8 -.el .IP "\f(CW%ignore\fR, \f(CW%ignorev\fR" 8 -.IX Item "%ignore, %ignorev" -Like '%ignorex', but '%ignore' parses regular expressions only inside -double braces (\*(L"{{ }}\*(R"), and '%ignorev' lines must match exactly. -.ie n .IP "%include \s-1FILENAME\s0" 8 -.el .IP "\f(CW%include\fR \s-1FILENAME\s0" 8 +.ie n .IP "\fB\fB%ignore\fB\fR, \fB\fB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignore\fB\fR, \fB\f(CB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.IX Item "%ignore, %ignorev [-adeiw] [+LENGTH] [FILENAME]" +Like \fB\f(CB%ignorex\fB\fR, but \fB\f(CB%ignore\fB\fR parses regular expressions only inside +double braces (\f(CW\*(C`{{ }}\*(C'\fR), and \fB\f(CB%ignorev\fB\fR lines must match exactly. +.ie n .IP "\fB\fB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 +.el .IP "\fB\f(CB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 .IX Item "%include FILENAME" Interpolate the contents of another testie file. -.ie n .IP "%eot" 8 -.el .IP "\f(CW%eot\fR" 8 +.ie n .IP "\fB\fB%eot\fB\fR" 8 +.el .IP "\fB\f(CB%eot\fB\fR" 8 .IX Item "%eot" -Marks the end of the current test. The rest of the file will be parsed for +Marks the end of the current test. The rest of the file will be parsed for additional tests. -.ie n .IP "%eof" 8 -.el .IP "\f(CW%eof\fR" 8 +.ie n .IP "\fB\fB%eof\fB\fR" 8 +.el .IP "\fB\f(CB%eof\fB\fR" 8 .IX Item "%eof" The rest of the file is ignored. .SH "EXAMPLE" @@ -360,8 +385,8 @@ file. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" By default, testie sets the \f(CW\*(C`LC_ALL\*(C'\fR environment variable to \*(L"C\*(R"; without -this setting commands like 'sort' have unpredictable effects. To set -\&\f(CW\*(C`LC_ALL\*(C'\fR to another value, set it in the \f(CW%script\fR section. +this setting commands like \fBsort\fR have unpredictable effects. To set +\&\f(CW\*(C`LC_ALL\*(C'\fR to another value, set it in the \fB\f(CB%script\fB\fR section. .SH "AUTHOR" .IX Header "AUTHOR" Eddie Kohler, diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index fb1ae6354b..24eaf20b23 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -140,6 +140,7 @@ void RClientControl::push_80211(Packet*p_in) rssi[ap] = rssi_this; else return; + printf("ap:%u, rssi:%d\n", ap, rssi_this); //if not update, return if(rssi[current_ap]==-127) diff --git a/elements/ip/wgtt/simpleControllerSwitch.cc b/elements/ip/wgtt/simpleControllerSwitch.cc index c4721d2c5d..f701ad6fe8 100755 --- a/elements/ip/wgtt/simpleControllerSwitch.cc +++ b/elements/ip/wgtt/simpleControllerSwitch.cc @@ -127,7 +127,7 @@ void SimpleControllerSwitch::push_status(Packet *p_in) } //data packet - WritablePacket *p_data = Packet::make(1400); + WritablePacket *p_data = Packet::make(100); _tcp.th_seq = htonl(tmp_counter); memcpy(p_data->data(), &_tcp, sizeof(_tcp)); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); diff --git a/fake.sh b/fake.sh new file mode 100755 index 0000000000..541f69c5be --- /dev/null +++ b/fake.sh @@ -0,0 +1,7 @@ +#!/bin/bash +#sudo ifconfig fake0 down +#sudo ifconfig fake0 172.17.2.135 +sudo route add default gw 172.17.2.68 fake0 +sudo ifconfig fake0 hw ether 44:c3:06:31:5b:07 +#sudo ifconfig fake0 hw ether 00:11:22:33:44:55 +sudo ifconfig fake0 up From 3b94df29830f4f1dbc8b23df3e9e815cfb91285c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 20 Jan 2017 21:17:21 -0500 Subject: [PATCH 149/171] threshold + alpha + lock --- elements/ip/80211r/rclientcontrol.cc | 18 +++++++++++------- elements/ip/80211r/rclientcontrol.hh | 5 ++++- include/clicknet/wgtt.h | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 24eaf20b23..259448f405 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -17,6 +17,7 @@ int RClientControl::configure(Vector &conf, ErrorHandler *errh) { int i, tmp_start[4],tmp_id; + char tmp_rssi_threshold; openlog("RClientControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); for(i=0;i &conf, ErrorHandler *errh) .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) .read_p("INTERVAL", IntArg(), interval) .read_p("PRINTINTERVAL", IntArg(), print_interval) + .read_p("RSSITHRESHOLD", IntArg(), tmp_rssi_threshold) + .read_p("ALPHA", DoubleArg(), alpha) .complete() < 0) return -1; + rssi_threshold = tmp_rssi_threshold; identity = tmp_id; current_ap = tmp_start[identity-1] - 1; @@ -137,13 +141,13 @@ void RClientControl::push_80211(Packet*p_in) } if(c == identity) - rssi[ap] = rssi_this; + rssi[ap] = (1-alpha)*rssi[ap] + alpha*rssi_this; else return; - printf("ap:%u, rssi:%d\n", ap, rssi_this); + // printf("ap:%u, rssi:%d\n", ap, rssi_this); //if not update, return - if(rssi[current_ap]==-127) + if(rssi[current_ap] < -80) return; // if IDLE, considering switching static unsigned int tmp_counter = 0; @@ -156,7 +160,7 @@ void RClientControl::push_80211(Packet*p_in) gettimeofday(&tv, NULL); double now_time = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; - if(now_time - last_time > SWITCH_MIN) + if(now_time - last_time > K_SWITCH_MIN) time_lock = false; @@ -176,10 +180,10 @@ void RClientControl::push_80211(Packet*p_in) } else { - if(rssi[current_ap] >= -68) + if(rssi[current_ap] >= rssi_threshold) return; - char max_rssi = -127; + double max_rssi = -127; // find max rssi for(i=0;i max_rssi) @@ -190,7 +194,7 @@ void RClientControl::push_80211(Packet*p_in) } if(max_id == current_ap) return; - syslog (LOG_DEBUG, "Considering to switch, current rssi: %d\n", rssi[current_ap]); + syslog (LOG_DEBUG, "Considering to switch, current rssi: %f\n", rssi[current_ap]); control_content[0] = 0x04; control_content[1] = identity-1; control_content[2] = current_ap; diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index 82e56d5117..a63418115d 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -31,7 +31,10 @@ class RClientControl : public Element { public: void push_updata(Packet *); private: - char rssi[MAX_N_AP]; + double rssi[MAX_N_AP]; + char rssi_threshold; + double alpha; + unsigned char identity; unsigned char state; unsigned char current_ap; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 122bc751dc..30dd4c74cd 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -60,6 +60,7 @@ struct my_test_struct { #define RING_SIZE 256 // unit ms #define SWITCH_MIN 60 +#define K_SWITCH_MIN 1000 // content encapsulated in mac header #define RESET_CONTENT 0xff From 12081d9fb6a962616a7db5ffd02e86e690765240 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 22 Jan 2017 10:43:18 -0500 Subject: [PATCH 150/171] add reset for 80211k --- elements/ip/80211r/rapcontrol.cc | 43 ++++++++++++++++++++++-- elements/ip/80211r/rapcontrol.hh | 1 + elements/ip/80211r/rclientcontrol.cc | 28 +++++++++++++++ elements/ip/80211r/rclientcontrol.hh | 1 + elements/ip/80211r/rcontrollercontrol.cc | 27 ++++++++++++++- elements/ip/80211r/rcontrollercontrol.hh | 1 + 6 files changed, 98 insertions(+), 3 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 030ac3e0a5..05f0faa0c0 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -16,7 +16,7 @@ int RAPControl::configure(Vector &conf, ErrorHandler *errh) { - int i, tmp_start[4],tmp_id; + int i,tmp_id; openlog("RAPControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); @@ -93,7 +93,7 @@ RAPControl::push(int port, Packet *p_in) void RAPControl::push_up_control(Packet*p_in) { - + int i; const unsigned char & t = r_control_type(p_in); const unsigned char & c = r_control_client(p_in); const unsigned char & ori = r_control_ori(p_in); @@ -127,6 +127,28 @@ void RAPControl::push_up_control(Packet*p_in) syslog (LOG_DEBUG, "ap %d pass reas for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(0).push(p); + } + else if(t == 0xff) + { + + for(i=0;idata(), &control_content, 4); + + syslog (LOG_DEBUG, "ap %d pass reset\n", identity); + output(0).push(p); + + } p_in -> kill(); @@ -134,6 +156,7 @@ void RAPControl::push_up_control(Packet*p_in) void RAPControl::push_down_control(Packet*p_in) { + int i; const unsigned char & t = r_control_type(p_in); const unsigned char & c = r_control_client(p_in); const unsigned char & ori = r_control_ori(p_in); @@ -186,6 +209,22 @@ void RAPControl::push_down_control(Packet*p_in) syslog (LOG_DEBUG, "ap %d pass reas ack for client %d, ap_ori %d, ap_tar %d\n", identity, c+1, ori+1, tar+1); output(2).push(p); } + else if(t == 0xff) + { + + for(i=0;i kill(); } diff --git a/elements/ip/80211r/rapcontrol.hh b/elements/ip/80211r/rapcontrol.hh index 79bd2b8499..ab6d6f837e 100755 --- a/elements/ip/80211r/rapcontrol.hh +++ b/elements/ip/80211r/rapcontrol.hh @@ -37,6 +37,7 @@ class RAPControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; + int tmp_start[4]; diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 259448f405..dc7f96e8d4 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -57,9 +57,37 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) return 0; } +void RClientControl::reset() +{ + WritablePacket *p = Packet::make(sizeof(click_ether)+4); + // // data part + + control_content[0] = 0xff; + control_content[1] = 0xff; + control_content[2] = 0xff; + control_content[3] = 0xff; + + memcpy(p->data()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_DEBUG, "client issue reset\n"); + output(0).push(p); + +} + void RClientControl::push(int port, Packet *p_in) { + + // here is a small bug, I can not put the reset function in the initial function + static unsigned char lock = 0; + if(!lock) + { + lock++; + reset(); + } + switch(port) { case 0: push_updata(p_in);break; diff --git a/elements/ip/80211r/rclientcontrol.hh b/elements/ip/80211r/rclientcontrol.hh index a63418115d..c40ead6184 100755 --- a/elements/ip/80211r/rclientcontrol.hh +++ b/elements/ip/80211r/rclientcontrol.hh @@ -29,6 +29,7 @@ class RClientControl : public Element { public: void push_80211(Packet *); void push_downdata(Packet *); void push_updata(Packet *); + void reset(); private: double rssi[MAX_N_AP]; diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index e4ef6bbd82..c1f074ae8c 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -16,7 +16,7 @@ int RControlerControl::configure(Vector &conf, ErrorHandler *errh) { - int i, tmp_start[4]; + int i; openlog("RControlerControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _ethh = new click_ether[MAX_N_AP*2]; if (Args(conf, this, errh) @@ -85,6 +85,7 @@ RControlerControl::push(int port, Packet *p_in) void RControlerControl::push_up_control(Packet*p_in) { + int i; const unsigned char & t = r_control_type(p_in); const unsigned char & c = r_control_client(p_in); const unsigned char & ori = r_control_ori(p_in); @@ -139,6 +140,30 @@ void RControlerControl::push_up_control(Packet*p_in) syslog (LOG_DEBUG, "controller ack reas for client %d, ap_ori %d, ap_tar %d\n", c+1, ori+1, tar+1); output(0).push(p); } + else if(t == 0xff) + { + + for(i=0;idata()+sizeof(click_ether), &control_content, 4); + + memcpy(p->data(), &(_ethh[i]), sizeof(click_ether)); + + syslog (LOG_DEBUG, "controller reset and broadcast reset\n"); + output(0).push(p); + } + + } p_in -> kill(); } diff --git a/elements/ip/80211r/rcontrollercontrol.hh b/elements/ip/80211r/rcontrollercontrol.hh index f70e230f6a..7fa950f36f 100755 --- a/elements/ip/80211r/rcontrollercontrol.hh +++ b/elements/ip/80211r/rcontrollercontrol.hh @@ -32,6 +32,7 @@ class RControlerControl : public Element { public: unsigned char outport[MAX_N_CLIENT]; unsigned char control_content[4]; click_ether * _ethh; + int tmp_start[4]; From d17b5b559e65bb7c157162bcb327a1899cab4135 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 22 Jan 2017 21:10:06 -0500 Subject: [PATCH 151/171] one tplink --- elements/ip/80211r/rssibecon.cc | 38 +++++++++++++++++-------------- elements/ip/80211r/rssibecon.hh | 7 +++--- elements/ip/wgtt/statuscollect.cc | 26 ++++++++++----------- elements/ip/wgtt/statuscollect.hh | 7 +++--- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index 12a69f9c68..d73a8c6b28 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -13,7 +13,7 @@ CLICK_DECLS RSSIBecon::RSSIBecon() { -#ifdef __arm__ +#ifdef __mips__ openlog("RSSIBecon", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); syslog (LOG_DEBUG, "finish init\n"); #endif @@ -22,7 +22,7 @@ RSSIBecon::RSSIBecon() RSSIBecon::~RSSIBecon() { -#ifdef __arm__ +#ifdef __mips__ iwinfo_finish(); #endif } @@ -36,13 +36,9 @@ RSSIBecon::configure(Vector &conf, ErrorHandler *errh) .complete() < 0) return -1; -#ifdef __arm__ - if(wlan_port == 0) - strcpy(ifname, "wlan0"); - else if(wlan_port == 1) - strcpy(ifname, "wlan1"); - else - syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); +#ifdef __mips__ + strcpy(ifname, "wlan0"); + iw = iwinfo_backend(ifname); if (!iw) syslog (LOG_DEBUG, "can not connect to backend iwinfo\n"); @@ -54,21 +50,24 @@ RSSIBecon::configure(Vector &conf, ErrorHandler *errh) void RSSIBecon::fragment(Packet *p_in) { -#ifdef __arm__ +#ifdef __mips__ int i,j; - - if(!(iw->assoclist(ifname, buf, &len))) + syslog (LOG_DEBUG, "in fragment\n"); + if(!(iw->assoclist("wlan0", buf, &len))) // // syslog (LOG_DEBUG, "can not find associlist\n"); // else if (len <= 0) // // syslog (LOG_DEBUG, "associ number < 0\n"); // else if (len) { + syslog (LOG_DEBUG, "prepare to send, len: %d\n", len); // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + if(len>0) { //one pkt per client WritablePacket *p_csi = Packet::make(11); + syslog (LOG_DEBUG, "creating pkt\n"); j=0; e = (struct iwinfo_assoclist_entry *) &buf[i]; uint8_t & mac = e->mac[5]; @@ -76,7 +75,7 @@ RSSIBecon::fragment(Packet *p_in) int8_t & noise = e->noise; uint32_t & rx_rate = (e->rx_rate).rate; uint32_t & tx_rate = (e->tx_rate).rate; - + syslog (LOG_DEBUG, "parsing\n"); memcpy(p_csi->data()+j, &(mac), 1); j += 1; memcpy(p_csi->data()+j, &(signal), 1); @@ -87,10 +86,14 @@ RSSIBecon::fragment(Packet *p_in) j += 4; memcpy(p_csi->data()+j, &(tx_rate), 4); j += 4; + syslog (LOG_DEBUG, "copying\n"); output(0).push(p_csi); } - } + // else + // syslog (LOG_DEBUG, "can not find associlist\n"); + // if (len <= 0) + // syslog (LOG_DEBUG, "associ number < 0\n"); #endif p_in -> kill(); } @@ -98,8 +101,9 @@ RSSIBecon::fragment(Packet *p_in) void RSSIBecon::push(int, Packet *p) { -#ifdef __arm__ - // syslog (LOG_DEBUG, "in push\n"); + // syslog (LOG_DEBUG, "enter push\n"); +#ifdef __mips__ + syslog (LOG_DEBUG, "in push\n"); fragment(p); #endif } diff --git a/elements/ip/80211r/rssibecon.hh b/elements/ip/80211r/rssibecon.hh index e1b586c7db..10051f307b 100644 --- a/elements/ip/80211r/rssibecon.hh +++ b/elements/ip/80211r/rssibecon.hh @@ -11,7 +11,8 @@ #include #include #include -#ifdef __arm__ +// #include +#ifdef __mips__ #include extern "C" { @@ -21,6 +22,7 @@ extern "C" CLICK_DECLS +char ifname[10]; class RSSIBecon : public Element { public: @@ -39,11 +41,10 @@ class RSSIBecon : public Element { public: private: -#ifdef __arm__ +#ifdef __mips__ int len; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; - char ifname[6]; struct iwinfo_assoclist_entry *e; #endif diff --git a/elements/ip/wgtt/statuscollect.cc b/elements/ip/wgtt/statuscollect.cc index 51305b1ed8..a4212e9aad 100755 --- a/elements/ip/wgtt/statuscollect.cc +++ b/elements/ip/wgtt/statuscollect.cc @@ -15,7 +15,7 @@ CLICK_DECLS StatusCollect::StatusCollect() { -#ifdef __arm__ +#ifdef __mips__ openlog("APControl_StatusCollect", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); syslog (LOG_DEBUG, "finish init\n"); // total_msg_cnt = 0; @@ -26,7 +26,7 @@ StatusCollect::StatusCollect() StatusCollect::~StatusCollect() { -#ifdef __arm__ +#ifdef __mips__ iwinfo_finish(); #endif } @@ -34,22 +34,19 @@ StatusCollect::~StatusCollect() int StatusCollect::configure(Vector &conf, ErrorHandler *errh) { + syslog (LOG_DEBUG, "in configure\n"); int wlan_port; if (Args(conf, this, errh) .read_p("SAMPLERATE", IntArg(), sample_rate) .read_p("WLANPORT", IntArg(), wlan_port) .complete() < 0) return -1; - -#ifdef __arm__ - if(wlan_port == 0) - strcpy(ifname, "wlan0"); - else if(wlan_port == 1) - strcpy(ifname, "wlan1"); - else - syslog (LOG_DEBUG, "Invalid wlan_port argument\n"); - iw = iwinfo_backend(ifname); - if (!iw) + syslog (LOG_DEBUG, "finish parsing arguments\n"); +#ifdef __mips__ + strcpy(ifname, "wlan0"); + syslog (LOG_DEBUG, "finish copying\n"); + // iw = iwinfo_backend(ifname); + // if (!iw) syslog (LOG_DEBUG, "Can not connect to backend iwinfo\n"); #endif syslog (LOG_DEBUG, "Finish configure, ready to start\n"); @@ -59,7 +56,7 @@ StatusCollect::configure(Vector &conf, ErrorHandler *errh) void StatusCollect::fragment(Packet *p_in) { -#ifdef __arm__ +#ifdef __mips__ int i,j; sample_counter ++; if(sample_counter>sample_rate) @@ -72,6 +69,7 @@ StatusCollect::fragment(Packet *p_in) // // syslog (LOG_DEBUG, "StatusCollect: associ number < 0\n"); // else if (len) { + syslog (LOG_DEBUG, "Len: %d\n", len); // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) @@ -109,7 +107,7 @@ StatusCollect::fragment(Packet *p_in) void StatusCollect::push(int, Packet *p) { -#ifdef __arm__ +#ifdef __mips__ // syslog (LOG_DEBUG, "StatusCollect: in push\n"); fragment(p); #endif diff --git a/elements/ip/wgtt/statuscollect.hh b/elements/ip/wgtt/statuscollect.hh index 7ec0990fcc..d2a5083d4e 100755 --- a/elements/ip/wgtt/statuscollect.hh +++ b/elements/ip/wgtt/statuscollect.hh @@ -13,7 +13,8 @@ #include #include #include -#ifdef __arm__ +// #include +#ifdef __mips__ #include extern "C" { @@ -21,6 +22,7 @@ extern "C" } #endif +char ifname[10]; CLICK_DECLS @@ -43,11 +45,10 @@ class StatusCollect : public Element { public: int sample_rate; int sample_counter; -#ifdef __arm__ +#ifdef __mips__ int len; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; - char ifname[6]; struct iwinfo_assoclist_entry *e; #endif From 8f28ed9a89f1cc5d8b03dd0d137b30e28c2e6151 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 22 Jan 2017 21:32:40 -0500 Subject: [PATCH 152/171] debug --- elements/ip/80211r/rssibecon.hh | 2 +- elements/ip/wgtt/csicollect.hh | 1 - elements/ip/wgtt/statuscollect.hh | 2 +- include/clicknet/wgtt.h | 2 ++ 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/elements/ip/80211r/rssibecon.hh b/elements/ip/80211r/rssibecon.hh index 10051f307b..a61ea3c42a 100644 --- a/elements/ip/80211r/rssibecon.hh +++ b/elements/ip/80211r/rssibecon.hh @@ -22,7 +22,7 @@ extern "C" CLICK_DECLS -char ifname[10]; + class RSSIBecon : public Element { public: diff --git a/elements/ip/wgtt/csicollect.hh b/elements/ip/wgtt/csicollect.hh index 4f0717a5dd..fa954f3d2f 100755 --- a/elements/ip/wgtt/csicollect.hh +++ b/elements/ip/wgtt/csicollect.hh @@ -47,7 +47,6 @@ class CSICollect : public Element { public: int len; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; - char ifname[6]; struct iwinfo_assoclist_entry *e; #endif diff --git a/elements/ip/wgtt/statuscollect.hh b/elements/ip/wgtt/statuscollect.hh index d2a5083d4e..af872c2a0c 100755 --- a/elements/ip/wgtt/statuscollect.hh +++ b/elements/ip/wgtt/statuscollect.hh @@ -22,7 +22,7 @@ extern "C" } #endif -char ifname[10]; + CLICK_DECLS diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 30dd4c74cd..1c90b5a6d6 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -95,4 +95,6 @@ struct my_test_struct { #define r_dst_mac_suffix(p) *(p->data()+5) #define r_ether_type_suffix(p) *(p->data()+13) +char ifname[20]; + #endif \ No newline at end of file From 32cce892607d84c260f6da3f1e68213b715591c8 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 22 Jan 2017 22:52:32 -0500 Subject: [PATCH 153/171] debug --- elements/ip/80211r/rssibecon.cc | 14 +++++++------- elements/ip/80211r/rssibecon.hh | 1 + elements/ip/wgtt/csicollect.hh | 1 + elements/ip/wgtt/statuscollect.cc | 10 +++++----- elements/ip/wgtt/statuscollect.hh | 1 + include/clicknet/wgtt.h | 1 - 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index d73a8c6b28..15ff863441 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -52,14 +52,14 @@ RSSIBecon::fragment(Packet *p_in) { #ifdef __mips__ int i,j; - syslog (LOG_DEBUG, "in fragment\n"); - if(!(iw->assoclist("wlan0", buf, &len))) + // syslog (LOG_DEBUG, "in fragment\n"); + if(!(iw->assoclist(ifname, buf, &len))) // // syslog (LOG_DEBUG, "can not find associlist\n"); // else if (len <= 0) // // syslog (LOG_DEBUG, "associ number < 0\n"); // else if (len) { - syslog (LOG_DEBUG, "prepare to send, len: %d\n", len); + // syslog (LOG_DEBUG, "prepare to send, len: %d\n", len); // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) @@ -67,7 +67,7 @@ RSSIBecon::fragment(Packet *p_in) { //one pkt per client WritablePacket *p_csi = Packet::make(11); - syslog (LOG_DEBUG, "creating pkt\n"); + // syslog (LOG_DEBUG, "creating pkt\n"); j=0; e = (struct iwinfo_assoclist_entry *) &buf[i]; uint8_t & mac = e->mac[5]; @@ -75,7 +75,7 @@ RSSIBecon::fragment(Packet *p_in) int8_t & noise = e->noise; uint32_t & rx_rate = (e->rx_rate).rate; uint32_t & tx_rate = (e->tx_rate).rate; - syslog (LOG_DEBUG, "parsing\n"); + // syslog (LOG_DEBUG, "parsing\n"); memcpy(p_csi->data()+j, &(mac), 1); j += 1; memcpy(p_csi->data()+j, &(signal), 1); @@ -86,7 +86,7 @@ RSSIBecon::fragment(Packet *p_in) j += 4; memcpy(p_csi->data()+j, &(tx_rate), 4); j += 4; - syslog (LOG_DEBUG, "copying\n"); + // syslog (LOG_DEBUG, "copying\n"); output(0).push(p_csi); } } @@ -103,7 +103,7 @@ RSSIBecon::push(int, Packet *p) { // syslog (LOG_DEBUG, "enter push\n"); #ifdef __mips__ - syslog (LOG_DEBUG, "in push\n"); + // syslog (LOG_DEBUG, "in push\n"); fragment(p); #endif } diff --git a/elements/ip/80211r/rssibecon.hh b/elements/ip/80211r/rssibecon.hh index a61ea3c42a..0bebae1705 100644 --- a/elements/ip/80211r/rssibecon.hh +++ b/elements/ip/80211r/rssibecon.hh @@ -43,6 +43,7 @@ class RSSIBecon : public Element { public: #ifdef __mips__ int len; + char ifname[20]; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; struct iwinfo_assoclist_entry *e; diff --git a/elements/ip/wgtt/csicollect.hh b/elements/ip/wgtt/csicollect.hh index fa954f3d2f..6ed56dde8c 100755 --- a/elements/ip/wgtt/csicollect.hh +++ b/elements/ip/wgtt/csicollect.hh @@ -45,6 +45,7 @@ class CSICollect : public Element { public: #ifdef __mips__ int len; + char ifname[20]; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; struct iwinfo_assoclist_entry *e; diff --git a/elements/ip/wgtt/statuscollect.cc b/elements/ip/wgtt/statuscollect.cc index a4212e9aad..f37e4a81e5 100755 --- a/elements/ip/wgtt/statuscollect.cc +++ b/elements/ip/wgtt/statuscollect.cc @@ -41,12 +41,12 @@ StatusCollect::configure(Vector &conf, ErrorHandler *errh) .read_p("WLANPORT", IntArg(), wlan_port) .complete() < 0) return -1; - syslog (LOG_DEBUG, "finish parsing arguments\n"); + // syslog (LOG_DEBUG, "finish parsing arguments\n"); #ifdef __mips__ strcpy(ifname, "wlan0"); - syslog (LOG_DEBUG, "finish copying\n"); - // iw = iwinfo_backend(ifname); - // if (!iw) + // syslog (LOG_DEBUG, "finish copying\n"); + iw = iwinfo_backend(ifname); + if (!iw) syslog (LOG_DEBUG, "Can not connect to backend iwinfo\n"); #endif syslog (LOG_DEBUG, "Finish configure, ready to start\n"); @@ -69,7 +69,7 @@ StatusCollect::fragment(Packet *p_in) // // syslog (LOG_DEBUG, "StatusCollect: associ number < 0\n"); // else if (len) { - syslog (LOG_DEBUG, "Len: %d\n", len); + // syslog (LOG_DEBUG, "Len: %d\n", len); // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) diff --git a/elements/ip/wgtt/statuscollect.hh b/elements/ip/wgtt/statuscollect.hh index af872c2a0c..e3bcf5af2a 100755 --- a/elements/ip/wgtt/statuscollect.hh +++ b/elements/ip/wgtt/statuscollect.hh @@ -47,6 +47,7 @@ class StatusCollect : public Element { public: #ifdef __mips__ int len; + char ifname[20]; const struct iwinfo_ops *iw; char buf[IWINFO_BUFSIZE]; struct iwinfo_assoclist_entry *e; diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 1c90b5a6d6..e2b7e43fa4 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -95,6 +95,5 @@ struct my_test_struct { #define r_dst_mac_suffix(p) *(p->data()+5) #define r_ether_type_suffix(p) *(p->data()+13) -char ifname[20]; #endif \ No newline at end of file From 89d1a49787f7dd81e54e0b46bc96604010c754fc Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 23 Jan 2017 22:05:11 -0500 Subject: [PATCH 154/171] debug: init not switch --- elements/ip/80211r/rclientcontrol.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index dc7f96e8d4..7967d6add6 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -39,6 +39,7 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) identity = tmp_id; current_ap = tmp_start[identity-1] - 1; + rssi[current_ap] = -60; //in case that fast switching at beginning state = IDLE; From a40524715a78434a8daab22a49b33d4593cd2971 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 26 Jan 2017 00:25:49 -0500 Subject: [PATCH 155/171] support for multi client --- elements/ip/80211r/rapcontrol.cc | 5 ++--- elements/ip/80211r/rapcontrol.hh | 2 +- elements/ip/80211r/rclientcontrol.cc | 6 +++--- elements/ip/80211r/rcontrollercontrol.cc | 1 - elements/ip/80211r/rcontrollercontrol.hh | 2 +- elements/ip/80211r/rssibecon.cc | 4 ++-- elements/ip/wgtt/packetselectionSerial.cc | 4 +--- elements/ip/wgtt/wgttqueue.cc | 4 +--- include/clicknet/wgtt.h | 11 +++++++---- 9 files changed, 18 insertions(+), 21 deletions(-) diff --git a/elements/ip/80211r/rapcontrol.cc b/elements/ip/80211r/rapcontrol.cc index 05f0faa0c0..5ef776ea4b 100755 --- a/elements/ip/80211r/rapcontrol.cc +++ b/elements/ip/80211r/rapcontrol.cc @@ -26,7 +26,6 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) - .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) .complete() < 0) return -1; @@ -51,6 +50,8 @@ RAPControl::configure(Vector &conf, ErrorHandler *errh) switch(i) { case 0:cp_ethernet_address(CLIENT1_MAC, _ethh[i].ether_dhost);break; + case 1:cp_ethernet_address(CLIENT2_MAC, _ethh[i].ether_dhost);break; + case 2:cp_ethernet_address(CLIENT3_MAC, _ethh[i].ether_dhost);break; } } @@ -237,7 +238,6 @@ void RAPControl::push_down_data(Packet*p_in) case CLIENT1_MAC_SUFFIX: c = 0;break; case CLIENT2_MAC_SUFFIX: c = 1;break; case CLIENT3_MAC_SUFFIX: c = 2;break; - case CLIENT4_MAC_SUFFIX: c = 3;break; } if(state[c] == INACTIVE) p_in -> kill(); @@ -253,7 +253,6 @@ void RAPControl::push_up_data(Packet*p_in) case CLIENT1_MAC_SUFFIX: c = 0;break; case CLIENT2_MAC_SUFFIX: c = 1;break; case CLIENT3_MAC_SUFFIX: c = 2;break; - case CLIENT4_MAC_SUFFIX: c = 3;break; } if(state[c] == INACTIVE) p_in -> kill(); diff --git a/elements/ip/80211r/rapcontrol.hh b/elements/ip/80211r/rapcontrol.hh index ab6d6f837e..421fbab348 100755 --- a/elements/ip/80211r/rapcontrol.hh +++ b/elements/ip/80211r/rapcontrol.hh @@ -37,7 +37,7 @@ class RAPControl : public Element { public: click_ether * _ethh; unsigned char control_content[4]; - int tmp_start[4]; + int tmp_start[3];//set this fix because # of click configuration interface diff --git a/elements/ip/80211r/rclientcontrol.cc b/elements/ip/80211r/rclientcontrol.cc index 7967d6add6..0a9142efce 100755 --- a/elements/ip/80211r/rclientcontrol.cc +++ b/elements/ip/80211r/rclientcontrol.cc @@ -16,7 +16,7 @@ int RClientControl::configure(Vector &conf, ErrorHandler *errh) { - int i, tmp_start[4],tmp_id; + int i, tmp_start[3],tmp_id; char tmp_rssi_threshold; openlog("RClientControl", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); for(i=0;i &conf, ErrorHandler *errh) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) - .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) .read_p("INTERVAL", IntArg(), interval) .read_p("PRINTINTERVAL", IntArg(), print_interval) .read_p("RSSITHRESHOLD", IntArg(), tmp_rssi_threshold) @@ -49,6 +48,8 @@ RClientControl::configure(Vector &conf, ErrorHandler *errh) switch(identity) { case 1: cp_ethernet_address(CLIENT1_MAC, _ethh->ether_shost);break; + case 2: cp_ethernet_address(CLIENT2_MAC, _ethh->ether_shost);break; + case 3: cp_ethernet_address(CLIENT3_MAC, _ethh->ether_shost);break; } cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_dhost); @@ -166,7 +167,6 @@ void RClientControl::push_80211(Packet*p_in) case CLIENT1_MAC_SUFFIX: c = 1;break; case CLIENT2_MAC_SUFFIX: c = 2;break; case CLIENT3_MAC_SUFFIX: c = 3;break; - case CLIENT4_MAC_SUFFIX: c = 4;break; } if(c == identity) diff --git a/elements/ip/80211r/rcontrollercontrol.cc b/elements/ip/80211r/rcontrollercontrol.cc index c1f074ae8c..b64f125358 100755 --- a/elements/ip/80211r/rcontrollercontrol.cc +++ b/elements/ip/80211r/rcontrollercontrol.cc @@ -23,7 +23,6 @@ RControlerControl::configure(Vector &conf, ErrorHandler *errh) .read_p("FIRSTSTART1", IntArg(), tmp_start[0]) .read_p("FIRSTSTART2", IntArg(), tmp_start[1]) .read_p("FIRSTSTART3", IntArg(), tmp_start[2]) - .read_p("FIRSTSTART4", IntArg(), tmp_start[3]) .complete() < 0) return -1; diff --git a/elements/ip/80211r/rcontrollercontrol.hh b/elements/ip/80211r/rcontrollercontrol.hh index 7fa950f36f..3a86286c02 100755 --- a/elements/ip/80211r/rcontrollercontrol.hh +++ b/elements/ip/80211r/rcontrollercontrol.hh @@ -32,7 +32,7 @@ class RControlerControl : public Element { public: unsigned char outport[MAX_N_CLIENT]; unsigned char control_content[4]; click_ether * _ethh; - int tmp_start[4]; + int tmp_start[3]; diff --git a/elements/ip/80211r/rssibecon.cc b/elements/ip/80211r/rssibecon.cc index 15ff863441..c7ce5cf91b 100644 --- a/elements/ip/80211r/rssibecon.cc +++ b/elements/ip/80211r/rssibecon.cc @@ -62,8 +62,8 @@ RSSIBecon::fragment(Packet *p_in) // syslog (LOG_DEBUG, "prepare to send, len: %d\n", len); // WritablePacket *p_csi = Packet::make(sizeof(my_test_struct)*N_CLIENT); - // for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) - if(len>0) + for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry)) + // if(len>0) { //one pkt per client WritablePacket *p_csi = Packet::make(11); diff --git a/elements/ip/wgtt/packetselectionSerial.cc b/elements/ip/wgtt/packetselectionSerial.cc index 80fb03df6e..e0bd48f3de 100755 --- a/elements/ip/wgtt/packetselectionSerial.cc +++ b/elements/ip/wgtt/packetselectionSerial.cc @@ -63,13 +63,12 @@ PacketSelectionSerial::PacketSelectionSerial() int PacketSelectionSerial::configure(Vector &conf, ErrorHandler *errh) { - int i,tmp[4]; + int i,tmp[3]; if (Args(conf, this, errh) .read_p("INTERVAL", IntArg(), interval) .read_p("FIRSTSTART1", IntArg(), tmp[0]) .read_p("FIRSTSTART2", IntArg(), tmp[1]) .read_p("FIRSTSTART3", IntArg(), tmp[2]) - .read_p("FIRSTSTART4", IntArg(), tmp[3]) .read_p("PRINTINTERVAL", IntArg(), print_interval) .complete() < 0) return -1; @@ -150,7 +149,6 @@ void PacketSelectionSerial::push_status(Packet *p_in) case CLIENT1_MAC_SUFFIX: c = 0;break; case CLIENT2_MAC_SUFFIX: c = 1;break; case CLIENT3_MAC_SUFFIX: c = 2;break; - case CLIENT4_MAC_SUFFIX: c = 3;break; } //since the score are minus, we minus again //TODO: smaller is better? diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index 1acc0c78ee..1448e56a67 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -33,13 +33,12 @@ WGTTQueue::WGTTQueue() int WGTTQueue::configure(Vector &conf, ErrorHandler *errh) { - int tmp[4], i; + int tmp[3], i; if (Args(conf, this, errh) .read_p("IDENTITY", IntArg(), identity) .read_p("FIRSTSTART1", IntArg(), tmp[0]) .read_p("FIRSTSTART2", IntArg(), tmp[1]) .read_p("FIRSTSTART3", IntArg(), tmp[2]) - .read_p("FIRSTSTART4", IntArg(), tmp[3]) .complete() < 0) return -1; for(i=0;i Date: Thu, 26 Jan 2017 00:34:49 -0500 Subject: [PATCH 156/171] debug: 3 input for adder --- elements/ip/wgtt/idadder.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/idadder.hh b/elements/ip/wgtt/idadder.hh index 55a6ad0f7a..bc8bad60d2 100755 --- a/elements/ip/wgtt/idadder.hh +++ b/elements/ip/wgtt/idadder.hh @@ -22,7 +22,7 @@ class IDAdder : public Element { public: IDAdder() CLICK_COLD; const char *class_name() const { return "IDAdder"; } - const char *port_count() const { return "4/1"; } + const char *port_count() const { return "3/1"; } const char *flags() const { return "A"; } void push(int port, Packet *p_in); From e0223453905facba6b7205fa77d5746f62d30c58 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Thu, 26 Jan 2017 02:20:04 -0500 Subject: [PATCH 157/171] debug --- elements/ip/80211r/rcontrollercontrol.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/80211r/rcontrollercontrol.hh b/elements/ip/80211r/rcontrollercontrol.hh index 3a86286c02..c426883769 100755 --- a/elements/ip/80211r/rcontrollercontrol.hh +++ b/elements/ip/80211r/rcontrollercontrol.hh @@ -18,7 +18,7 @@ class RControlerControl : public Element { public: const char *class_name() const { return "RControlerControl"; } - const char *port_count() const { return "5/2"; } + const char *port_count() const { return "4/2"; } const char *flags() const { return "A"; } int configure(Vector &, ErrorHandler *) CLICK_COLD; From ccddc9123c56937f5e62c6a50001fd91a301dc42 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 6 Feb 2017 19:18:29 -0500 Subject: [PATCH 158/171] add a seqgen part --- elements/ip/wgtt/seqgen.cc | 144 +++++++++++++++++++++++++++++++++++++ elements/ip/wgtt/seqgen.hh | 56 +++++++++++++++ 2 files changed, 200 insertions(+) create mode 100755 elements/ip/wgtt/seqgen.cc create mode 100755 elements/ip/wgtt/seqgen.hh diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc new file mode 100755 index 0000000000..5acdbe8096 --- /dev/null +++ b/elements/ip/wgtt/seqgen.cc @@ -0,0 +1,144 @@ +/* + Controller program, generate simple data and switch control + Input: trigger packet + Output: control & data + Created by Zhenyu Song: sunnyszy@gmail.com + */ + +#include +#include "seqgen.hh" +#include +#include +#include +#include + +CLICK_DECLS + +SeqGen::SeqGen() +{ + openlog("SeqGen", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); + + _ethh = new click_ether; + _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); + cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); + output_port = 3; + counter = 0; + + syslog (LOG_DEBUG, "Init finish, ready to start\n"); +} + +int SeqGen::configure(Vector &conf, ErrorHandler *errh) +{ + if (Args(conf, this, errh) + .read_p("SWITCHINTERVAL", IntArg(), interval) + .complete() < 0) + return -1; + + syslog (LOG_DEBUG, "Finish configure. Switch interval: %d\n", interval); + return 0; +} + +void SeqGen::push(int port, Packet *p_in) +{ + // here is a small bug, I can not put the reset function in the initial function + static unsigned char lock = 0; + if(!lock) + { + lock++; + reset_ap(); + } + + // syslog (LOG_DEBUG, "pkt_type: %x\n", pkt_type(p_in)); + push_status(p_in); + +} + +void SeqGen::reset_ap() +{ + control_content[0] = RESET_CONTENT; + control_content[1] = RESET_CONTENT; + for(int i=0;idata()+sizeof(click_ether), &control_content, 2); + //ether part + switch(i) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_DEBUG, "Controller reset ap %X\n", i+1); + output(1).push(p); + } +} + +void SeqGen::push_status(Packet *p_in) +{ + const unsigned char a = status_ap(p_in) - 1; + unsigned char c = 0; + + + + p_in -> kill(); + // syslog (LOG_DEBUG, "state idle\n"); + unsigned char best_ap; + // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); + // WGTT + counter++; + + if(!(counter%interval)) + { + best_ap = output_port; + best_ap = 7 - best_ap; //only switch between 3,4 + syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); + + // send_meg(best_ap) + WritablePacket *p = Packet::make(sizeof(click_ether)+2); + // click_ip *ip = reinterpret_cast(p->data()+sizeof(click_ether)); + // // data part + control_content[0] = CLIENT1_IP_SUFFIX + c; + control_content[1] = best_ap; + memcpy(p->data()+sizeof(click_ether), &control_content, 2); + //ether part + switch(output_port) + { + case 0:cp_ethernet_address(AP1_MAC, _ethh->ether_dhost);break; + case 1:cp_ethernet_address(AP2_MAC, _ethh->ether_dhost);break; + case 2:cp_ethernet_address(AP3_MAC, _ethh->ether_dhost);break; + case 3:cp_ethernet_address(AP4_MAC, _ethh->ether_dhost);break; + case 4:cp_ethernet_address(AP5_MAC, _ethh->ether_dhost);break; + case 5:cp_ethernet_address(AP6_MAC, _ethh->ether_dhost);break; + case 6:cp_ethernet_address(AP7_MAC, _ethh->ether_dhost);break; + case 7:cp_ethernet_address(AP8_MAC, _ethh->ether_dhost);break; + } + memcpy(p->data(), _ethh, sizeof(click_ether)); + + syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + output_port = best_ap; + + output(1).push(p); + } + + //data packet + WritablePacket *p_data = Packet::make(1); + memcpy(p_data->data(), &counter, 1); + + //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); + //output_port = best_ap; + output(0).push(p_data); + +} + + + +CLICK_ENDDECLS +EXPORT_ELEMENT(SeqGen) +ELEMENT_MT_SAFE(SeqGen) diff --git a/elements/ip/wgtt/seqgen.hh b/elements/ip/wgtt/seqgen.hh new file mode 100755 index 0000000000..852029867c --- /dev/null +++ b/elements/ip/wgtt/seqgen.hh @@ -0,0 +1,56 @@ +/* + generate a sequence of seq/ switch signal + Input: trigger packet + Output: control & data + Created by Zhenyu Song: sunnyszy@gmail.com + */ +#ifndef CLICK_SEQGEN_HH +#define CLICK_SEQGEN_HH +#include +#include +#include +#include +#include +#include +#include +#include +#include +CLICK_DECLS + +class SeqGen : public Element { public: + + + SeqGen() CLICK_COLD; + + const char *class_name() const { return "SeqGen"; } + const char *port_count() const { return "1/2"; } + const char *flags() const { return "A"; } + + int configure(Vector &, ErrorHandler *) CLICK_COLD; + + void reset_ap(); + void push(int port, Packet *p_in); + + void push_status(Packet *p_in); + + private: + + unsigned char output_port; + unsigned char control_content[2]; + + // used for debug. + // By setting a positive number, manually switch after every ${interval} pkt + // Between ap 1 - 2 + int interval; + + click_ether * _ethh; + uint8_t counter; + + +}; + + + + +CLICK_ENDDECLS +#endif From c60b48836bae1e659de47d66b11b93f28f0fb6d9 Mon Sep 17 00:00:00 2001 From: Zhenyu Song Date: Wed, 8 Feb 2017 11:04:11 -0500 Subject: [PATCH 159/171] add pkt length --- doc/testie.1 | 392 +++++++++++++++++++++++++++++++++++++ elements/ip/wgtt/seqgen.cc | 5 +- elements/ip/wgtt/seqgen.hh | 2 + 3 files changed, 397 insertions(+), 2 deletions(-) create mode 100644 doc/testie.1 diff --git a/doc/testie.1 b/doc/testie.1 new file mode 100644 index 0000000000..99dd5f0af1 --- /dev/null +++ b/doc/testie.1 @@ -0,0 +1,392 @@ +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) +.\" +.\" Standard preamble: +.\" ======================================================================== +.de Sp \" Vertical space (when we can't use .PP) +.if t .sp .5v +.if n .sp +.. +.de Vb \" Begin verbatim text +.ft CW +.nf +.ne \\$1 +.. +.de Ve \" End verbatim text +.ft R +.fi +.. +.\" Set up some character translations and predefined strings. \*(-- will +.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left +.\" double quote, and \*(R" will give a right double quote. \*(C+ will +.\" give a nicer C++. Capital omega is used to do unbreakable dashes and +.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, +.\" nothing in troff, for use with C<>. +.tr \(*W- +.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' +.ie n \{\ +. ds -- \(*W- +. ds PI pi +. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch +. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch +. ds L" "" +. ds R" "" +. ds C` "" +. ds C' "" +'br\} +.el\{\ +. ds -- \|\(em\| +. ds PI \(*p +. ds L" `` +. ds R" '' +. ds C` +. ds C' +'br\} +.\" +.\" Escape single quotes in literal strings from groff's Unicode transform. +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" +.\" If the F register is turned on, we'll generate index entries on stderr for +.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index +.\" entries marked with X<> in POD. Of course, you'll have to process the +.\" output yourself in some meaningful fashion. +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX +.. +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" +.. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} +.\} +.rr rF +.\" +.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). +.\" Fear. Run. Save yourself. No user-serviceable parts. +. \" fudge factors for nroff and troff +.if n \{\ +. ds #H 0 +. ds #V .8m +. ds #F .3m +. ds #[ \f1 +. ds #] \fP +.\} +.if t \{\ +. ds #H ((1u-(\\\\n(.fu%2u))*.13m) +. ds #V .6m +. ds #F 0 +. ds #[ \& +. ds #] \& +.\} +. \" simple accents for nroff and troff +.if n \{\ +. ds ' \& +. ds ` \& +. ds ^ \& +. ds , \& +. ds ~ ~ +. ds / +.\} +.if t \{\ +. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" +. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' +. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' +. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' +. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' +. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' +.\} +. \" troff and (daisy-wheel) nroff accents +.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' +.ds 8 \h'\*(#H'\(*b\h'-\*(#H' +.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] +.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' +.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' +.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] +.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] +.ds ae a\h'-(\w'a'u*4/10)'e +.ds Ae A\h'-(\w'A'u*4/10)'E +. \" corrections for vroff +.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' +.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' +. \" for low resolution devices (crt and lpr) +.if \n(.H>23 .if \n(.V>19 \ +\{\ +. ds : e +. ds 8 ss +. ds o a +. ds d- d\h'-1'\(ga +. ds D- D\h'-1'\(hy +. ds th \o'bp' +. ds Th \o'LP' +. ds ae ae +. ds Ae AE +.\} +.rm #[ #] #H #V #F C +.\" ======================================================================== +.\" +.IX Title "TESTIE 1" +.TH TESTIE 1 "2017-01-18" "perl v5.18.2" "" +.\" For nroff, turn off justification. Always turn off hyphenation; it makes +.\" way too many mistakes in technical documents. +.if n .ad l +.nh +.SH "NAME" +testie \- simple test harness +.SH "SYNOPSIS" +.IX Header "SYNOPSIS" +testie [\s-1OPTIONS\s0] [\s-1FILE\s0]... +.SH "DESCRIPTION" +.IX Header "DESCRIPTION" +Testie is a simple test harness. A testie test comprises a shell +script and, optionally, input and expected output files for that +script. Testie runs the script; the test succeeds if all of the script +commands succeed, and the actual output files match expectations. +.PP +Testie accepts test filenames and directories as arguments. +Directories are recursively searched for \fI*.testie\fR files. It +reports problems for failed tests, plus a summary. +.PP +Testie exits with status 0 if all tests succeed, 1 if any test fails, +and 2 if a test fails due to an internal error. Tests whose \fB\f(CB%require\fB\fR +prerequisites fail do not affect the exit status, except that if all +tests' prerequisites fail, the return status is 1 instead of 0. +.SH "OPTIONS" +.IX Header "OPTIONS" +.IP "\fB\-j\fR\fIN\fR, \fB\-\-jobs\fR=\fIN\fR" 8 +.IX Item "-jN, --jobs=N" +Run up to \fIN\fR tests simultaneously. Like Make's \fB\-j\fR option. +.IP "\fI\s-1VARIABLE\s0\fR=\fI\s-1VALUE\s0\fR" 8 +.IX Item "VARIABLE=VALUE" +Provide an environment variable setting for \fI\s-1VARIABLE\s0\fR within the script. +.IP "\fB\-s\fR, \fB\-\-show\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-s, --show FILE" +Echo the contents of \fI\s-1FILE\s0\fR on completion. \fI\s-1FILE\s0\fR should be one of the +filenames specified by \fB\f(CB%file\fB\fR or \fB\f(CB%expect\fB\fR, or \fBstdout\fR or \fBstderr\fR. +Leaves out any ignored lines. +.IP "\fB\-S\fR, \fB\-\-show\-raw\fR \fI\s-1FILE\s0\fR" 8 +.IX Item "-S, --show-raw FILE" +Like \fB\-\-show\fR, but includes any ignored lines. +.IP "\fB\-\-show\-all\fR" 8 +.IX Item "--show-all" +Calls \fB\-\-show\fR for all filenames specified by any \fB\f(CB%expect\fB\fR, plus \fBstdout\fR +and \fBstderr\fR. Leaves out any ignored lines. +.IP "\fB\-\-show\-all\-raw\fR" 8 +.IX Item "--show-all-raw" +Like \fB\-\-show\-all\fR, but includes any ignored lines. +.IP "\fB\-e\fR, \fB\-\-expand\fR" 8 +.IX Item "-e, --expand" +Don't run the given test; instead, expand its files into the current +directory. The script is stored in a file called \fI\f(CI%script\fI\fR. +.IP "\fB\-\-preserve\-temporaries\fR" 8 +.IX Item "--preserve-temporaries" +Preserve temporary test directories. Testie runs each test in its own +subdirectory of the current directory. Test directories are named +\&\fItestieNNNNN\fR, and are typically removed on test completion. +Examining the contents of a test directory can be useful when +debugging a test. +.IP "\fB\-p\fR, \fB\-\-path\fR \fI\s-1DIR\s0\fR" 8 +.IX Item "-p, --path DIR" +Prepend \fI\s-1DIR\s0\fR to the \f(CW\*(C`PATH\*(C'\fR environment variable before running the +test script. +.IP "\fB\-V\fR, \fB\-\-verbose\fR" 8 +.IX Item "-V, --verbose" +Print information to standard error about successful tests as well as +unsuccessful tests. +.IP "\fB\-VV\fR, \fB\-\-superverbose\fR" 8 +.IX Item "-VV, --superverbose" +Like \fB\-\-verbose\fR, but use a slightly different format, and +additionally print every test's \fB\f(CB%info\fB\fR section before the test results. +.IP "\fB\-q\fR, \fB\-\-quiet\fR" 8 +.IX Item "-q, --quiet" +Don't print information to the terminal while running multiple tests. +.IP "\fB\-v\fR, \fB\-\-version\fR" 8 +.IX Item "-v, --version" +Print version number information and exit. +.IP "\fB\-\-help\fR" 8 +.IX Item "--help" +Print help information and exit. +.SH "FILE FORMAT" +.IX Header "FILE FORMAT" +Testie test files consist of several sections, each introduced by a line +starting with \fB%\fR. There must be, at least, a \fB\f(CB%script\fB\fR section. +The \fB\f(CB%file\fB\fR and \fB\f(CB%expect\fB\fR sections define input and output files by +name. +.ie n .IP "\fB\fB%script\fB\fR" 8 +.el .IP "\fB\f(CB%script\fB\fR" 8 +.IX Item "%script" +The \fBsh\fR shell script that controls the test. Testie will run each +command in sequence. Every command in the script must succeed, with +exit status 0, or the test will fail. Use \fB\f(CB%file\fB\fR sections to define +script input files and \fB\f(CB%expect\fB\fR sections to check script output files +for expected values. +.Sp +The \fB\f(CB%script\fB\fR section can contain subtests. To start a new subtest, +execute a command like \f(CW\*(C`testie_subtest\ SECTIONNAME\*(C'\fR. Testie will +report the problematic \f(CW\*(C`SECTIONNAME\*(C'\fR when standard output or error +doesn't match an expected value. +.Sp +The script's environment is populated with any \fI\s-1VARIABLE\s0\fRs set on the +testie command line with \fB\f(BI\s-1VARIABLE\s0\fB=\f(BI\s-1VALUE\s0\fB\fR syntax. Also, the +\&\fB\f(CB$rundir\fB\fR environment variable is set to the directory in which +testie was originally run. +.ie n .IP "\fB\fB%require\fB [\-q]\fR" 8 +.el .IP "\fB\f(CB%require\fB [\-q]\fR" 8 +.IX Item "%require [-q]" +An \fBsh\fR shell script defining prerequisites that must be satisfied +before the test can run. Every command in the script must succeed, with +exit status 0, for the test to run. Standard output and error are not +checked, however. The \fB\-q\fR flag tells testie not to print an error message +if a requirement fails. +.Sp +Testie runs the requirement script before creating any other test files. +For example, contents of \fB\f(CB%file\fB\fR sections are not available. +.ie n .IP "\fB\fB%info\fB\fR" 8 +.el .IP "\fB\f(CB%info\fB\fR" 8 +.IX Item "%info" +A short description of the test. In \fB\-\-superverbose\fR mode, the first +paragraph of its contents is printed before the test results. +.ie n .IP "\fB\fB%cut\fB\fR" 8 +.el .IP "\fB\f(CB%cut\fB\fR" 8 +.IX Item "%cut" +This section is ignored. It is intended to comment out obsolete parts of +the test. +.ie n .IP "\fB\fB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%file\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%file [-de] [+LENGTH] FILENAME..." +Create an input file for the script. \fI\s-1FILENAME\s0\fR can be \fBstdin\fR, +which sets the script's standard input. If \fB+\fR\fI\s-1LENGTH\s0\fR is provided, +the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this line; +otherwise, it consists of the data up to the next section. The \fB\-d\fR +flag tells testie to delete the first character of each line in the +section. The \fB\-e\fR flag indicates that the section was \s-1MIME\s0 +Base64\-encoded (see \fIbase64\fR\|(1)); it is decoded before use. To +include a file with lines that start with \fB%\fR (which would normally +start a new section), use \fB\-d\fR and preface each line of the file with +a space, or use \fB\-e\fR. +.ie n .IP "\fB\fB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expect\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expect [-adeiw] [+LENGTH] FILENAME..." +Define an expected output file. Differences between the script's +output \fI\s-1FILENAME\s0\fR and the contents of the \fB\f(CB%expect\fB\fR section will +cause the test to fail. +.Sp +\&\fI\s-1FILENAME\s0\fR can be \fBstdout\fR, for standard output. If \fB+\fR\fI\s-1LENGTH\s0\fR is +provided, the file data consists of the \fI\s-1LENGTH\s0\fR bytes following this +line; otherwise, it consists of the data up to the next section. +.Sp +After running the script, testie compares the \fI\s-1FILENAME\s0\fR generated by +the script with the provided data. The files are compared +line-by-line. Testie ignores blank lines, differences in trailing +whitespace, and lines in the script output that match \fB\f(CB%ignore\fB\fR +patterns (see below). The \fB\-w\fR flag causes testie to ignore +differences in amount of whitespace within each line. +.Sp +\&\fB\f(CB%expect\fB\fR lines can contain Perl regular expressions, enclosed by two +sets of braces. The \fB\f(CB%expect\fB\fR line +.Sp +.Vb 1 +\& foo{{(bar)?}} +.Ve +.Sp +matches either \f(CW\*(C`foo\*(C'\fR or \f(CW\*(C`foobar\*(C'\fR. The \fB\-i\fR flag makes all such +regular expressions case-insensitive. (Text outside of regular +expressions must match case.) +.Sp +Document an \fB\f(CB%expect\fB\fR line with \f(CW\*(C`{{?comment}}\*(C'\fR blocks. For example: +.Sp +.Vb 1 +\& foo {{? the sort was in the right order}} +.Ve +.Sp +Testie ignores whitespace before and after the \f(CW\*(C`{{?comment}}\*(C'\fR block, and if +the actual output differs from this expected line, it prints the comment in +addition to the line differences. +.Sp +The \fB\-a\fR flag marks this expected output as an alternate. Testie will +compare the script's output file with each provided alternate; the +test succeeds if any of the alternates match. The \fB\-d\fR flag behaves +as in \fB\f(CB%file\fB\fR. +.ie n .IP "\fB\fB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectv\fB [\-ade] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expectv [-ade] [+LENGTH] FILENAME..." +Define a literal expected output file. This behaves like \fB\f(CB%expect\fB\fR, +except that the script's output file must match the provided data +\&\fIexactly\fR: \fB\f(CB%expectv\fB\fR never ignores whitespace differences, does not +treat \f(CW\*(C`{{}}\*(C'\fR blocks as regular expressions, and does not parse +\&\fB\f(CB%ignore\fB\fR patterns. +.ie n .IP "\fB\fB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.el .IP "\fB\f(CB%expectx\fB [\-adiw] [+\f(BI\s-1LENGTH\s0\fB] \f(BI\s-1FILENAME\s0\fB...\fR" 8 +.IX Item "%expectx [-adiw] [+LENGTH] FILENAME..." +Define a regular-expression expected output file. This behaves like +\&\fB\f(CB%expect\fB\fR, except that every line is treated as a regular expression. +\&\f(CW\*(C`{{?comment}}\*(C'\fR blocks are ignored, but other brace pairs are treated +according to the normal regular expression rules. +.ie n .IP "\fB\fB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdin\fB [\-de] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdin [-de] [+LENGTH]" +Same as \fB\f(CB%file\fB stdin\fR. +.ie n .IP "\fB\fB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stdout\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stdout [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stdout\fR. +.ie n .IP "\fB\fB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%stderr\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB]\fR" 8 +.IX Item "%stderr [-adeiw] [+LENGTH]" +Same as \fB\f(CB%expect\fB stderr\fR. +.ie n .IP "\fB\fB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignorex\fB [\-di] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.IX Item "%ignorex [-di] [+LENGTH] [FILENAME]" +Each line in the \fB\f(CB%ignorex\fB\fR section is a Perl regular expression. Lines in +the supplied \fI\s-1FILENAME\s0\fR that match any of those regular expressions will not +be considered when comparing files with \fB\f(CB%expect\fB\fR data. The regular +expression must match the whole line. \fI\s-1FILENAME\s0\fR may be \fBall\fR, in which case +the regular expressions will apply to all \fB\f(CB%expect\fB\fR files. \f(CW\*(C`{{?comment}}\*(C'\fR +blocks are ignored. +.ie n .IP "\fB\fB%ignore\fB\fR, \fB\fB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.el .IP "\fB\f(CB%ignore\fB\fR, \fB\f(CB%ignorev\fB [\-adeiw] [+\f(BI\s-1LENGTH\s0\fB] [\f(BI\s-1FILENAME\s0\fB]\fR" 8 +.IX Item "%ignore, %ignorev [-adeiw] [+LENGTH] [FILENAME]" +Like \fB\f(CB%ignorex\fB\fR, but \fB\f(CB%ignore\fB\fR parses regular expressions only inside +double braces (\f(CW\*(C`{{ }}\*(C'\fR), and \fB\f(CB%ignorev\fB\fR lines must match exactly. +.ie n .IP "\fB\fB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 +.el .IP "\fB\f(CB%include\fB \f(BI\s-1FILENAME\s0\fB\fR" 8 +.IX Item "%include FILENAME" +Interpolate the contents of another testie file. +.ie n .IP "\fB\fB%eot\fB\fR" 8 +.el .IP "\fB\f(CB%eot\fB\fR" 8 +.IX Item "%eot" +Marks the end of the current test. The rest of the file will be parsed for +additional tests. +.ie n .IP "\fB\fB%eof\fB\fR" 8 +.el .IP "\fB\f(CB%eof\fB\fR" 8 +.IX Item "%eof" +The rest of the file is ignored. +.SH "EXAMPLE" +.IX Header "EXAMPLE" +This simple testie script checks that 'grep \-c' works for a simple output +file. +.PP +.Vb 7 +\& %script +\& grep \-c B. +\& %stdin +\& Bfoo +\& B +\& %stdout +\& 1 +.Ve +.SH "ENVIRONMENT" +.IX Header "ENVIRONMENT" +By default, testie sets the \f(CW\*(C`LC_ALL\*(C'\fR environment variable to \*(L"C\*(R"; without +this setting commands like \fBsort\fR have unpredictable effects. To set +\&\f(CW\*(C`LC_ALL\*(C'\fR to another value, set it in the \fB\f(CB%script\fB\fR section. +.SH "AUTHOR" +.IX Header "AUTHOR" +Eddie Kohler, diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index 5acdbe8096..21ae914ec5 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -31,6 +31,7 @@ int SeqGen::configure(Vector &conf, ErrorHandler *errh) { if (Args(conf, this, errh) .read_p("SWITCHINTERVAL", IntArg(), interval) + .read_p("PACKETLENGTH", IntArg(), pkt_len) .complete() < 0) return -1; @@ -128,8 +129,8 @@ void SeqGen::push_status(Packet *p_in) } //data packet - WritablePacket *p_data = Packet::make(1); - memcpy(p_data->data(), &counter, 1); + WritablePacket *p_data = Packet::make(pkt_len); + memcpy(p_data->end_data()-1, &counter, 1); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; diff --git a/elements/ip/wgtt/seqgen.hh b/elements/ip/wgtt/seqgen.hh index 852029867c..c76a42cdd9 100755 --- a/elements/ip/wgtt/seqgen.hh +++ b/elements/ip/wgtt/seqgen.hh @@ -46,6 +46,8 @@ class SeqGen : public Element { public: click_ether * _ethh; uint8_t counter; + int pkt_len; + }; From 4a164fb0d45519697c0598f1ecdf45d056de65c5 Mon Sep 17 00:00:00 2001 From: Zhenyu Song Date: Fri, 10 Feb 2017 09:33:46 -0500 Subject: [PATCH 160/171] suffix 2 byte --- elements/ip/wgtt/seqgen.cc | 6 ++++-- elements/ip/wgtt/seqgen.hh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index 21ae914ec5..4d5a8f9273 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -93,7 +93,8 @@ void SeqGen::push_status(Packet *p_in) unsigned char best_ap; // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); // WGTT - counter++; + // increment by 1 + counter = (counter >= 4095)? 0: counter + 1; if(!(counter%interval)) { @@ -130,7 +131,8 @@ void SeqGen::push_status(Packet *p_in) //data packet WritablePacket *p_data = Packet::make(pkt_len); - memcpy(p_data->end_data()-1, &counter, 1); + uint16_t tmp_seq = htons(counter); + memcpy(p_data->end_data()-sizeof(uint16_t), &tmp_seq, sizeof(uint16_t)); //syslog (LOG_DEBUG, "issu switch. for client: %d to ap: %d\n", c+1, best_ap+1); //output_port = best_ap; diff --git a/elements/ip/wgtt/seqgen.hh b/elements/ip/wgtt/seqgen.hh index c76a42cdd9..3c8050d129 100755 --- a/elements/ip/wgtt/seqgen.hh +++ b/elements/ip/wgtt/seqgen.hh @@ -44,7 +44,7 @@ class SeqGen : public Element { public: int interval; click_ether * _ethh; - uint8_t counter; + uint16_t counter; int pkt_len; From 12371d4c15b9691ba20ee3009260372e968f1143 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 10 Feb 2017 09:35:31 -0500 Subject: [PATCH 161/171] debug wgttqueue --- elements/ip/wgtt/wgttqueue.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/elements/ip/wgtt/wgttqueue.cc b/elements/ip/wgtt/wgttqueue.cc index 1448e56a67..8f225a495f 100644 --- a/elements/ip/wgtt/wgttqueue.cc +++ b/elements/ip/wgtt/wgttqueue.cc @@ -13,7 +13,7 @@ CLICK_DECLS WGTTQueue::WGTTQueue() { - int i; + int i, j; openlog("APControl_WGTTQueue", LOG_PERROR | LOG_CONS | LOG_NDELAY, 0); _q = new Packet **[MAX_N_CLIENT]; for(i=0; i kill(); } + // syslog (LOG_DEBUG, "receive reset req for client: %d, counter %d\n", i, tmp_counter); } + syslog (LOG_DEBUG, "finish reset req\n"); } else { @@ -243,7 +255,9 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { - const unsigned char & seq = queue_seq(p_in); + // syslog (LOG_DEBUG, "begin push_data\n"); + const unsigned char & seq = *(p_in -> end_data()-1); + // syslog (LOG_DEBUG, "seq: %u\n", seq); unsigned char c; switch(data_client(p_in)) { @@ -260,7 +274,7 @@ void WGTTQueue::push_data(Packet *p_in) // syslog (LOG_DEBUG, "wgttQueue: before for client: %d\n", c+1); enRing(c, 0); } - p_in -> pull(15); + p_in -> pull(14); // syslog (LOG_DEBUG, "after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); enRing(c, p_in); } From 594840ed6a012b080f73fd876355ea9336f47836 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 10 Feb 2017 09:44:41 -0500 Subject: [PATCH 162/171] debug: append after checksum --- elements/ip/wgtt/seqgen.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index 4d5a8f9273..02c05cedac 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -83,12 +83,7 @@ void SeqGen::reset_ap() void SeqGen::push_status(Packet *p_in) { - const unsigned char a = status_ap(p_in) - 1; unsigned char c = 0; - - - - p_in -> kill(); // syslog (LOG_DEBUG, "state idle\n"); unsigned char best_ap; // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); @@ -130,7 +125,7 @@ void SeqGen::push_status(Packet *p_in) } //data packet - WritablePacket *p_data = Packet::make(pkt_len); + WritablePacket *p_data = p_in -> put(sizeof(uint16_t)); uint16_t tmp_seq = htons(counter); memcpy(p_data->end_data()-sizeof(uint16_t), &tmp_seq, sizeof(uint16_t)); From 96eebd1ed2d168034e6618e0582f57f5d697777c Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 10 Feb 2017 11:37:02 -0500 Subject: [PATCH 163/171] start from 100 --- elements/ip/wgtt/seqgen.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index 02c05cedac..4ca8026deb 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -22,7 +22,7 @@ SeqGen::SeqGen() _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); output_port = 3; - counter = 0; + counter = 100; syslog (LOG_DEBUG, "Init finish, ready to start\n"); } From 116d504fd4faf116bad1f5e27f34c39c3df3010f Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 12 Feb 2017 17:36:32 -0500 Subject: [PATCH 164/171] switch between 0 & 1 --- elements/ip/wgtt/seqgen.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index 4ca8026deb..e00fe4d2ec 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -94,7 +94,7 @@ void SeqGen::push_status(Packet *p_in) if(!(counter%interval)) { best_ap = output_port; - best_ap = 7 - best_ap; //only switch between 3,4 + best_ap = 1 - best_ap; //only switch between 0, 1 syslog (LOG_DEBUG, "prepare manually switch to ap %X\n", best_ap+1); // send_meg(best_ap) From 50c7367205df7213265d4b5a9dc22fb73176aafe Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sun, 12 Feb 2017 17:43:39 -0500 Subject: [PATCH 165/171] debug --- elements/ip/wgtt/seqgen.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elements/ip/wgtt/seqgen.cc b/elements/ip/wgtt/seqgen.cc index e00fe4d2ec..1e870b0d53 100755 --- a/elements/ip/wgtt/seqgen.cc +++ b/elements/ip/wgtt/seqgen.cc @@ -21,7 +21,7 @@ SeqGen::SeqGen() _ethh = new click_ether; _ethh->ether_type = htons(CONTROL_SUFFIX+ETHER_PROTO_BASE); cp_ethernet_address(CONTROLLER_IN_MAC, _ethh->ether_shost); - output_port = 3; + output_port = 0; counter = 100; syslog (LOG_DEBUG, "Init finish, ready to start\n"); @@ -83,7 +83,7 @@ void SeqGen::reset_ap() void SeqGen::push_status(Packet *p_in) { - unsigned char c = 0; + unsigned char c = 2; // syslog (LOG_DEBUG, "state idle\n"); unsigned char best_ap; // syslog (LOG_DEBUG, "current_state: %d, time_lock: %d\n", state[c], time_lock[c]); From 7dc62d31d866b97238a997deaaa11333fb646d53 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Mon, 13 Feb 2017 10:48:51 -0500 Subject: [PATCH 166/171] 2 ap --- include/clicknet/wgtt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 09482829c1..6b53c44d68 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -41,7 +41,7 @@ struct my_test_struct { #define CLIENT2_MAC "44:c3:06:31:5b:0b" #define CLIENT3_MAC "44:c3:06:31:5b:0d" // ap -#define MAX_N_AP 8 +#define MAX_N_AP 2 #define CLIENT1_IP_SUFFIX 135 #define CLIENT2_IP_SUFFIX 136 #define CLIENT3_IP_SUFFIX 137 From 66d893daffd1c65487f5dc213255c325be8418de Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 17 Feb 2017 15:38:45 -0500 Subject: [PATCH 167/171] id_adder to suffix-seq mode --- elements/ip/wgtt/idadder.cc | 24 +++++++++--------------- elements/ip/wgtt/idadder.hh | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index 542d1f6d7d..9458636629 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -33,16 +33,15 @@ void IDAdder::push(int port, Packet *p_in) cp_ethernet_address(CONTROLLER_IN_MAC, _ethh.ether_shost); } // syslog (LOG_DEBUG, "IDadder: counter: %X\n", counter); - - p_in->push(sizeof(click_ether)+1); - for(int i = 1;i uniqueify(); + *(p_base -> data()+13) &= 0x10; // add a flag to the packet + p_base->push(sizeof(click_ether)); // tunneling head + p_base->put(2); //mac80211 seq + for(int i = 0;iclone(); + Packet *p_tmp = p_base->clone(); WritablePacket *p = p_tmp->uniqueify(); - // data - memcpy(p->data()+sizeof(click_ether), &counter[port], 1); // eth - switch(i) { case 0:cp_ethernet_address(AP1_MAC, _ethh.ether_dhost);break; @@ -55,17 +54,12 @@ void IDAdder::push(int port, Packet *p_in) case 7:cp_ethernet_address(AP8_MAC, _ethh.ether_dhost);break; } memcpy(p->data(), &_ethh, sizeof(click_ether)); + // data + uint16_t net_form_seq = htons(counter[port]); + memcpy(p->end_data()-2, &net_form_seq, 2); // syslog (LOG_DEBUG, "idadder push %dth\n", i); output(0).push(p); } - WritablePacket *p = p_in->uniqueify(); - //data - memcpy(p->data()+sizeof(click_ether), &counter[port], 1); - //eth - cp_ethernet_address(AP1_MAC, _ethh.ether_dhost); - memcpy(p->data(), &_ethh, sizeof(click_ether)); - counter[port]++; - output(0).push(p); } diff --git a/elements/ip/wgtt/idadder.hh b/elements/ip/wgtt/idadder.hh index bc8bad60d2..1769f91fd3 100755 --- a/elements/ip/wgtt/idadder.hh +++ b/elements/ip/wgtt/idadder.hh @@ -30,7 +30,7 @@ class IDAdder : public Element { public: private: - unsigned char counter[MAX_N_CLIENT]; + uint16_t counter[MAX_N_CLIENT]; click_ether _ethh; From 7baa734fa1e0b2d747a2d6e13ad3714a3d63f887 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Sat, 18 Feb 2017 17:39:47 -0500 Subject: [PATCH 168/171] debug: bit operation --- elements/ip/wgtt/idadder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index 9458636629..067ea71187 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -34,7 +34,7 @@ void IDAdder::push(int port, Packet *p_in) } // syslog (LOG_DEBUG, "IDadder: counter: %X\n", counter); WritablePacket *p_base = p_in-> uniqueify(); - *(p_base -> data()+13) &= 0x10; // add a flag to the packet + *(p_base -> data()+13) |= 0x10; // add a flag to the packet p_base->push(sizeof(click_ether)); // tunneling head p_base->put(2); //mac80211 seq for(int i = 0;i Date: Sat, 18 Feb 2017 17:40:47 -0500 Subject: [PATCH 169/171] make make.sh include Already up-to-date. --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index d8bd5c9a4c..3352d9099a 100755 --- a/make.sh +++ b/make.sh @@ -1,5 +1,5 @@ #!/bin/bash - +git pull sudo rm ./bin/click sudo make ./elemlist sudo make From b657a7701c99745d43fdd53a6ab463d98a713ee1 Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Fri, 18 Aug 2017 10:40:37 -0400 Subject: [PATCH 170/171] for seq sync --- elements/ip/wgtt/idadder.cc | 1 + elements/ip/wgtt/idadder.hh | 2 +- include/clicknet/wgtt.h | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index 067ea71187..82ee25ce58 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -60,6 +60,7 @@ void IDAdder::push(int port, Packet *p_in) // syslog (LOG_DEBUG, "idadder push %dth\n", i); output(0).push(p); } + counter[port] = (counter[port] + 1) & 0xfff; } diff --git a/elements/ip/wgtt/idadder.hh b/elements/ip/wgtt/idadder.hh index 1769f91fd3..fa44542927 100755 --- a/elements/ip/wgtt/idadder.hh +++ b/elements/ip/wgtt/idadder.hh @@ -22,7 +22,7 @@ class IDAdder : public Element { public: IDAdder() CLICK_COLD; const char *class_name() const { return "IDAdder"; } - const char *port_count() const { return "3/1"; } + const char *port_count() const { return "1/1"; } const char *flags() const { return "A"; } void push(int port, Packet *p_in); diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index 6b53c44d68..f9592dff3d 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -30,7 +30,7 @@ struct my_test_struct { #define ANT 3 // client 1 ip -#define MAX_N_CLIENT 3 +#define MAX_N_CLIENT 1 //currently unused // #define RSSI_THRESHOLD -67 @@ -41,7 +41,7 @@ struct my_test_struct { #define CLIENT2_MAC "44:c3:06:31:5b:0b" #define CLIENT3_MAC "44:c3:06:31:5b:0d" // ap -#define MAX_N_AP 2 +#define MAX_N_AP 3 #define CLIENT1_IP_SUFFIX 135 #define CLIENT2_IP_SUFFIX 136 #define CLIENT3_IP_SUFFIX 137 From f988288748b9fdae137f2ffdb84000eb8254550d Mon Sep 17 00:00:00 2001 From: "sunnyszy@sjtu.edu.cn" <87453371@qq.com> Date: Wed, 30 Aug 2017 16:01:25 -0400 Subject: [PATCH 171/171] modify for demo --- elements/ip/wgtt/idadder.cc | 2 +- elements/ip/wgtt/packetselectionSerial.cc | 6 +-- elements/ip/wgtt/wgttqueue.cc | 52 ++++++++++++----------- include/clicknet/wgtt.h | 30 +++++++++++++ 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/elements/ip/wgtt/idadder.cc b/elements/ip/wgtt/idadder.cc index 82ee25ce58..b10b419f0b 100755 --- a/elements/ip/wgtt/idadder.cc +++ b/elements/ip/wgtt/idadder.cc @@ -34,7 +34,7 @@ void IDAdder::push(int port, Packet *p_in) } // syslog (LOG_DEBUG, "IDadder: counter: %X\n", counter); WritablePacket *p_base = p_in-> uniqueify(); - *(p_base -> data()+13) |= 0x10; // add a flag to the packet + // *(p_base -> data()+13) |= 0x10; // add a flag to the packet p_base->push(sizeof(click_ether)); // tunneling head p_base->put(2); //mac80211 seq for(int i = 0;i kill(); } - // syslog (LOG_DEBUG, "receive reset req for client: %d, counter %d\n", i, tmp_counter); + syslog (LOG_DEBUG, "receive reset req for client: %d, counter %d\n", i, tmp_counter); } syslog (LOG_DEBUG, "finish reset req\n"); } @@ -256,8 +247,19 @@ void WGTTQueue::push_control(Packet *p_in) void WGTTQueue::push_data(Packet *p_in) { // syslog (LOG_DEBUG, "begin push_data\n"); - const unsigned char & seq = *(p_in -> end_data()-1); - // syslog (LOG_DEBUG, "seq: %u\n", seq); + unsigned char seq = *(p_in -> end_data()-3); + // const unsigned char * p_c; + // int i; + // for (p_c = p_in->data(); p_c+i != p_in ->end_data(); i++) + // printf("%x", *(p_c+i)); + // printf("\n"); + // printf("-1 %x\n", *(p_in->end_data()-1)); + // printf("-2 %x\n", *(p_in->end_data()-2)); + // printf("-3 %x\n", *(p_in->end_data()-3)); + // printf("-4 %x\n", *(p_in->end_data()-4)); + + + // syslog (LOG_DEBUG, "seq: %x\n", seq); unsigned char c; switch(data_client(p_in)) { @@ -275,7 +277,7 @@ void WGTTQueue::push_data(Packet *p_in) enRing(c, 0); } p_in -> pull(14); - // syslog (LOG_DEBUG, "after enring, _head: %X, _tail: %X\n", _head[c], _tail[c]); + // syslog (LOG_DEBUG, "enring client %d, after enring, _head: %X, _tail: %X\n", c+1, _head[c], _tail[c]); enRing(c, p_in); } diff --git a/include/clicknet/wgtt.h b/include/clicknet/wgtt.h index f9592dff3d..40fadecc59 100644 --- a/include/clicknet/wgtt.h +++ b/include/clicknet/wgtt.h @@ -5,6 +5,36 @@ #ifndef _WGTT_H_ #define _WGTT_H_ + +// #define WGTT_DEBUG +// #ifdef WGTT_DEBUG +// #define DPRINT(fmt, args...) syslog (LOG_DEBUG, "%s: " fmt, __func__ , ## args) +// #else +// #define DPRINT(fmt, args...) do {} while (0) +// #endif +// #define NDPRINT(fmt, args...) do {} while(0) + +// #ifdef WGTT_DEBUG +// #define DASSERT(expr) \ +// if (!(expr)) { \ +// syslog("Assertion failed! %s,%s,%s,line=%d\n", \ +// #expr, __FILE__, __func__, __LINE__); \ +// } +// #else +// #define DASSERT(expr) do {} while (0) +// #endif + +// #ifdef WGTT_DEBUG +// #define DASSERT2(expr1, expr2) \ +// if (expr1 != expr2) { \ +// syslog("Assertion failed! %s,%016lx,%s,%016lx,%s,%s,line=%d\n", \ +// #expr1, expr1, #expr2, expr2, __FILE__, __func__, __LINE__); \ +// } +// #else +// #define DASSERT2(expr1, expr2) do {} while (0) +// #endif + + struct my_test_struct { uint8_t mac; int8_t signal;