libcyberradio 22.01.24
DataPort.cpp
1/***************************************************************************
2 * \file DataPort.cpp
3 * \brief Defines the 10GigE data port interface for an NDR551.
4 * \author DA
5 * \author NH
6 * \author MN
7 * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
8 *
9 ***************************************************************************/
10
11#include "LibCyberRadio/Driver/NDR551/DataPort.h"
12#include "LibCyberRadio/Driver/RadioHandler.h"
13#include <boost/format.hpp>
14
15
16namespace LibCyberRadio
17{
18
19 namespace Driver
20 {
21
22 namespace NDR551
23 {
24
27 bool debug,
28 const std::string& sourceIP) :
29 ::LibCyberRadio::Driver::DataPort(/* const std::string& name */ (boost::format("NDR551-DP%02d") % \
30 index).str(),
31 /* int index */ index,
32 /* RadioHandler* parent */ parent,
33 /* bool debug */ debug,
34 /* const std::string& sourceIP */ sourceIP,
35 /* int numDataPortDipEntries */ 64,
36 /* int dataPortDipEntryIndexBase */ 0)
37 {
38 this->debug("[NDR551::DataPort] index - %d\n", index);
39
41 }
42
46
49 {
50 }
51
53 {
54 ::LibCyberRadio::Driver::DataPort::operator=(other);
55 if ( this != &other )
56 {
57 }
58 return *this;
59 }
60
62 {
63 _config.clear();
64 _config["sourceIP"] = _sourceIP;
65 _config["sourcePort"] = _sourcePort;
66 _config["sourceMac"] = _sourceMacAddr;
67 }
69 {
70 Json::Value command;
71 Json::Value params;
72 command["cmd"] = "qcfge10g";
73 command["msg"] = _parent->getMessageId();
74 command["params"] = Json::objectValue;
75 command["params"]["link"] = _index;
76 Json::FastWriter fastWriter;
77 std::string output = fastWriter.write(command);
78 BasicStringList rsp = _parent->sendCommand(output);
79 Json::Reader reader;
80 Json::Value returnVal;
81 std::string t = rsp.at(0);
82 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
83 _sourceIP = boost::lexical_cast<std::string>(returnVal["result"]["ip"].asString());
84 _sourceMacAddr = boost::lexical_cast<std::string>(returnVal["result"]["mac"].asString());
85 _sourcePort = boost::lexical_cast<uint16_t>(returnVal["result"]["port"].asUInt());
86 for(int i = _dipEntryIndexBase; i < _numDipEntries; i++ )
87 {
88 this->executeDestIPQuery(_index, i, _ipAddresses[i],
89 _macAddresses[i],
90 _sourcePorts[i],
91 _destPorts[i]);
92 }
94 }
95
96 bool DataPort::executeSourceIPQuery(int index, std::string& ipAddr)
97 {
98 bool ret = false;
99 Json::Value command;
100 Json::Value params;
101 command["cmd"] = "qcfge10g";
102 command["msg"] = _parent->getMessageId();
103 command["params"] = Json::objectValue;
104 command["params"]["link"] = index;
105 Json::FastWriter fastWriter;
106 std::string output = fastWriter.write(command);
107 BasicStringList rsp = _parent->sendCommand(output);
108 Json::Reader reader;
109 Json::Value returnVal;
110 std::string t = rsp.at(0);
111 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
112 ret = returnVal["success"].asBool();
113 if(ret){
114 ipAddr = boost::lexical_cast<std::string>(returnVal["result"]["ip"].asString());
115 } else {
116 ipAddr = "0.0.0.0";
117 }
118 return ret;
119 }
120 bool DataPort::executeSourceIPCommand(int index, std::string& ipAddr)
121 {
122 bool ret = false;
123 Json::Value command;
124 Json::Value params;
125 command["cmd"] = "cfge10g";
126 command["msg"] = _parent->getMessageId();
127 command["params"] = Json::objectValue;
128 command["params"]["link"] = index;
129 command["params"]["ip"] = ipAddr.c_str();
130 Json::FastWriter fastWriter;
131 std::string output = fastWriter.write(command);
132 BasicStringList rsp = _parent->sendCommand(output);
133 Json::Reader reader;
134 Json::Value returnVal;
135 std::string t = rsp.at(0);
136 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
137 ret = returnVal["success"].asBool();
138 return ret;
139 }
140 // Default implementation uses the NDR308 pattern
142 int dipIndex,
143 std::string& ipAddr,
144 std::string& macAddr,
145 unsigned int& sourcePort,
146 unsigned int& destPort)
147 {
148 bool ret = false;
149 ipAddr = "";
150 macAddr = "";
151 sourcePort = 0;
152 destPort = 0;
153 if ( (_parent != NULL) && (_parent->isConnected()) &&
154 ( _macAddresses.find(dipIndex) != _macAddresses.end()) )
155 {
156 Json::Value command;
157 Json::Value params;
158 command["cmd"] = "qe10g";
159 command["msg"] = _parent->getMessageId();
160 command["params"] = Json::objectValue;
161 command["params"]["link"] = index;
162 command["params"]["dest"] = dipIndex;
163 Json::FastWriter fastWriter;
164 std::string output = fastWriter.write(command);
165 BasicStringList rsp = _parent->sendCommand(output);
166 Json::Reader reader;
167 Json::Value returnVal;
168 std::string t = rsp.at(0);
169 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
170 ret = returnVal["success"].asBool();
171 if(ret)
172 {
173 ipAddr = boost::lexical_cast<std::string>(returnVal["result"]["ip"].asString());
174 macAddr = boost::lexical_cast<std::string>(returnVal["result"]["mac"].asString());
175 //sourcePort = boost::lexical_cast<uint16_t>(returnVal["result"]["port"].asUInt());
176 sourcePort = 0;
177 destPort = boost::lexical_cast<uint16_t>(returnVal["result"]["port"].asUInt());
178 }
179 }
180 return ret;
181 }
183 int dipIndex,
184 std::string& ipAddr,
185 std::string& macAddr,
186 unsigned int& sourcePort,
187 unsigned int& destPort)
188 {
189 bool ret = false;
190 Json::Value command;
191 Json::Value params;
192 command["cmd"] = "e10g";
193 command["msg"] = _parent->getMessageId();
194 command["params"] = Json::objectValue;
195 command["params"]["link"] = index;
196 command["params"]["dest"] = dipIndex;
197 command["params"]["ip"] = ipAddr.c_str();
198 command["params"]["port"] = destPort;
199 command["params"]["mac"] = macAddr.c_str();
200 command["params"]["arp"] = false;
201 Json::FastWriter fastWriter;
202 std::string output = fastWriter.write(command);
203 BasicStringList rsp = _parent->sendCommand(output);
204 Json::Reader reader;
205 Json::Value returnVal;
206 std::string t = rsp.at(0);
207 bool parsingSuccessful = reader.parse( t.c_str(), returnVal ); //parse process
208 ret = returnVal["success"].asBool();
209 return ret;
210 }
211
212 } // namespace NDR551
213
214 } /* namespace Driver */
215
216} /* namespace LibCyberRadio */
217
218
219
220
221
222
virtual int debug(const char *format,...)
Outputs debug information.
virtual void updateConfigurationDict()
Updates the configuration dictionary from object settings.
Definition DataPort.cpp:312
bool executeDestIPCommand(int index, int dipIndex, std::string &ipAddr, std::string &macAddr, unsigned int &sourcePort, unsigned int &destPort)
Executes the destination IP set command.
Definition DataPort.cpp:182
bool executeDestIPQuery(int index, int dipIndex, std::string &ipAddr, std::string &macAddr, unsigned int &sourcePort, unsigned int &destPort)
Executes the destination IP query command.
Definition DataPort.cpp:141
virtual DataPort & operator=(const DataPort &other)
Assignment operator for DataPort objects.
Definition DataPort.cpp:52
DataPort(int index=0, ::LibCyberRadio::Driver::RadioHandler *parent=NULL, bool debug=false, const std::string &sourceIP="0.0.0.0")
Constructs a DataPort object.
Definition DataPort.cpp:25
virtual ~DataPort()
Destroys a DataPort object.
Definition DataPort.cpp:43
bool executeSourceIPCommand(int index, std::string &ipAddr)
Executes the source IP set command.
Definition DataPort.cpp:120
void queryConfiguration()
Updates the configuration dictionary from object settings.
Definition DataPort.cpp:68
bool executeSourceIPQuery(int index, std::string &ipAddr)
Executes the source IP query command.
Definition DataPort.cpp:96
void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Definition DataPort.cpp:61
Generic radio handler class.
Provides programming elements for driving NDR551 radios.
Definition DataPort.h:36
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
Definition App.h:24
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition BasicList.h:25