28 return (!(*
this == other));
34 (ipc_ip == other.
ipc_ip) &&
55 if (!rv)
return false;
57 sprintf((
char*)
txBuf,
"cmd=%d,port=%d,ipaddr=%s,subnet=%s,gateway=%s",
58 (
int)
MB_CMD_SET_NET,(
int)port,ipaddr.c_str(),netmask.c_str(),gateway.c_str());
71 splitResponse(response, msg);
75 rv = getString(msg[0],
"status",status);
76 if (rv && (status ==
"OK"))
82 else if (rv && (status ==
"FAIL"))
105 if (!rv)
return false;
107 sprintf((
char*)
txBuf,
"cmd=%d,port=%d",
121 splitResponse(response, msg);
125 rv = getString(msg[0],
"status",status);
126 if (rv && (status ==
"OK"))
132 else if (rv && (status ==
"FAIL"))
165 splitResponse(response, msg);
169 rv = getString(msg[0],
"status",status);
170 if (rv && (status ==
"OK"))
174 else if (rv && (status ==
"FAIL"))
195 if (!rv)
return false;
200 rv = SendArpRequest(remote_IPAddress,port);
201 if (!rv)
return false;
204 eArpState as = GetRemoteMACFromArpTable(remote_IPAddress, port, stream, MACaddress);
225 eArpState CNTV2MBController::GetRemoteMACFromArpTable(std::string remote_IPAddress,
eSFP port,
NTV2Stream stream,
string & MACaddress)
230 sprintf(
reinterpret_cast<char*
>(
txBuf),
"cmd=%d,ipaddr=%s,port=%d,stream=%d",
232 remote_IPAddress.c_str(),
244 splitResponse(response, msg);
248 rv = getString(msg[0],
"status",status);
249 if (rv && (status ==
"OK"))
257 rv = getString(msg[2],
"MAC",MACaddress);
265 else if (rv && (status ==
"FAIL"))
271 rv = getDecimal(msg[3],
"state",state);
282 bool CNTV2MBController::SendArpRequest(std::string remote_IPAddress,
eSFP port)
287 sprintf((
char*)
txBuf,
"cmd=%d,ipaddr=%s,port=%d",
289 remote_IPAddress.c_str(),
301 splitResponse(response, msg);
305 rv = getString(msg[0],
"status",status);
306 if (rv && (status ==
"OK"))
315 else if (rv && (status ==
"FAIL"))
330 void CNTV2MBController::splitResponse(std::string response, std::vector<std::string> & results)
332 std::istringstream ss(response);
335 while(std::getline(ss, token,
','))
337 results.push_back(token);
341 bool CNTV2MBController::getDecimal(
const std::string & resp,
const std::string & parm, uint32_t & result)
344 bool rv = getString(resp,parm,val);
347 result = atoi(val.c_str());
353 bool CNTV2MBController::getHex(
const std::string & resp,
const std::string & parm, uint32_t & result)
356 bool rv = getString(resp,parm,val);
359 result = uint32_t(::strtoul(val.c_str(),
NULL,16));
365 bool CNTV2MBController::getString(
const std::string & resp,
const std::string & parm, std::string & result)
367 string match = parm +
"=";
369 std::string::size_type i = resp.find(match);
371 if (i != std::string::npos && i == 0)
374 result.erase(i, match.length());
382 uint32_t offset = getIGMPCBOffset(port, stream);
397 uint32_t offset = getIGMPCBOffset(port, stream);
408 uint32_t offset = getIGMPCBOffset(port, stream);
423 uint32_t CNTV2MBController::getIGMPCBOffset(
eSFP port,
NTV2Stream stream)
428 uint32_t multicast_addr;
429 uint32_t source_addr;
435 uint32_t reg = (index *
sizeof(IGMPCB))/4;
443 uint32_t chan = (uint32_t)channel;
446 if (sfp1Enable) val |= 0x2;
447 if (sfp2Enable) val |= 0x1;
452 if (!rv)
return false;
453 state &= ~( 0x3 << (chan * 2) );
461 uint32_t chan = (uint32_t)channel;
465 if (!rv)
return false;
466 state &= ( 0x3 << (chan * 2) );
467 state >>= (chan * 2);
468 sfp1Enable = (state & 0x02) ?
true :
false;
469 sfp2Enable = (state & 0x01) ?
true :
false;
476 uint32_t chan = (uint32_t)channel;
479 if (sfp1Enable) val |= 0x2;
480 if (sfp2Enable) val |= 0x1;
485 if (!rv)
return false;
486 state &= ~( (0x3 << (chan * 2)) << 8 );
494 uint32_t chan = (uint32_t)channel;
498 if (!rv)
return false;
500 state &= ( 0x3 << (chan * 2) );
501 state >>= (chan * 2);
502 sfp1Enable = (state & 0x02) ?
true :
false;
503 sfp2Enable = (state & 0x01) ?
true :
false;
509 uint32_t chan = (uint32_t)channel;
521 val &= ~( 0xff << (chan * 8));
522 val |= ( match << (chan * 8) );
537 uint32_t chan = (uint32_t)channel;
551 match = (uint8_t)val;
633 uint32_t shift = 8 * (int)chan;
636 state &= ~(0xff << shift);
637 state |= (uint8_t(fmt) << shift );
644 uint32_t shift = 8 * (int)chan;
647 state &= (0xff << shift);
661 uint64_t res = secsLo;
662 res = (res << 32) + nanosecs;
672 string sdp = sdpstream.str();
675 string to =
",";
676 size_t start_pos = 0;
677 while((start_pos = sdp.find(from, start_pos)) != std::string::npos)
679 sdp.replace(start_pos, from.length(), to);
680 start_pos += to.length();
683 int size = (int)sdp.size();
690 sprintf((
char*)
txBuf,
"cmd=%d,name=%s,sdp=%s",(
int)
MB_CMD_TAKE_SDP,filename.c_str(),sdp.c_str());
701 splitResponse(response, msg);
705 rv = getString(msg[0],
"status",status);
706 if (rv && (status ==
"OK"))
710 else if (rv && (status ==
"FAIL"))
747 splitResponse(response, msg);
751 rv = getString(msg[0],
"status",status);
752 if (rv && (status ==
"OK"))
754 rv = getString(msg[2],
"SDP",sdp);
761 string from =
",";
762 size_t start_pos = 0;
763 while((start_pos = sdp.find(from, start_pos)) != std::string::npos)
765 sdp.replace(start_pos, from.length(), to);
766 start_pos += to.length();
770 else if (rv && (status ==
"FAIL"))
801 splitResponse(response, msg);
805 rv = getString(msg[0],
"status",status);
806 if (rv && (status ==
"OK"))
809 rv = getString(msg[2],
"SFP",info);
815 if (info.size() != 129)
821 for (
int i=0; i < 128; i+=2)
828 uint8_t val = (uint8_t)strtol(buf,&
end,16);
829 sfpdata.
data[j++]= val;
833 else if (rv && (status ==
"FAIL"))
849 std::string &chassisId1, std::string &portId1)
865 splitResponse(response, msg);
869 rv = getString(msg[0],
"status",status);
870 if (rv && (status ==
"OK"))
872 rv = getString(msg[2],
"chassisId0",chassisId0);
878 rv = getString(msg[3],
"portId0",portId0);
884 rv = getString(msg[4],
"chassisId1",chassisId1);
890 rv = getString(msg[5],
"portId1",portId1);
898 else if (rv && (status ==
"FAIL"))
919 if (!rv)
return false;
935 splitResponse(response, msg);
939 rv = getString(msg[0],
"status",status);
940 if (rv && (status ==
"OK"))
945 else if (rv && (status ==
"FAIL"))