00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #ifndef TP_OVER_UDP_H
00035 #define TP_OVER_UDP_H
00036
00037 #include <ext/hash_map>
00038
00039 #include "tp.h"
00040 #include "threads.h"
00041 #include "threadsafe_db.h"
00042 #include "connectionmap.h"
00043 #include "assocdata.h"
00044
00045 namespace protlib
00046 {
00053 struct TPoverUDPParam : public ThreadParam
00054 {
00056 TPoverUDPParam(
00057 unsigned short common_header_length,
00058 bool (*const getmsglength) (NetMsg& m, uint32& clen_words),
00059 port_t listen_port,
00060 uint32 sleep = ThreadParam::default_sleep_time,
00061 bool debug_pdu = false,
00062 message::qaddr_t source = message::qaddr_tp_over_udp,
00063 message::qaddr_t dest = message::qaddr_signaling,
00064 bool sendaborts = false,
00065 uint8 tos = 0x10) :
00066 ThreadParam(sleep,"TPoverUDP",1,1),
00067 port(listen_port),
00068 debug_pdu(debug_pdu),
00069 source(source),
00070 dest(dest),
00071 common_header_length(common_header_length),
00072 getmsglength(getmsglength),
00073 terminate(false),
00074 ip_tos(tos)
00075 {};
00076
00078 const port_t port;
00079 bool debug_pdu;
00081 const message::qaddr_t source;
00082 const message::qaddr_t dest;
00084 const unsigned short common_header_length;
00085
00088 bool (*const getmsglength) (NetMsg& m, uint32& clen_words);
00089
00091 const bool terminate;
00092 const uint8 ip_tos;
00093
00094 bool (*rao_lookup) (uint32);
00095
00096
00097 };
00098
00099
00101
00102 class TPoverUDP : public TP, public Thread
00103 {
00104
00105 public:
00107 virtual void send(NetMsg* msg, const address& addr, bool use_existing_connection);
00108 virtual void terminate(const address& addr);
00109
00110
00111 public:
00113 virtual void main_loop(uint32 nr);
00114
00115
00116 public:
00118 TPoverUDP(const TPoverUDPParam& p) :
00119 TP(tsdb::getprotobyname("udp"),"udp",p.name,p.common_header_length,p.getmsglength),
00120 Thread(p), tpparam(p), already_aborted(false), msgqueue(NULL), debug_pdu(p.debug_pdu),
00121 master_listener_socket(-1)
00122 {
00123
00124
00125 init= true;
00126 }
00128 virtual ~TPoverUDP();
00129
00130 class sender_thread_start_arg_t
00131 {
00132 public:
00133 TPoverUDP* instance;
00134 FastQueue* sender_thread_queue;
00135
00136 sender_thread_start_arg_t(TPoverUDP* instance, FastQueue* sq) :
00137 instance(instance), sender_thread_queue(sq) {};
00138 };
00139
00140 int get_listener_socket() const { return master_listener_socket; }
00141
00142 private:
00143
00144
00146 void udpsend(NetMsg* msg, appladdress* addr);
00147
00149 static void* listener_thread_starter(void *argp);
00150
00152 void listener_thread();
00153
00155 void terminate_all_threads();
00156
00158 const TPoverUDPParam tpparam;
00159
00161 bool already_aborted;
00163 FastQueue* msgqueue;
00164
00165 bool debug_pdu;
00166
00167 int master_listener_socket;
00168
00169 };
00170
00175 class TPoverUDPMsg : public message
00176 {
00177 public:
00178
00179 enum msg_t { start,
00180 stop,
00181 send_data
00182 };
00183
00184 private:
00185 const AssocData* peer_assoc;
00186 const TPoverUDPMsg::msg_t type;
00187 NetMsg* netmsg;
00188 appladdress* addr;
00189
00190 public:
00191 TPoverUDPMsg(const AssocData* peer_assoc, message::qaddr_t source= qaddr_unknown, TPoverUDPMsg::msg_t type= stop) :
00192 message(type_transport, source), peer_assoc(peer_assoc), type(type), netmsg(0), addr(0) {}
00193
00194 TPoverUDPMsg(NetMsg* netmsg, appladdress* addr, message::qaddr_t source= qaddr_unknown) :
00195 message(type_transport, source), peer_assoc(0), type(send_data), netmsg(netmsg), addr(addr) {}
00196
00197 const AssocData* get_peer_assoc() const { return peer_assoc; }
00198 TPoverUDPMsg::msg_t get_msgtype() const { return type; }
00199 NetMsg* get_netmsg() const { return netmsg; }
00200 appladdress* get_appladdr() const { return addr; }
00201 };
00202
00203 }
00204
00205 #endif