Accessing routing table from agent to get next hop - groovy

I've set up my routing algorithm from node itself. After this I want to send datagrams from physical layer in that route itself.
For example if my routes are 1 to 2 and 2 to 3 and I want to send a datagram from 1 to 3 I want my datagram to go through 2.
For this routing table for 1 will be as follows:
Routing table for 1
to: 3 nextHop: 2
to: 2 nextHop: 2
to: 1 nextHop: 1
So I want my process msg function to be as follows:
void processMessage(Message msg) {
if (msg instanceof DatagramNtf && msg.protocol == PING_PROTOCOL && msg.to != nodeInfo.addr)
def dG = new DatagramReq(to: routes.nextHop(msg.to), destination: msg.to)
send new DatagramReq(recipient: msg.sender, to: msg.from, protocol: Protocol.DATA)
}
also what routes.nextHop does is takes in the addr of the destination node and from the routing table gets the next hop.
I want to know to how to get the nextHop from routing table.

To send datagrams using route table entries, you need to use router agent, which inturn uses link and phy agents to send your datagram to the destination.Further routing of packets to the destination will be taken care by router agent itself.Hence I don't think you need to determine nextHop here for the to field in DatagramReq.
Your DatagramReq can be as-
router.send new DatagramReq(recipient: msg.sender, to: msg.from, protocol: Protocol.DATA)
Assuming router is the AgentID defined, and value of msg.from is your destination, and there is a valid route in the route table.
Further, nextHop or getNextHop() returns the address of neighbor node.

Related

How to Concatenate Multiple Message as one at the delivery by NodeJs SMPP

Hello im using Nodejs with farhadi node-smpp library to send Message through smpp v3.4 protocals and gsm library to split the message, In my case i have a long Message(More than 255 characters), when i split the message i want it to be delivered as single long message, but unfortunately it is delivered in parts. Here are my sample codes for sending the message
var info = gsm(text);
var concat_ref = Math.floor(Math.random() * 255);
var part_id = 0;
info.parts.forEach(function(part){
part_id++;
var udh = new Buffer.allocUnsafe(6);
udh.write(String.fromCharCode(0x5), 0); //Length of UDF
udh.write(String.fromCharCode(0x0), 1); //Indicator for concatenated message
udh.write(String.fromCharCode(0x3), 2); // Subheader Length ( 3 bytes)
udh.write(String.fromCharCode(concat_ref), 3); //Same reference for all concatenated messages
udh.write(String.fromCharCode(info.sms_count), 4); //Number of total messages in the concatenation
udh.write(String.fromCharCode(part_id), 5); //Sequence number ( used by the mobile to concatenate the split messages)
session.submit_sm({
source_addr: from,
destination_addr: to,
message_payload: { udh: part.udh, message: part }
}, function(pdu) {
console.log('sms pdu status', lookupPDUStatusKey(pdu.command_status));
if (pdu.command_status == 0) {
// Message successfully sent
console.log(pdu.message_id);
}
});
})
You can use the message_payload parameter (field name) as stated in the official SMPP's specification to send messages longer than 254 octets.
message_payload definition:
Contains the extended short message user data. Up to 64K octets can be
transmitted.
The official document says:
Applications which need to send messages longer than 254 octets should
use the message_payload parameter. In this case the sm_length field
should be set to zero.
The short message data should be inserted in either the short_message
or message_payload fields. Both fields must not be used
simultaneously.
I made a test with node-smpp, and it works. No need to concatenate.
It's not very clear what you mean by "i want it to be delivered as single long message".
But SMPP wise, what you are doing seems correct. Long messages are delivered in parts and they are concatenated by the terminal(phone) based on the three parameters : part_ref, part_number and total_parts. However, from my experience, the concatenation is not really standard across all devices. For instance, some devices don't wait long enough for all the parts to arrive and show incomplete messages or nothing at all.
You have 2 choices when sending concatenated sms via SMPP : One is what you used (UDH), but there are also TLV parameters dedicated for the 3 parameters. You could ask your SMPP provider about extra details on how they support the sending of concatenated messages.

How to add extra options to CoAP request?

I know that CoAP defines some options which can be included in the sending request and each option has their own number. The structure of the CoAP uri request looks like:
coap-URI = "coap:" "//" host [ ":" port ] path-abempty [ "?" query ]
where inside they include some options like: Uri-Host, Uri-Port, Uri-Path, and Uri-Query, and each of them has their own number, ex: 3 for Uri-Host, 11 for Uri Path.... . And I would like to add some more extra options to this CoAP request, for example some options number 256, 257...How can I do that?
Thank you in advanced
Son
I've managed to pass the Option Number 256.
CoapClient client = new CoapClient(...);
Request request = new Request(CoAP.Code.GET, CoAP.Type.NON);
OptionSet optionSet = new OptionSet();
optionSet.addOption(new Option(256, "admin:admin"));
request.setOptions(optionSet);
client.advanced(request); // or async version
client.shutdown();
At resource:
#Override
public void handleGET(CoapExchange exchange) {
OptionSet optionSet = exchange.advanced().getRequest().getOptions();
List<Option> options = optionSet.asSortedList();
options.stream()
.filter(o -> o.getNumber() == 256)
.findFirst()
.ifPresent(o -> System.err.println(o.getNumber() + " " + o.getStringValue()));
}
Output:
256 admin:admin
However, Option Number 256 may not be a proper choice in general:
RFC 7252 The Constrained Application Protocol (CoAP). 12.2. CoAP Option Numbers Registry
The IANA policy for future additions to this sub-registry is split
into three tiers as follows. The range of 0..255 is reserved for
options defined by the IETF (IETF Review or IESG Approval). The
range of 256..2047 is reserved for commonly used options with public
specifications (Specification Required). The range of 2048..64999 is
for all other options including private or vendor-specific ones,
which undergo a Designated Expert review to help ensure that the
option semantics are defined correctly. The option numbers between
65000 and 65535 inclusive are reserved for experiments. They are not
meant for vendor-specific use of any kind and MUST NOT be used in
operational deployments.

