00001
00029 #ifndef SELECTIVE_REPEAT_H
00030 #define SELECTIVE_REPEAT_H
00031
00032 #include <itpp/protocol/packet.h>
00033 #include <itpp/protocol/front_drop_queue.h>
00034 #include <itpp/base/vec.h>
00035 #include <itpp/base/array.h>
00036
00037
00038 namespace itpp
00039 {
00040
00042
00043
00047 class Selective_Repeat_ARQ_Sender
00048 {
00049 public:
00051 Selective_Repeat_ARQ_Sender();
00052
00054 Selective_Repeat_ARQ_Sender(const int Seq_no_size, const int Buffer_size_factor, const int Link_packet_size, const Ttype Time_out);
00055
00057 ~Selective_Repeat_ARQ_Sender();
00058
00060 void set_parameters(const int Seq_no_size,
00061 const int Buffer_size_factor,
00062 const int Link_packet_size,
00063 const Ttype Time_out);
00064
00065
00066 Slot<Selective_Repeat_ARQ_Sender, Packet*> packet_input;
00067 Slot<Selective_Repeat_ARQ_Sender, Array<Packet*> > ack_input;
00068 Slot<Selective_Repeat_ARQ_Sender, void*> query_nof_ready_packets;
00069 Slot<Selective_Repeat_ARQ_Sender, int> packet_output_request;
00070
00071
00072 Signal<Array<Packet*> > packet_output;
00073 Signal<int> nof_ready_packets;
00074 Signal<int> buffer_overflow;
00075
00077 int buffer_size();
00079 int link_packets_buffered();
00081 int nof_ready_link_packets();
00083 int link_packets_queued_waiting_for_transmission();
00085 Ttype link_packets_max_queuing_time();
00087 void get_link_packets(const int K, Array<Packet*> &pa);
00088
00089 private:
00090 void handle_ack_input(Array<Packet*> packet_array);
00091 void handle_packet_input(Packet *P);
00092 void handle_packet_output_request(int K);
00093 void handle_query_nof_ready_packets(void*);
00094 void retransmit(int Sequence_number);
00095 void remove(const int Sequence_number);
00096 void push_packet_on_tx_buffer(Packet *packet);
00097 int buffered_non_outstanding();
00098 int free_sequence_numbers();
00099 int sequence_number_2_buffer_index(const int Sequence_number);
00100 void schedule_output(const int Buffer_index, const int Sequence_number, const bool Retransmission);
00101 void cancel_output(const int Sequence_number);
00102 void fill_output();
00103 int feasable_blocks();
00104 bool parameters_ok;
00105 Front_Drop_Queue ip_pkt_queue;
00106 Array<Link_Packet*> input_buffer;
00107 int input_buffer_size;
00108 int input_next;
00109 int input_free_space;
00110 int seq_no_size;
00111 int seq_no;
00112 int seq_no_max;
00113 int tx_next;
00114 int tx_last;
00115 int outstanding;
00116 int id;
00117 Ttype time_out;
00118 Array<ATimer<Selective_Repeat_ARQ_Sender, int> > timer;
00119 ivec output_indexes;
00120 ivec retransmission_indexes;
00121 int rd_pos;
00122 int rt_pos;
00123 int scheduled_total;
00124 int scheduled_retransmissions;
00125 int no_retransmit;
00126 int link_packet_size;
00127 };
00128
00129
00133 class Selective_Repeat_ARQ_Receiver
00134 {
00135 public:
00137 Selective_Repeat_ARQ_Receiver();
00138
00140 Selective_Repeat_ARQ_Receiver(const int Seq_no_size);
00141
00143 ~Selective_Repeat_ARQ_Receiver();
00144
00145
00146 Slot<Selective_Repeat_ARQ_Receiver, Array<Packet*> > packet_input;
00147
00148
00149 Signal<Array<Packet*> > ack_output;
00150 Signal<Packet*> packet_output;
00151
00153 void set_parameters(const int Seq_no_size);
00154
00155 private:
00156 bool greater_modulo_L(const int a, const int b);
00157 void handle_packet_input(Array<Packet*>);
00158 int seq_no_size;
00159 int seq_no_max;
00160 Array<Link_Packet*> rx_buffer;
00161 int Rnext;
00162 int id;
00163 bool parameters_ok;
00164 };
00165
00167
00168 }
00169
00170 #endif // #ifndef SELECTIVE_REPEAT_H
00171