Programming routing protocol for MANet in Java(UDP) - java

I'm programming mobile ad hoc network routing protocol in JAVA (using UDP). That routing protocol consists of ring topology (each node as one predecessor node and one successor node).
First, I've combined one transmitter (one thread) and one receiver (one thread) to form one node. But, I'm facing some problems like:
I'd that a third node could listen transmission from one node to another node. Per example,
node A sends a packet to node B, and if node C is in the range of node A then it might listen that transmission too.
I'd set one channel per ring to reduce interference. But, I don't know which java network API mechanism I should use.
I'd have your guidance.
Thank you in advance (sorry for my poor english)!

Per example, node A sends a packet to node B, and if node C is in the range of node A then it might listen that transmission too.
This is expected behavior for wireless ad-hoc network. If C is not destination (according to MAC-address) you can drop received message.
I'd set one channel per ring to reduce interference.
One channel per ring would oppositely increase interference, especially if you expect high load and many messages being routed around. But it is much easier to manage single channel.
You need to think more what is your environment and requirements.
Are you using 802.11 at MAC level?
Do you want reliable guaranteed delivery?

Related

Initiator nodes in a distributed system

I've got an assignment to find out the all possible initiator nodes for a state recording algorithm in the distributed system.
The question that has been given exactly is
"Write a program to find out the all possible initiator nodes for a state recording algorithm in a distributed system.".
I want to mentioned that we have studied Chandy - Lamport's global state recording algorithm on our course of distributed operating system. I wrote a code for Chandy - Lamport's global state recording algorithm for the another assignment.
What does this initiator node signifies? I thought that those nodes who have recorded their corresponding states. Am I right? I've to write the code in java. Please suggest me the approach or an algorithm to follow.
According to the Wikipedia page on the Chandy-Lamport algorithm:
The assumptions of the algorithm are as follows:
There are no failures and all messages arrive intact and only once
The communication channels are unidirectional and FIFO ordered
There is a communication path between any two processes in the system
Any process may initiate the snapshot algorithm
The snapshot algorithm does not interfere with the normal execution of the processes
Each process in the system records its local state and the state of its incoming channels
The algorithm works using marker messages. Each process that wants to
initiate a snapshot records its local state and sends a marker on each
of its outgoing channels. All the other processes, upon receiving a
marker, record their local state, the state of the channel from which
the marker just came as empty, and send marker messages on all of
their outgoing channels. If a process receives a marker after having
recorded its local state, it records the state of the incoming channel
from which the marker came as carrying all the messages received since
it first recorded its local state.
You are using slightly different terminology to the Wikipedia description, but I assume that your "nodes" correspond to the "processes" in the above. Thus an "initiator node" is a simply a node that initiates (requests) a snapshot.
If that is what your terminology means, then with the Chandy-Lamport algorithm, any node could be an initiator node. Hence the answer to the question is "all of them".
But, given the trivial nature of the answer / solution, I suspect that is not what your assignment really means. Either you have left out some context, or the assignment is misstated. I suggest that you ask your instructor.
(Or ... maybe it is a "trick question".)

how can we get the number of concurrent active streams in a cluster?

I work with java sockets and I transfer data between nodes of the cluster, the trasfer can be tree braodcast (master sends data to some nodes and they send received data to the rest ), chain broadcast (master sends data to all the workers sequentially), shuffle (all the nodes exchange data simultaneouly)
the trasnfers are simply a stream between 2 nodes (master-worker or worker-worker) using java serverSocket and socket communication.
how can I determine the number of concurrent flows (active stream in the cluster) so I can schedule these flows and give every flow a part of the network
network bandwidth is 1 gb/s
socket buffer is 8192-byte
here is an illustration
The best you will be able to do is to maintain your own data structure recording the "flows" and then count them.
The Java APIs don't provide a way to find or count all open sockets, or determine which ones are currently active. It is probably not tractable even at the native code level. And that is only within a single JVM: you presumably have multiple JVMs in your cluster.

How to create a connection to the node where queue is created in, RabbitMQ

We will have a a clusters, say 3 nodes, now we will pass three addresses to create a connection:
factory.newConnection(consumerExecutor, addresses, clinetProviedName);// addresses has three elements
Questions:
1 .Since a queue is created in only one node which is master say nodeA. So if I create a connection to nodeB, does RabbitMQ need to redirect every publish requests to the nodeA from nodeB?
2. Will the same things happen to consumers?
3. Does Redirect makes a big difference on performance when qps is high? We need tens of thousands qps to support our app.
4. If #1 is right, how can I connect to the exactly right node to reduce redirect.
The RabbitMQ team monitors this mailing list and only sometimes answers questions on StackOverflow.
Yes
Yes
No, but your benchmarks and monitoring will definitively answer it. You do have benchmarks and monitoring, right?
It isn't worth the hassle. The Spring AMQP library does have a node affinity feature if you really think it's worth it.

How to limit the scope of multicast explicitly to 1 hop only?