Zstack read attribute

I want to know how can I read some attribute on local and remote zigbee device using TI zstack and how to put its value to uart. I'm zstack beginner. I managed to use uart with usb to uart converter and can send data to my pc. So I need to know how to get the attribute data. I've read api manual but didn't anderstand how to use zcl_SendRead function. Thanks.
Follow section "3.3 Send Read" of the "Z-Stack ZCL API.pdf" this should contain enough info for getting the read attr to the correct destination device. The contents of the readCmd is an array of attribute ID's, specific to the attribute(s) you want to read. You will need to consult the ZCL specification or device documentation to determine the correct Attr ID and Cluster ID.
An example for sending a read attr is shown below. It reads the ATTRID_MS_TEMPERATURE_MEASURED_VALUE attribute (from the ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT cluster) from device with short address 0x1234 and endpoint 0x1.
afAddrType_t dstAddr;
dstAddr.addrMode = afAddr16Bit;
dstAddr.addr.shortAddr = 0x1234; //set this to correct address
dstAddr.addr.endPoint = 0x1; // set this to correct ep
zclReadCmd_t *cmd = osal_mem_alloc((sizeof zclReadCmd_t) + sizeof(uint16));
cmd->numAttr = 1;
cmd->attrID[0] = ATTRID_MS_TEMPERATURE_MEASURED_VALUE;
zcl_SendRead( SAMPLETHERMOSTAT_ENDPOINT, &dstAddr,
ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT,
&cmd, ZCL_FRAME_CLIENT_SERVER_DIR,
hdr->fc.disableDefaultRsp, hdr->transSeqNum );
Once this command is sent you need to process the received the response, you will notice that the functions are contained in the ZStack Sample Applications but not populated, for instance the SampleSwitch application has zclSampleSw_ProcessInReadRspCmd() function, this will be called to process the read attr response and you will need to populate it to do what you want to do with the response.
Regards,
TC.

getnameinfo returning numeric name with "%<interface>"

I'm using getnameinfo as follows:
ifaddrs *ifaddr = NULL, *ifa = NULL;
int rc, family, insize;
rc = getifaddrs(&ifaddr);
...
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
family = ifa->ifa_addr->sa_family
insize = (family == AF_INET) ?
(int)sizeof(struct sockaddr_in) :
(int)sizeof(struct sockaddr_in6);
char host[HOST_NAME_MAX];
rc = getnameinfo(ifa->ifa_addr, insize,
host, sizeof(host), NULL, 0, NI_NUMERICHOST);
}
...
When the function returns with an IPv6 address, it include the interface appended to the numeric IP address:
fe80::62a4:4cff:fe05:dc1b%eth0
What's the purpose of appending the interface to the numerical IP address?
Is there a flag available that controls the appending of the interface to the IP address?
fe80::* addresses are link-local in scope, which means the address is only valid for that particular network, the same address may reference a difference host on a different network. It is thus meaningless to specify a link-local address without specifying which network adapter. Also, DNS becomes rather meaningless outside of link-local scope such as provided by ZeroConf / multicast-DNS.
Unix hosts tend to specify the adapter by name, Windows hosts will specify the adapter by index. Note that Windows maintains separate interface indexes for IPv4 and IPv6.

Node.js Jade: Add rows to tables

I am using Node.js with the Jade template engine to create a test web page, to confirm that some features will work in the real project.
Depending on the first digit of the client's IP address, I want to render a Jade page with a table on it. The number of rows in the table is equal to that first digit from earlier. For example, if the client's address is 192.198.94.227, the table will have 1 row. If it is 92.61.131.242, the table will have 9 rows.
I know this sounds very silly, but I am only using this to test if I can add varying number of table rows for my real website.
Is there any way in Jade or Node.js code to represent this?
Or if I cannot do this, is there any work-around?
When you render a page using Jade template, you can provide a set of variables to the template.
This is exemplary express method handling '/example' request.
First argument of req.render specifies template name, the second argument (an object) specifies template parameters. In this case there are two parameters: ip (a customers IP) and ipFirstDigit - first digit of the customer IP address.
function remoteAddr(req) {
if (req.ip) {
return req.ip;
}
var socket = req.socket;
if (socket.socket) {
return socket.socket.remoteAddress;
}
return socket.remoteAddress;
};
app.get('/example', function(req, res){
var ip = remoteAddr(req);
res.render('index', { ip: ip, ipFirstDigit:ip.charAt(0) });
});
Jade template can looks as follows:
p Customer IP: #{ip}
p Customer IP first digit: #{ipFirstDigit}
table
- for (var i = 0; i < ipFirstDigit; i++)
tr
td #{i+1}
First two lines display customer IP and the first digit of the customer IP. Then a table is rendered depending on the first digit of the customer IP value.
Output for IP:92.61.131.242 is as follows:
<p>Customer IP: 92.61.131.242</p>
<p>Customer IP first digit: 9</p>
<table>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
</tbody>
</table>
I hope that will help with your prototype.
Actually, Jade is just a template engine. The right solution is to use JavaScript to modify DOM (Document Object Model). Think about Jade is just the structure for displaying your data. But before doing that, you need to manipulate those data first. Use Node.js to collect some necessary information, then use JavaScript (jQuery, AngularJS, etc.) to manipulate DOM in HTML template (with Jade).

Resources