Hi all,
I'm really having trouble with this been going in circles for days some fresh insight would really help.
Basic idea - is i have n nodes that have m ports that connect by links to other nodes each port has 1 link to an adjacent node. my idea has to been to create at an adjacency list style graph (potentially were im having trouble).
I have created a node that has an array of ports, a link class that connects 2 ports from adjacent nodes. i also have an entry class which represents the data (destination nodeID, next-hop nodeID, exit portID, distance value(hop-count))in each slot of the routing table must get to destination hop by hop.
my problem is when i try update the routing tables to contain an entry's for every other node in the network. here is how it should work
1.Broadcast new or last updated entries in the routing table to all ports.
2.Receive update entries from all ports, discard any route with the local node as destination. replace the Exit Port ID with the local port ID from which the entry was received, and add 1 to all Distance Values.
3.If a route update from 2) contains new destination not yet included in the routing table, create a new entry.
4.If a route update from 2) contains destination already exists in the routing table, create a new entry only if the Distance Value is smaller than the existing entry.
5.For each new entry created in 3) or 4), replace the Next-Hop ID with the respective
adjacent node ID if it is not.
6. Repeat 1)-5) until convergence (no new entries for all nodes).
i think my problem is shared memory of objects. when i receive an update and increment count it updates for all other nodes so for example when node 2 receives new entry's all should have +1 to distance but it does it for all my nodes(8) i have distance of 8 for every entry on every node. and i'm also have trouble with the main concept of this route discovery like how to stop once its achieved.
last thing it runs on a epoch by epoch basis so it does one loop of the above per epoch the repeat until convergence is the number of epochs to reach it.
thanks for reading and any help =]
here is my code should be a link too.
node class:
public class node
{
public int nodeID;
public port[] ports = new port[10]; //node has list(ports) of node connections
public LinkedList <Entry> routingTable = new LinkedList<Entry>();
private Entry[] newReceivedEntrys = new Entry[10];
private int receivedEntryCounter = 0;
private int portCount = 1;
public class port
{
private int portID;
private link adjacent;
private int parentNode;
public port(int ID)
{
portID = ID;
setparentNode();
}
public void setPortID(int item)
{
this.portID = item;
}
public void setparentNode()
{
parentNode = nodeID;
}
public int getPID()
{
return portID;
}
public int getNID()
{
return parentNode;
}
public void makelink(link newEdge)
{
adjacent = newEdge;
}
public void entryReceive(Entry newEntry)
{
newEntry.setExitPort(getPID());
newEntry.addDistance();
if(newEntry.getDestination() == getNID())
{}
else
{newReceivedEntrys[receivedEntryCounter++] = newEntry;}
}
public void sendEntry(Entry newEntry, int index)
{
ports[index].adjacent.to.entryReceive(newEntry);
}
}
public node(int ID)
{
nodeID = ID; //stores ID of the node
}
public void setNodeID(int item)
{
this.nodeID = item;
}
public int getID()
{
return nodeID;
}
public void addlink(node.port a, node.port b)
{
link newlink = new link(a,b);//create a new edge to adjacent nodes
link newlink2 = new link(b,a);
a.makelink(newlink);
b.makelink(newlink2);
}
public void addport(int PID)
{
port e = new port(PID);
ports[PID] = e;
portCount++;
//int index = ports.indexOf(e);
//PortID[e.portID] = index;
}
public void addEntry(Entry newEntry)
{
routingTable.add(newEntry);
}
public void broadcast()
{
Entry entry = new Entry(0,0,0,0);
for(int i=1;i<portCount;i++)
{
for(int j=0;j<routingTable.size();j++)
{
Entry current = routingTable.get(j);
if(current.getEntryUpdate() == true)
{
entry = current;
ports[i].sendEntry(entry,i);
}
}
}
}
public void routDiscover()
{
for(int i=0; i<receivedEntryCounter;i++)
{
Entry newEntry = newReceivedEntrys[i];
int found = find(newEntry);
if(found == -1)
{
if(newEntry.getDistance() < routingTable.get(i).getDistance())
{
routingTable.remove(i);
routingTable.add(newEntry);
}
}
else
{
routingTable.add(newEntry);
}
routingTable.getLast().setNextHop(1);
}
}
public int find(Entry newEntry)
{
int found = -1;
for(int i=0;i<routingTable.size();i++)
{
//System.out.println(routingTable.get(i).toString());
//System.out.println(newEntry.toString());
if(routingTable.get(i).equals(newEntry))
{
System.out.println("5");
found = routingTable.indexOf(i);
}
}
return found;
}
}
link class:
public class link
{
//simple edge class has 2 values of from vertex and to vertex
public node.port from;
public node.port to;
public String label; //label = speed
//link constructor
public link(node.port p, node.port n)
{
from = p;
to = n;
}
public void setLabel(String a)
{
label = a;
}
public String getLabel()
{
return label;
}
}
entry class:
package attempt2;
public class Entry {
private int Destination;
private int NextHop;
private int ExitPort;
private int Distance;
private boolean entryUpdate = false;
public Entry(int destination, int nexth, int eport, int dist)
{
Destination = destination;
NextHop = nexth;
ExitPort = eport;
Distance = dist;
entryUpdate = true;
}
public void setDestination(int dest)
{
this.Destination = dest;
}
public int getDestination()
{
return Destination;
}
public void setNextHop(int ID)
{
this.NextHop = ID;
}
public int getNextHop()
{
return NextHop;
}
public void setExitPort(int pNo)
{
this.ExitPort = pNo;
}
public int getExitPort()
{
return ExitPort;
}
public String toString()
{
String x = ""+ getDestination() + getNextHop() + getExitPort() + getDistance();
return x;
}
public int addDistance() {
Distance = Distance + 1;
return this.Distance;
}
public int getDistance() {
return Distance;
}
public boolean setEntryUpdate(boolean entryUpdate) {
this.entryUpdate = entryUpdate;
return entryUpdate;
}
public boolean getEntryUpdate() {
return entryUpdate;
}
}
main class:
public void starSim(int setting1, int setting2)
{
node node1 = new node(1);
node node2 = new node(2);
node node3 = new node(3);
node node4 = new node(4);
node node5 = new node(5);
node node6 = new node(6);
node node7 = new node(7);
node node8 = new node(8);
node1.addport(1);
node1.addport(2);
node1.addport(3);
node1.addport(4);
node1.addport(5);
node1.addport(6);
node1.addport(7);
node2.addport(1);
node3.addport(1);
node4.addport(1);
node5.addport(1);
node6.addport(1);
node7.addport(1);
node8.addport(1);
node1.addlink(node1.ports[1], node2.ports[1]);
node1.addlink(node1.ports[2], node3.ports[1]);
node1.addlink(node1.ports[3], node4.ports[1]);
node1.addlink(node1.ports[4], node5.ports[1]);
node1.addlink(node1.ports[5], node6.ports[1]);
node1.addlink(node1.ports[6], node7.ports[1]);
node1.addlink(node1.ports[7], node8.ports[1]);
node1.routingTable.add(new Entry(2,2,1,1));
node1.routingTable.add(new Entry(3,3,2,1));
node1.routingTable.add(new Entry(4,4,3,1));
node1.routingTable.add(new Entry(5,5,4,1));
node1.routingTable.add(new Entry(6,6,5,1));
node1.routingTable.add(new Entry(7,7,6,1));
node1.routingTable.add(new Entry(8,8,7,1));
node2.routingTable.add(new Entry(1,1,1,1));
node3.routingTable.add(new Entry(1,1,1,1));
node4.routingTable.add(new Entry(1,1,1,1));
node5.routingTable.add(new Entry(1,1,1,1));
node6.routingTable.add(new Entry(1,1,1,1));
node7.routingTable.add(new Entry(1,1,1,1));
node8.routingTable.add(new Entry(1,1,1,1));
for(int i=0;i<setting1;i++)
{
node1.broadcast();
node2.broadcast();
node3.broadcast();
node4.broadcast();
node5.broadcast();
node6.broadcast();
node7.broadcast();
node8.broadcast();
node1.routDiscover();
node2.routDiscover();
etc.. until node 8