It's my first question here, so my apologies if I asked wrongly.
In my experiment, multiple android devices are connected using WiFi Direct. To make use of the broadcast nature of wireless tx, all the devices join a single multicast group to exchange their information. My intention is to let the sender send only one copy of its information, while all the 1-hop neighbors receives it.
My trouble is, nodes further away are also receiving it.
Consider the example:
A----B----C
at the same time:
A----D
1) connection is done by wifi direct;
2) they join a single multicast group for message exchange.
What I want: if A sends, B and D can receive, not C; if B sends, A and C can receive, not D. Basically the so-called "1-hop broadcast".
What I get: if A sends, B and D receives, B helps relay it (due to mac layer multicast established by udp multicast I guess?) so C also receives it.
I did some search, multicastSocket has a setTimeToLive() method, with parameters as:
0: not sent on network, only local use;
1: only local network, not going through router;
...
But I somehow need something between 0 and 1, so I can limit the tx to only 1-hop. I couldn't find a solution to this.
You might ask why I need to limit the scope. That's for preventing the flooding, thus reducing network resource consumption.
You might ask why not using unicast to each neighbors. This has a scalability issue in terms of neighbor set cardinality, which should be efficiently solved by multicast/broadcast. Unless wifi direct actually "simulates" multicast/broadcast using unicast at mac layer?
You might also ask why don't I create one distinct multicastSocket for each node to let his neighbors join. I have thought about this, but not sure about the complexity of managing all those sockets.
Sorry for having written so long. I'm looking forward for any suggestion.
EDIT:
--- We tried to setTimeToLive(1), but nodes 2 hops away from a sender can still receive the message.
--- We checked the default TTL and confirmed the default value is already 1.
--- My feeling is that TTL doesn't decrease as it goes from hop to hop, it merely limits the transmission within a "local network" i.e., not going through routers. With wireless nodes connected by WiFi Direct, the network may be treated as a single "local network", hence the relay to all multicast group members.
--- So I doubt if there is any way to explicitly limit the transmission hop counts for a multicastSocket.
--- My two UGLY backup plans are:
1) unicast from a sender to each of its 1-hop neighbors; or
2) each node maintains its own multicastSocket, to let each of its neighbors to join. So nodes 2-hops away will join different multicast groups.
But both solutions will cause the creation and close of lots of sockets, and are subject to the scalability issue (i.e., density).
Can anyone suggest any better solutions to do this? Basically the key target is: implement the 1-hop broadcast functionality for wireless nodes to share local information to its 1-hop neighbors.
Best
Zhang Bo
In C, you have to set the socket option for TTL (Time to Live):
u_char ttl;
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,sizeof(ttl))
In java you have different options:
MulticastSocket.setTimeToLive: http://docs.oracle.com/javase/7/docs/api/java/net/MulticastSocket.html#setTimeToLive(int)
Other options:
Use StandardSocketOptions class to set socket options: http://docs.oracle.com/javase/7/docs/api/java/net/StandardSocketOptions.html#IP_MULTICAST_TTL
To use StandardSocketOptions you need to work with DatagramChannel:
http://docs.oracle.com/javase/7/docs/api/java/nio/channels/DatagramChannel.html
DatagramChannel channel = DatagramChannel.open();
int ttlValue = 1;
channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttlValue);

cross thread communication java

So I am new to Java, I have done a bit of c programming.
I am trying to make a virtual network of nodes, each node would need to be a thread.
The nodes are only allowed to talk to their neighbor nodes.
there will be a master node that can talk to any node but the nodes would have to talk to each other to get back to the master node. the master nodes neighbors can talk to the master node.
I was originally going to keep an array list of the nodes, but then I realized all the nodes needed to be there own thread.
My question is how do I pass information back in forward between threads in Java.
I need to be able to have the master node give all the regular nodes position information.
and I need the regular nodes to be able to pass messages to their neighbor regular nodes.?
here are my git repos if you would like to look at the code I got going now.
https://github.com/fieldju/cs372_project
in C I made a program that used pipes for the children to talk to each other and a server connected the clients, but in this problem the nodes to to have p2p communication as most of them can not directly communicate to the master node / server
Just an Update for anyone who looks at this and wants to see the results. I got the nodes up and running and communicating you can check out the code at
https://github.com/fieldju/cs372_project
I am still working on the distance vector stuff and a few other things but by the end of next week the entire thing should be done.
I was originally going to keep an
array list of the nodes, but then I
realized all the nodes needed to be
there own thread.
You can keep an array of threads, it would still maintain a thread-per-node with the same logic structure.
how do I pass information back in
forward between threads in Java.
If threads reside in the same process then definitely sockets are an overkill. I would use one or several ConcurrentLinkedQueue instances to push/pop messages.
One or several really depends on the kind of communication that you are implementing. Maybe one ConcurrentLinkedQueue per node, so nodes push messages to queues and every node knows where from to pop the message.
Few hints for implementation
Wrap up all the logic to en-route messages in a class - let's call this class VirtualNetwork. VirtualNetwork deals with all the instances of ConcurrentLinkedQueue and offers an API of methods to all threads for sending/receiving messages. Make one instance of the class VirtualNetwork accessible to all nodes - by passing a reference to it on the Thread constructor.
This is an sketch of how your class NodeThread would be. Notice that the classes VirtualNetwork and Message are classes that you have to implement your self.
class NodeThread extends Thread {
private int nodeId;
private VirtualNetwork network;
public NodeThread(int nodeId,VirtualNetwork network) {
this.network = network;
this.nodeId = nodeId;
}
public void run() {
/* when you have to send */
int nodeReceptor = this.nodeId -1; /* neighbor in the array of threads */
Message m = new Message(this.nodeId,nodeReceptor);
m.setContent(10);
network.send(m);
/* when you have to receive */
Message m = network.receive(this.nodeId);
/* it's your decision to implement this in a blocking way or not */
}
}
An easy (if not optimal) way to start is to create a BlockingQueue for each pair of threads that need to pass values in one direction (if it's bidirectional you need twice as many.)
You could definitely use Sockets. There are a couple of tutorials/descriptions here and here. Your description of the project suggests a client/server setup would work well since you have a central "master node". The master will be the server and the other threads will be able to connect to the master/server to receive their updates.

Categories