DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-stack-controller-phy.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2014 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
39
43static class UwMultiStackControllerPhyClass : public TclClass {
44public:
48 UwMultiStackControllerPhyClass() : TclClass("Module/UW/MULTI_STACK_CONTROLLER_PHY") {}
53 TclObject* create(int, const char*const*) {
54 return (new UwMultiStackControllerPhy);
55 }
57
58map< UwMultiStackControllerPhy::UWPHY_CONTROLLER_STATE, string> UwMultiStackControllerPhy::state_info;
59
61:
63receiving_id(0),
64current_state(UWPHY_CONTROLLER_STATE_IDLE)
65{
66 initInfo();
67}
68
75
76int UwMultiStackControllerPhy::command(int argc, const char*const* argv)
77{
78 Tcl& tcl = Tcl::instance();
79 if (argc == 2)
80 {
81 if(strcasecmp(argv[1], "getStatus") == 0)
82 {
83 tcl.resultf("%d", (int)(current_state));
84 return TCL_OK;
85 }
86 }
87
88 return UwMultiStackController::command(argc, argv);
89} /* UwMultiStackControllerPhy::command */
90
92{
93 int mac_addr = -1;
94 ClMsgPhy2MacAddr msg;
95 sendSyncClMsg(&msg);
96 mac_addr = msg.getAddr();
97 if (debug_)
98 {
99 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::recvSyncClMsg(ClMessage* m), state_info: "
101 }
102
103 if (m->direction() == DOWN)//mac2phy something
104 {
105 if (debug_)
106 std::cout << " direction = DOWN "<< std::endl;
107 m->setDest(lower_id_active_);
108 sendSyncClMsgDown(m);
109 return 0;
110 }
111 else if (m->type() == CLMSG_PHY2MAC_STARTRX)
112 {
113 if (debug_)
114 std::cout << " type = CLMSG_PHY2MAC_STARTRX "<< std::endl;
116 {
117 stateBusy2Rx(m->getSource());
118 sendSyncClMsgUp(m);
119 return 0;
120 }
121 else
122 {
123 if (debug_)
124 {
125 std::cout <<"ControllerPhy("<< mac_addr <<")::recvSyncClMsg(ClMessage* m), nothing done."<<std::endl;
126 }
127 return 0;
128 }
129 }
130 else
131 {
132 if (m->type() == CLMSG_PHY2MAC_ENDTX && current_state == UWPHY_CONTROLLER_STATE_BUSY_2_TX)
133 {
134 if (debug_)
135 std::cout << " endTx "<< std::endl;
136 stateIdle();
137 }
138 else {
139 if (debug_)
140 {
141 std::cout << " altro, ClMsg type = " << m->type() << std::endl;
142 }
143 }
144
145 sendSyncClMsgUp(m);
146 return 0;
147 }
148}
149
151{
152 int mac_addr = -1;
153 ClMsgPhy2MacAddr msg;
154 sendSyncClMsg(&msg);
155 mac_addr = msg.getAddr();
156 if (debug_)
157 {
158 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::stateIdle(), state_info: " << state_info[current_state]
159 << std::endl;
160 }
162 receiving_id = 0;
163}
164
166{
167 int mac_addr = -1;
168 ClMsgPhy2MacAddr msg;
169 sendSyncClMsg(&msg);
170 mac_addr = msg.getAddr();
171 if (debug_)
172 {
173 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::stateBusy2Rx(id), state_info: "
174 << state_info[current_state] << " phy_id = " << id << std::endl;
175 }
177 receiving_id = id;
178}
179
181{
182 int mac_addr = -1;
183 ClMsgPhy2MacAddr msg;
184 sendSyncClMsg(&msg);
185 mac_addr = msg.getAddr();
186 if (debug_)
187 {
188 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::stateBusy2Tx(), state_info: "
189 << state_info[current_state] << std::endl;
190 }
194}
195
196void UwMultiStackControllerPhy::recv(Packet *p, int idSrc)
197{
198 int mac_addr = -1;
199 ClMsgPhy2MacAddr msg;
200 sendSyncClMsg(&msg);
201 mac_addr = msg.getAddr();
202 hdr_cmn *ch = HDR_CMN(p);
203 if (ch->direction() == hdr_cmn::DOWN && current_state == UWPHY_CONTROLLER_STATE_IDLE)
204 {
205 //direction DOWN: packet is coming from upper layers
206 if(debug_)
207 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::recv(Packet *p, int idSrc) FromUpperLayer idSrc = "
208 << idSrc << std::endl;
209 stateBusy2Tx(p);
210 }
212 {
213 if(debug_)
214 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::recv(Packet *p, int idSrc) sendUp"
215 << std::endl;
216 sendUp(p, min_delay_);
217 stateIdle();
218 }
219 else {
220 if (debug_)
221 std::cout << NOW << " ControllerPhy("<< mac_addr <<")::recv(Packet *p, int idSrc) block direction = "
222 << ch->direction() << " idSrc = " << idSrc << std::endl;
223 //Packet::free(p);?
224 }
225}
Class that represents the binding with the tcl configuration script.
UwMultiStackControllerPhyClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
virtual void recv(Packet *p, int idSrc)
It manages each packet reception, either from the upper and the lower layer.
UwMultiStackControllerPhy()
Constructor of UwMultiPhy class.
static map< UWPHY_CONTROLLER_STATE, string > state_info
virtual void stateBusy2Tx(Packet *p)
Called when a node is transmitting a packet.
virtual void stateBusy2Rx(int id)
Called when a node is receiving correctely a packet from the lower layer.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
virtual int command(int, const char *const *)
TCL command interpreter.
int receiving_id
current receiving PHY ID
virtual void initInfo()
This function is used to initialize the UwMultiStackControllerPhy debugging info.
virtual void stateIdle()
Node is in Idle state.
Class used to represents the UwMultiStackController layer of a node.
int debug_
Flag to activate debug verbosity.
virtual int command(int, const char *const *)
TCL command interpreter.
int lower_id_active_
<Current switch mode (either AUTOMATIC or MANUAL).
virtual void recvFromUpperLayers(Packet *p)
By default the signaling is not employed, if it is needed, here where to set the signaling packet siz...
UwMultiStackControllerPhyClass class_uwmulti_stack_controller_phy
Definition of UwMultiStackControllerPhy class.