DESERT 3.5.1
Loading...
Searching...
No Matches
uwmulti-stack-controller-phy-slave.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 UwMultiStackControllerPhySlaveClass : public TclClass {
44public:
48 UwMultiStackControllerPhySlaveClass() : TclClass("Module/UW/MULTI_STACK_CONTROLLER_PHY_SLAVE") {}
53 TclObject* create(int, const char*const*) {
55 }
57
59:
61 signaling_recv_(0),
62 signaling_active_(0)
63{
64 bind("signaling_active_", &signaling_active_);
65}
66
67int UwMultiStackControllerPhySlave::command(int argc, const char*const* argv)
68{
69 Tcl& tcl = Tcl::instance();
70 if (argc == 2)
71 {
72 if(strcasecmp(argv[1], "signalingON") == 0)
73 {
75 return TCL_OK;
76 }
77 else if(strcasecmp(argv[1], "signalingOFF") == 0)
78 {
80 return TCL_OK;
81 }
82 else if(strcasecmp(argv[1], "getSignalsRecv") == 0)
83 {
84 tcl.resultf("%d", signaling_recv_);
85 return TCL_OK;
86 }
87 }
88 else if (argc == 3)
89 {
90 if(strcasecmp(argv[1], "setManualLowerlId") == 0)
91 {
92 lower_id_active_ = atoi(argv[2]);
93 slave_lower_layer_ = lower_id_active_; // first initialization of the automatic slave_lower_layer
94 return TCL_OK;
95 }
96 }
97 return UwMultiStackControllerPhy::command(argc, argv);
98} /* UwMultiStackControllerPhySlave::command */
99
100void UwMultiStackControllerPhySlave::recv(Packet *p, int idSrc)
101{
102 updateSlave(p,idSrc);
103 hdr_cmn* ch = hdr_cmn::access(p);
104 if (ch->ptype() == PT_MULTI_ST_SIGNALING) {
106 //Filippo: signaling con risposta
107 if (signaling_active_) {
108 hdr_mac* mach = HDR_MAC(p);
109 int my_mac_addr = -1;
110 ClMsgPhy2MacAddr msg;
111 sendSyncClMsg(&msg);
112 my_mac_addr = msg.getAddr();
113 if (mach->macDA() == my_mac_addr || mach->macDA() == MAC_BROADCAST) {
114 mach->macDA() = mach->macSA();
115 mach->macSA() = my_mac_addr;
116 sendDown(lower_id_active_, p, min_delay_);
117 }
118 }
119 else
120 Packet::free(p);
121
122 if (debug_)
123 {
124 std::cout << NOW << " ControllerPhySlave::recv(Packet *p, int idSrc) signaling "<< ch->ptype() << " " << PT_MULTI_ST_SIGNALING<< std::endl;
125 }
126 }
127 else
129}
130
132 if (m->type() == CLMSG_PHY2MAC_ENDTX)
133 {
134 hdr_cmn* ch = hdr_cmn::access( static_cast<ClMsgPhy2MacEndTx *>(m)->pkt);
135 if (ch->ptype() == PT_MULTI_ST_SIGNALING)
136 return 0;
137 }
138 else if (m->type() == CLMSG_PHY2MAC_STARTRX)
139 {
140 hdr_cmn* ch = hdr_cmn::access( static_cast<ClMsgPhy2MacStartRx *>(m)->pkt);
141 if (ch->ptype() == PT_MULTI_ST_SIGNALING)
142 return 0;
143 }
145}
146
149
150 int mac_addr = -1;
151 ClMsgPhy2MacAddr msg;
152 sendSyncClMsg(&msg);
153 mac_addr = msg.getAddr();
154
155 if (debug_)
156 {
157 std::cout << NOW << " ControllerPhySlave("<< mac_addr <<")::getBestLayer(Packet *p) "<< std::endl;
158 }
160
161 return slave_lower_layer_;
162 }
163
165{
166 int mac_addr = -1;
167 hdr_mac* mach = HDR_MAC(p);
168 ClMsgPhy2MacAddr msg;
169 sendSyncClMsg(&msg);
170 mac_addr = msg.getAddr();
171 if (mach->macDA() == mac_addr || mach->macDA() == MAC_BROADCAST)
172 {
173 if (debug_)
174 {
175 std::cout << NOW << " ControllerPhySlave("<< mac_addr <<")::updateSlave "
176 << msg.getAddr() << ": " << slave_lower_layer_ << " --> " << idSrc << std::endl;
177 }
178 slave_lower_layer_ = idSrc;
179 }
180}
Class that represents the binding with the tcl configuration script.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
Class used to represents the UwMultiStackControllerPhySlave layer of a node.
virtual void updateSlave(Packet *p, int idSrc)
It implements the slave choice rule to choose the lower layer when the system works in AUTOMATIC_MODE...
int signaling_active_
Number of signaling packets received.
virtual void recv(Packet *p, int idSrc)
It manages each packet reception, either from the upper and the lower layer.
virtual int command(int, const char *const *)
TCL command interpreter.
virtual int getBestLayer(Packet *p)
If true slave is in signaling mode, otherwise not.
int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
UwMultiStackControllerPhySlave()
Constructor of UwMultiPhy class.
virtual void recv(Packet *p, int idSrc)
It manages each packet reception, either from the upper and the lower layer.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
virtual int command(int, const char *const *)
TCL command interpreter.
int debug_
Flag to activate debug verbosity.
@ UW_AUTOMATIC_SWITCH
State to switch-mode automatically.
int lower_id_active_
<Current switch mode (either AUTOMATIC or MANUAL).
UwMultiStackControllerPhySlaveClass class_uwmulti_stack_controller_phy_slave
Definition of UwMultiStackControllerPhySlave class.