NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4468


Ignore:
Timestamp:
Sep 24, 2009, 1:03:41 AM (8 years ago)
Author:
stud-dettling
Message:
  • Added network notification module and network notification client (nwnclient).
Location:
protlib/branches/20090610-qos-nslp-aho
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protlib/branches/20090610-qos-nslp-aho/include/address.h

    r3701 r4468  
    731731} // end get_socknum
    732732
    733 
    734 
    735733}; // end udsaddress
     734
     735
     736/// IEEE48 address (or MAC address)
     737/** This class can hold an IEEE48 address. */
     738class macaddress : public address {
     739public:
     740        virtual macaddress* new_instance() const;
     741        virtual macaddress* copy() const;
     742        virtual bool operator==(const address& ie) const;
     743
     744        // hash function
     745        virtual size_t get_hash() const;
     746
     747public:
     748        /// constructor
     749        macaddress();
     750        /// copy constructor
     751        macaddress(const macaddress& ma);
     752        /// constructor from string
     753        macaddress(const char* str, bool *res = NULL);
     754        /// constructor from byte array
     755        macaddress(const uint8_t macaddr[6]);
     756        /// assignment
     757        macaddress& operator=(const macaddress& ma);
     758        /// destructor
     759        virtual ~macaddress() {};
     760
     761        /// are they equivalent
     762        virtual bool equiv(const macaddress& ma) const;
     763
     764
     765        /// set MAC from macaddress
     766        void set_mac(const macaddress& ma);
     767        /// set MAC address from string
     768        bool set_mac(const char *str);
     769        /// set MAC address from byte array
     770        void set_mac(const uint8_t macaddr[6]);
     771        /// is MAC address unspecified
     772        bool is_mac_unspec() const { return !initialized; };
     773        /// get MAC address as string
     774        const char *get_mac_str() const;
     775        /// get MAC address as string
     776        void get_mac_str(char *str) const;
     777        /// get MAC address as byte array
     778        void get_mac(uint8_t macaddr[6]) const;
     779
     780protected:
     781        uint8_t macaddr[6];
     782        bool initialized;
     783
     784private:
     785        /// pointer to MAC string representation
     786        mutable char outstring[18];
     787}; // end macaddress
     788
     789inline ostream &operator<<(ostream &out, const macaddress &addr) {
     790        return out << addr.get_mac_str();
     791}
     792
    736793
    737794template <typename _dT>
     
    13891446
    13901447
     1448inline
     1449size_t macaddress::get_hash() const {
     1450        size_t tmp = 0;
     1451
     1452        tmp |= ((macaddr[2] & 0xff) << 24);
     1453        tmp |= ((macaddr[3] & 0xff) << 16);
     1454        tmp |= ((macaddr[4] & 0xff) << 8);
     1455        tmp |= (macaddr[5]  & 0xff);
     1456
     1457        return tmp;
     1458} // end get_hash
     1459
     1460
    13911461
    13921462} // end namespace protlib
     
    14051475}; // end appladdress hasher
    14061476
     1477/// netaddress hasher
     1478template <> struct hash<protlib::netaddress> {
     1479        inline size_t operator() (const protlib::netaddress& addr) const { return addr.get_hash(); }
     1480}; // end netaddress hasher
     1481
    14071482/// udsaddress hasher
    14081483template <> struct hash<protlib::udsaddress> {
     
    14101485}; // end udsaddress hasher
    14111486
    1412 
    1413 
    1414 
    1415 /// netaddress hasher
    1416 template <> struct hash<protlib::netaddress> {
    1417         inline size_t operator() (const protlib::netaddress& addr) const { return addr.get_hash(); }
    1418 }; // end netaddress hasher
     1487/// macaddress hasher
     1488template <> struct hash<protlib::macaddress> {
     1489        inline size_t operator()(const protlib::macaddress& addr) const { return addr.get_hash(); }
     1490}; // end macaddress hasher
    14191491
    14201492} // end namespace __gnu_cxx
     
    14361508template <> struct equal_to<protlib::netaddress> {
    14371509        inline bool operator()(const protlib::netaddress& addr1, const protlib::netaddress& addr2) const { return addr1.equiv(addr2); }
    1438 
    14391510}; // end netaddress equal_to
     1511
     1512/// macaddress equal_to
     1513template <> struct equal_to<protlib::macaddress> {
     1514        inline bool operator()(const protlib::macaddress& addr1, const protlib::macaddress& addr2) const { return addr1.equiv(addr2); }
     1515}; // end macaddress equal_to
    14401516
    14411517} // end namespace std
  • protlib/branches/20090610-qos-nslp-aho/include/messages.h

    r3346 r4468  
    6868                type_routing,
    6969                type_API,
    70                 type_mobility
     70                type_mobility,
     71                type_handover
    7172        }; // end type_t
    7273
     
    109110                qaddr_tp_over_uds,
    110111                qaddr_uds_appl_qos,     // receives messages from an external client via UDS
    111                 qaddr_mobility
     112                qaddr_mobility,
     113                qaddr_handover
    112114        }; // end qaddr_t
    113115
  • protlib/branches/20090610-qos-nslp-aho/src/address.cpp

    r3861 r4468  
    4646#include <netdb.h>
    4747#include <err.h>
     48#include <string.h>
    4849
    4950namespace protlib {
     
    800801} // end operator==
    801802
     803
     804/***** class macaddress *****/
     805
     806macaddress* macaddress::new_instance() const {
     807        macaddress* ma = NULL;
     808        catch_bad_alloc(ma = new macaddress());
     809        return ma;
     810} // end new_instance
     811
     812macaddress* macaddress::copy() const {
     813        macaddress* ma = NULL;
     814        catch_bad_alloc(ma =  new macaddress(*this));
     815        return ma;
     816} // end copy
     817
     818bool macaddress::operator==(const address& ie) const {
     819        const macaddress* ma = dynamic_cast<const macaddress*>(&ie);
     820        if (ma) {
     821                return ((initialized == ma->initialized) &&
     822                                (macaddr[0] == ma->macaddr[0]) &&
     823                                (macaddr[1] == ma->macaddr[1]) &&
     824                                (macaddr[2] == ma->macaddr[2]) &&
     825                                (macaddr[3] == ma->macaddr[3]) &&
     826                                (macaddr[4] == ma->macaddr[4]) &&
     827                                (macaddr[5] == ma->macaddr[5]));
     828        }
     829        else {
     830                return false;
     831        }
     832} // end operator==
     833
     834/** Initialize a macaddress object */
     835macaddress::macaddress()
     836        :       address(IEEE48),
     837                initialized(false)
     838{
     839        //clear_mac();
     840} // end constructor macaddress
     841
     842/** Copy constructor for macaddress objects */
     843macaddress::macaddress(const macaddress& ma)
     844        :       address(ma),
     845                initialized(false)
     846{
     847        this->set_mac(ma);
     848} // end copy constructor macaddress
     849
     850/** Initialize macaddress from string if possible. */
     851macaddress::macaddress(const char *str, bool *res)
     852        :       address(IEEE48),
     853                initialized(false)
     854{
     855        register bool tmpres = false;
     856        tmpres = set_mac(str);
     857        if (res) {
     858                *res = tmpres;
     859        }
     860} // end string constructor macaddress
     861
     862/** Initialize macaddress from byte array */
     863macaddress::macaddress(const uint8_t macaddr[6])
     864        :       address(IEEE48),
     865                initialized(false)
     866{
     867        this->set_mac(macaddr);
     868} // end byte array constructor macaddress
     869
     870/** Assign ma to this object. */
     871macaddress& macaddress::operator=(const macaddress& ma) {
     872        address::operator=(ma);
     873        this->set_mac(ma);
     874
     875        return *this;
     876} // end operator=
     877
     878/** Set MAC address from macaddress. */
     879void macaddress::set_mac(const macaddress& ma) {
     880        uint8_t macaddr[6];
     881
     882        if (!ma.is_mac_unspec()) {
     883                ma.get_mac(macaddr);
     884                set_mac(macaddr);
     885        }
     886} // end set_mac(macaddress)
     887
     888/** Set MAC address from string or leave object unchanged. */
     889bool macaddress::set_mac(const char *str) {
     890        uint8_t macaddr[6];
     891        register uint32_t a, b, c, d, e, f;
     892
     893        int ret = sscanf(str, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f);
     894        if (ret == 6) {
     895                macaddr[0] = a; macaddr[1] = b; macaddr[2] = c;
     896                macaddr[3] = d; macaddr[4] = e; macaddr[5] = f;
     897                set_mac(macaddr);
     898
     899                return true;
     900        }
     901
     902        return false;
     903} // end set_mac(str)
     904
     905/** Set MAC address from byte array. */
     906void macaddress::set_mac(const uint8_t macaddr[6]) {
     907        memcpy(this->macaddr, macaddr, 6);
     908        initialized = true;
     909} // end set_mac(uint8_t)
     910
     911/** Get MAC address as a string. The output string is kept inside the
     912 *  macaddress object and should be copied if used for a longer time.
     913 */
     914const char* macaddress::get_mac_str() const
     915{
     916        if (initialized == false) {
     917                memset(outstring, 0, sizeof(outstring));
     918        }
     919        else {
     920                sprintf(outstring, "%02x:%02x:%02x:%02x:%02x:%02x",
     921                                macaddr[0], macaddr[1], macaddr[2],
     922                                macaddr[3], macaddr[4], macaddr[5]);
     923        }
     924
     925        return outstring;
     926} // end get_mac_str
     927
     928/** Get MAC address as a string.
     929 *  @param str string buffer
     930 */
     931void macaddress::get_mac_str(char *str) const
     932{
     933        if (str != NULL) {
     934                const char *src = get_mac_str();
     935
     936                strcpy(str, src);
     937        }
     938} // end get_mac_str(char*)
     939
     940/** Get MAC address as byte array.
     941 *  @param byte array
     942 */
     943void macaddress::get_mac(uint8_t macaddr[6]) const
     944{
     945        memcpy(macaddr, this->macaddr, 6);
     946} // end get_mac(uint8_t)
     947
     948bool macaddress::equiv(const macaddress& ma) const
     949{
     950        return operator==(ma);
     951}
     952
     953
    802954AddressList::AddrProperty *AddressList::LocalAddr_P;
    803955AddressList::AddrProperty *AddressList::ConfiguredAddr_P;
  • protlib/branches/20090610-qos-nslp-aho/src/messages.cpp

    r3346 r4468  
    8181        "QoS NSLP Client API over UDS",
    8282        "Mobility Service",
     83        "HandoverNotificationQueue",
    8384        "(INVALID)"
    8485}; // end qaddr_string
     
    9394        "RoutingMsg",
    9495        "APIMsg",
    95         "MobilityMsg"
     96        "MobilityMsg",
     97        "HandoverMsg"
    9698}; // end type_string
    9799
Note: See TracChangeset for help on using the changeset viewer.