60 : TclClass(
"Module/UW/TDMA_FRAME")
84 , topology_S_file_name_(
"")
85 , topology_S_token_separator_(
',')
106 std::cout << NOW <<
" ID:" << addr
111 int num_jumping_slots =
113 num_jumping_slots = num_jumping_slots > 0
116 double nextSlotTime =
121 std::cout << NOW <<
" Off ID " << addr <<
" " << nextSlotTime <<
""
125 <<
"::TDMA_node(" << addr <<
")::Off timeslot "
134 Tcl &tcl = Tcl::instance();
136 if (strcasecmp(argv[1],
"start") == 0) {
138 std::cout <<
"Error: the near far tdma works only in fair mode"
143 std::cout <<
"Error: number of slots set to 0, please, "
144 "initialize the topology"
150 std::cout <<
"Error: guard time or frame set incorrectly"
160 }
else if (strcasecmp(argv[1],
"stop") == 0) {
164 }
else if (argc == 3) {
165 if (strcasecmp(argv[1],
"setSlotNumber") == 0) {
166 std::cout <<
"Use near far topology!!" << std::endl;
168 }
else if (strcasecmp(argv[1],
"setTopologyIndex") == 0) {
171 }
else if (strcasecmp(argv[1],
"setSTopologyFileName") == 0) {
172 string tmp_ = ((
char *) argv[2]);
173 if (tmp_.size() == 0) {
174 fprintf(stderr,
"Empty string for the file name");
180 }
else if (strcasecmp(argv[1],
"setTopologySeparator") == 0) {
181 string tmp_ = ((
char *) argv[2]);
182 if (tmp_.size() == 0) {
183 fprintf(stderr,
"Empty char for the file name");
201 std::cout << NOW <<
" ID:" << addr <<
" Slot Pos:" << pos << std::endl;
202 for (
int i = 0; i < pos; i++) {
214 std::cout << NOW <<
" ID:" << addr <<
" Pos:" << pos << std::endl;
215 for (
int i = 0; i < pos; i++) {
225 ifstream input_file_;
229 input_file_.open(tmp_);
237 if (input_file_.is_open()) {
238 while (std::getline(input_file_, line_)) {
239 ::std::stringstream line_stream(line_);
245 int tx_status = atoi(result_.c_str());
265 std::cout << NOW <<
" ID " << addr
266 <<
": Topology S initialized, tot_nodes = " <<
tot_nodes
267 <<
", Slots in a frame = " <<
tot_slots << std::endl;
Class that represent the binding of the protocol with tcl.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
TDMA_FRAMEModuleClass()
Constructor of the TDMAGenericModule class.
Class that represents a TDMA_frame MAC layer of a Node.
Slot::iterator getCurrentSlot()
virtual void changeStatus()
Alternate TDMA status between MY_STATUS and NOT_MY_STATUS.
SlotTopology s_
matrix cointaining the transmission schedule of all the network
virtual ~UwTDMA_frame()
Destructor of the TDMA_frame class.
int topology_index
index in the topology matrix
string topology_S_file_name_
Topology S file name.
virtual void initializeTopologyS()
Initialize the topology S 2D matrix from file.
char topology_S_token_separator_
character used as token separator when importing the S topology from file
UwTDMA_frame()
Constructor of the TDMA_frame class.
Slot::iterator getNextMySlot(int skip=0)
int tot_nodes
total number of nodes in the network
int my_slots_counter
count the passed number of slots in which it was active
Slot my_slot_numbers_
set the position of the node in the frame (fair_mode) (starting from 0 to tot_slots-1)
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
int packet_sent_curr_slot_
counter of packet has been sent in the current slot
Class that represents a TDMA Node.
virtual void start(double delay)
Schedule the beginning of each TDMA cycle, each one after delay.
int tot_slots
Number of slots in the frame (fair_mode)
double guard_time
Guard time between slots.
int sea_trial_
Written log variable.
int debug_
Debug variable: 0 for no info, >-5 for small info, <-5 for complete info.
int fair_mode
Fair modality on if 1: then only set tot_slots and common guard_time.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
UwTDMATimer tdma_timer
TDMA timer handler.
std::ofstream out_file_stats
File stream for the log file.
virtual void stop()
Terminate a TDMA cycle, essentially cancel the TDMA timer.
unsigned long int getEpoch()
Calculate the epoch of the event.
double frame_duration
Frame duration.
double start_time
Time to wait before starting the protocol.
int slot_status
Is it my turn to transmit data?
virtual void changeStatus()
Alternate TDMA status between MY_STATUS and NOT_MY_STATUS.
double slot_duration
Slot duration.
int slot_number
set the position of the node in the frame (fair_mode) (starting from 0 to tot_slots-1)
TDMA_FRAMEModuleClass class_uwtdma
Provides the definition of the class UWTDMA_FRAME.
#define UW_TDMA_STATUS_NOT_MY_SLOT
Status slot not active >
#define UW_TDMA_STATUS_MY_SLOT
Status slot active>