1 /* 2 * Copyright (C) 2005 Hugo Santos <hugo@fivebits.net> 3 * $Id: dbeacon.h 399 2007-06-25 00:32:38Z hugo $ 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 */ 14 15 #ifndef _dbeacon_h_ 16 #define _dbeacon_h_ 17 18 #if __FreeBSD_version <= 500042 19 #include <inttypes.h> 20 #else 21 #include <stdint.h> 22 #endif 23 24 #include <string> 25 #include <map> 26 27 #include "address.h" 28 29 struct Stats { 30 Stats(); 31 32 uint64_t timestamp, lastupdate; 33 float avgdelay, avgjitter, avgloss, avgdup, avgooo; 34 bool valid; 35 uint8_t rttl; 36 37 void check_validity(uint64_t); 38 }; 39 40 struct beaconExternalStats { 41 beaconExternalStats(); 42 43 uint64_t lastupdate; 44 uint32_t age; 45 46 Stats ASM, SSM; 47 48 bool identified; 49 std::string name, contact; 50 }; 51 52 struct beaconMcastState { 53 beaconMcastState(); 54 55 uint32_t lastseq; 56 57 uint32_t packetcount, packetcountreal; 58 uint32_t pointer; 59 60 int lastdelay, lastjitter, lastloss, lastdup, lastooo; 61 62 Stats s; 63 64 #define PACKETS_PERIOD 40 65 #define PACKETS_VERY_OLD 150 66 67 uint32_t cacheseqnum[PACKETS_PERIOD+1]; 68 69 void refresh(uint32_t, uint64_t); 70 void update(uint8_t, uint32_t, uint64_t, uint64_t, uint64_t); 71 }; 72 73 typedef std::map<int, std::string> WebSites; 74 75 struct beaconSource { 76 beaconSource(); 77 78 address addr; 79 80 uint64_t creation; 81 82 int sttl; 83 84 uint64_t lastevent; 85 uint64_t lastlocalevent; 86 87 beaconMcastState ASM, SSM; 88 89 void setName(const std::string &); 90 void update(uint8_t, uint32_t, uint64_t, uint64_t, uint64_t, bool); 91 92 beaconExternalStats &getExternal(const address &, uint64_t now, uint64_t ts); 93 94 bool rxlocal(uint64_t now) const; 95 96 std::string name; 97 std::string adminContact; 98 std::string CC; 99 100 uint32_t Flags; 101 102 typedef std::map<address, beaconExternalStats> ExternalSources; 103 ExternalSources externalSources; 104 105 WebSites webSites; 106 107 bool identified; 108 }; 109 110 typedef std::map<address, beaconSource> Sources; 111 112 beaconSource &getSource(const address &, const char *name, uint64_t now, uint64_t recvts, bool rxlocal); 113 void removeSource(const address &, bool); 114 115 uint64_t get_timestamp(); 116 uint64_t get_time_of_day(); 117 118 enum content_type { 119 NPROBE, 120 NSSMPROBE, 121 SSMPING 122 }; 123 124 void ListenTo(content_type, int); 125 void SetupFDSet(int); 126 127 int SetupSSMPing(); 128 void handle_ssmping(int s, address &, const address &, uint8_t *, int, uint64_t); 129 130 extern const char * const defaultPort; 131 extern const int defaultTTL; 132 133 extern int forceFamily; 134 extern int mcastInterface; 135 136 struct beaconExternalStats; 137 138 extern uint32_t flags; 139 140 extern std::string beaconName, adminContact, twoLetterCC; 141 extern Sources sources; 142 extern WebSites webSites; 143 extern address beaconUnicastAddr; 144 145 extern int verbose; 146 147 void info(const char *format, ...); 148 void fatal(const char *format, ...); 149 150 #endif 151 152