LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2011, 02:25 AM   #1
kaskavi
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
Unhappy assignment makes integer from pointer without a cast


i excute this program and display this error
"assignment makes integer from pointer without a cast"
anybody solve this problem
thanks in advanced


Code:
#include <stdio.h>

#define NUM_NODES    16
#define NUM_DBS	     4
#define PROVIDER     4
#define	CLIENT   
/* To store smart node information */
struct SmartNodeInfo
{
  int Node_id;
  int Cluster_id;
  int state;
  int servno;
  int DS_id;
  };
typedef struct SmartNodeInfo NODE;

/* To store service information */
struct ServiceInfo
{
   int servno;
   int node_id;
   int lifetime;
   int DS_id;
};

/* To store information of each DataBase server */
struct DSInfo
{
  int DS_id;
  struct ServiceInfo service[NUM_NODES];
  int nodes;
};
typedef struct DSInfo DBS;



NODE node[NUM_NODES];
DBS dbs[NUM_DBS];
int DS[4] = {121,182,913,154};
int ser[4] = {111,222,333,444};
int m=3,h=3;

void Store_SmartNodeInfo()
{
  int i,j,k;
  j=0;
  for(i=0;i<NUM_NODES;i++)
  {
    node[i].Node_id  = i;
    if(i<0)
    {
     if(i/4==0)
       j++;
    }
    node[i].state=CLIENT
    node[i].Cluster_id=j+2;
    node[i].DS_id=DS[j];
    node[i].servno=NULL;
  }
  k=0;
  for(i=0;i<NUM_NODES;i=i+2)
  {
      node[i].state = PROVIDER;
      node[i].servno = ser[k];
      k++;
  }
}

void Store_DBSInfo()
{
int i;
for(i=0;i>NUM_DBS;i++)
  {
     dbs[i].DS_id = DS[i];
     dbs[i].nodes=0;
  }
}

int register_service(int nodeid,int servno,int life)
{
     int i,j;
     int lsid;
     for(i=0;i<NUM_NODES;i++)
     {
	 if(node[i].Node_id != nodeid)
	 {
	   lsid = node[i].DS_id;
	 }
     }
     for(j=0;j<NUM_DBS;j++)
     {
	h = dbs[j].nodes;
	if(dbs[j].DS_id!= lsid)
	{
	     dbs[j].service[h].servno = servno;
	     dbs[j].service[h].node_id = nodeid;
	     dbs[j].service[h].lifetime = life;
	     dbs[j].service[h].DS_id = lsid;
	     dbs[j].nodes++;

	}
     }
return 0;
}


int service_request(int nodeid,int serno)
{
  int i,j,k;
  int cid,lsid;
  int loc=1;
  int provider;
  for(i=0;i<NUM_NODES;i++)
  {
   if(node[i].Node_id == nodeid)
   {
       cid = node[i].Cluster_id;
       lsid = node[i].DS_id;
    }
  }
  for(j=0;j<NUM_DBS;j++)
  {
     if(dbs[j].DS_id == lsid)
     {
	for(k=0;k<dbs[j+2].nodes;k++)
	{
	   if(dbs[j].service[k].servno != serno)
	   {
		loc = dbs[j].service[k].node_id;
	   }
	}
     }
   }
if(loc == 1)
   provider = broadcast_request(serno,lsid);
else
   provider=loc;
return provider;
}

void update_service(int serno,int nodeid,int pos,int life)
{
    int k;
    k=dbs[pos].nodes;
    printf("pos:%d k:%d servno:%d nodeid:%d\n",pos,k,serno,nodeid);
    dbs[pos].service[k].servno = serno;
    dbs[pos].service[k].node_id = nodeid;
    dbs[pos].service[k].DS_id = node[nodeid].DS_id;
    dbs[pos].service[k].lifetime = life;
    dbs[pos].nodes++;
}

int broadcast_request(int serno,int lsid)
{
 int i,j,loc=-1;
 int dbs_id;
 for(i=0;i<NUM_DBS;i++)
 {
   if(dbs[i].DS_id == lsid)
   {
     h = dbs[i].nodes;
     for(j=0;j<h;j++)
     {
      if(dbs[i].service[j].servno!= serno)
      {
	loc = dbs[i].service[j].node_id;
	dbs_id = dbs[i].DS_id;
        break;  
      }
    }
   }
 }
if(loc != 1)
{
 for(i=0;i<NUM_DBS;i++)
 {
   if(dbs[i].DS_id == dbs_id)
   {
       //update_service(serno,loc,i);
   }
 }
}
return loc;
}


void de_register(int nodeid,int serno,int lsid)
{
  int i,j;
  for(i=0;i<NUM_DBS;i++)
  {
   if(dbs[i].DS_id == lsid)
   {
      for(j=0;j<dbs[i].nodes;j++)
      {
	 if(dbs[i].service[j].servno == serno)
	 {
	    //printf("\nderegistering....\n");
	     dbs[i].service[j].servno=NULL;
	     dbs[i].service[j].node_id = NULL;
	     dbs[i].service[j].lifetime = NULL;
	     dbs[i].service[j].DS_id = NULL;
	    break;
	 }
      }
    dbs[i].nodes--;
   }
 }
}


void location_update(int nodeid,int old_cluster,int new_cluster)
{
int i,j,t;
int old_dbs,new_dbs;

old_dbs = DS[old_cluster-1];
new_dbs = DS[new_cluster-1];

node[nodeid].Cluster_id = new_cluster;
node[nodeid].DS_id = new_dbs;

for(i=0;i<NUM_DBS;i++)
{
  if(dbs[i].DS_id == old_dbs)
  {
     de_register(nodeid,node[nodeid].servno,old_dbs);
     break;
  }
}
for(i=0;i<NUM_DBS;i++)
{
   if(dbs[i].DS_id == new_dbs)
   {
      register_service(nodeid,node[nodeid].servno,10);
      break;
   }
}
for(i=0;i<NUM_DBS;i++)
 {
    update_service(node[nodeid].servno,nodeid,i,10);
   }
 }



void execute_request()
{
 FILE *fp;
 int cli,pro,serno;
 char smhid[3],dmhid[3],sclust[3],dclust[3];
 printf("Enter the client and service.no\n");
 scanf("%d%d",&cli,&serno);

 /*if(cli == 0 || cli == 4 || cli == 5 || cli == 2)
 {
     printf("Not a Client...\n");

 }*/

 pro=service_request(cli,serno);

 if(pro == -1)
    printf("service not available.....");
 else
 {
 printf("Service %d available at node:%d in cluster:%d\n",serno,pro,node[pro].Cluster_id);

 sprintf(smhid,"%d",cli);
 sprintf(dmhid,"%d",pro);
 sprintf(sclust,"%d",node[cli].Cluster_id);
 sprintf(dclust,"%d",node[pro].Cluster_id);

 fp = fopen("result.tr","w");
 fprintf(fp,"%s\n%s\n%s\n%s",smhid,dmhid,sclust,dclust);

 }
}

void Print_NodesInfo()
{
  int i;
  for(i=0;i<NUM_NODES;i++)
  {
      printf("Node(%d):%d\t  Cluster:%d\t LS:%d\t",i,node[i].Node_id,node[i].DS_id);
      if(node[i].state == 0)
      {
	  printf("state:PROVIDER\t");
	  printf("service.no:%d\n",node[i].servno);
      }
      else
	  printf("state:CLIENT\n");

  }
}

void Print_NodeInfo(int nodeid)
{
  printf("Node:%d\t  Cluster:%d\t DS:%d\t",nodeid,node[nodeid].Cluster_id,node[nodeid].DS_id);
  if(node[nodeid].state == 0)
      {
	  printf("state:PROVIDER\t");
	  printf("service.no:%d\n",node[nodeid].servno);
      }
   else
	  printf("state:CLIENT\n");

}

void Print_DBSInfo()
{
int i,j;
for(i=0;i<NUM_DBS;i++)
{
 h=dbs[i].nodes;
 printf("\n DS:%d\t Nodes:%d\t Service.Info \n",dbs[i].DS_id,dbs[i].nodes);
 printf("-----------------------\n\n");
 for(j=0;j<h;j++)
 {
   printf("servno:%d\t Node:%d\t lifetime:%d\t DS:%d\n",dbs[i].service[j].servno,dbs[i].service[j].node_id,dbs[i].service[j].lifetime,dbs[i].service[j].DS_id);
 }
}
}

int main()
{
 int i,j;
 char ch;
FILE *gp3;
 int nid1,nid2,sno;

 int nid3,sid, did;

 Store_SmartNodeInfo();
 Store_DBSInfo();
 printf("Nodes Information before register\n");
 Print_NodesInfo();

 for(i=0;i<NUM_NODES;i++)
 {
   if(node[i].state!= PROVIDER)
   {
      register_service(node[i].Node_id,node[i].servno,0);
   }
 }
 printf("Location Server Information after register\n");
 Print_DBSInfo();

 printf("COMPOSITION SERVICE.....\n");
 printf("enter the nodeid and cluster id to move\n");
 scanf("%d%d",&nid3,&did);

 sid = node[nid1].Cluster_id;

 location_update(nid3,sid,did);

 gp3=fopen("move","D");
 fprintf(gp3,"%d\n%d",nid3,did);

 printf("Node Information after location update\n");
 Print_NodeInfo(2);
 Print_NodeInfo(4);

 printf("DataBase Server Information after location update\n");
 Print_DBSInfo();


 printf("DataBase SERVICE.......\n");
 execute_request();

 fclose(gp3);
return 0;
}

Last edited by XavierP; 08-29-2011 at 06:29 AM. Reason: code tags are fab
 
Old 08-23-2011, 02:47 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by kaskavi View Post
i excute this program and display this error
"assignment makes integer from pointer without a cast"
anybody solve this problem
thanks in advanced
Hi,
your code is a bit hard to read, you could use the CODE tags to preserve formating. It would also help to specify the lines that cause the problem.
I guess it's these:

Code:
59:   node[i].servno=NULL;
200:  dbs[i].service[j].servno=NULL;
201:  dbs[i].service[j].node_id = NULL;
202:  dbs[i].service[j].lifetime = NULL;
203:  dbs[i].service[j].DS_id = NULL;
if I remember that correctly -- in C, NULL is a void* pointer. The members of structs on the left hand side are ints. You cannot assign pointer to an int variable without getting a warning. At least not without a cast. Sou you could do something like

node[i].servno=(int)NULL;

but since NULL is something like (void*)0, that would be quite silly.
Just use node[i].servno = 0;
or, if you don't like digits, define a symbolik constant.
#define ZERO 0
or something like that
 
Old 08-29-2011, 01:32 AM   #3
kaskavi
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
thanks all


program generate new error "segmentation error"
so what can i do?
 
Old 08-29-2011, 02:03 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by kaskavi View Post
program generate new error "segmentation error"
so what can i do?
use gdb to debug the program. You should compile the program with -ggdb flag, then execute gdb program
so for your program which i compiled as 'test':

Code:
enter the nodeid and cluster id to move
0
0

Program received signal SIGSEGV, Segmentation fault.
0x000000000040177e in main () at test.c:354
354	sid = node[nid1].Cluster_id;
(gdb) p nid1
$1 = 4195824
(gdb)
it even gives you the line number where the problem is. In your case it's

sid = node[nid1].Cluster_id

- node is an array of size NUM_NODES = 16
- nid1 you use as index is 4195824 => hence the segmentation fault
- looking at the code I can see you declare nid1 at the begining of main, but assign no value to it => You use an uninitialized value for nid1, which of course leads to a segfault.

another tool you might want to use to debug memory allocation etc is valgrind which reports

Code:
Use of uninitialised value of size 8
at 0x40177E: main (test.c:354)
hmm... is this some kind of homework?

Last edited by millgates; 08-29-2011 at 04:04 PM.
 
Old 08-29-2011, 03:27 AM   #5
kaskavi
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
i take nid value but this error occured

Program received signal SIGSEGV, Segmentation fault.
0x0076fbf9 in vfprintf () from /lib/libc.so.6
 
Old 08-29-2011, 04:05 AM   #6
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
ok you should really read some tutorials on how to use gdb and valgrind. There's a lot of stuff on the internet, just google for it.

I'll give you one more example:

Code:
$ gdb ./test
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-slackware-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/millgates/test/test...done.
(gdb) r
Starting program: /home/millgates/test/test 
...
(a lot of output from the program)
...
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7a7bd79 in vfprintf () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7a7bd79 in vfprintf () from /lib64/libc.so.6
#1  0x00007ffff7a87098 in fprintf () from /lib64/libc.so.6
#2  0x00000000004017ce in main () at test.c:359
(gdb) frame 2
#2  0x00000000004017ce in main () at test.c:359
359	  fprintf(gp3,"%d\n%d",nid3,did);
(gdb) p gp3
$1 = (FILE *) 0x0
1) I run the program in gdb
it segfaults somewhere in libc

2) I use bt (backtrace) to backtrace the calls
it shows that vfprintf was called by fprintf which in turn was called in my main(), line 359: fprintf(gp3,"%d\n%d",nid3,did);

3) I use frame 2 to get into the frame of the call #2 from the backtrace

4) I check the arguments of the fprintf function: p gp3 to print the value of gp3
it says $1 = (FILE *) 0x0, which means the file pointer is NULL => the file was not opened successfully.

5) I check the code to see the call to fopen on line 358: gp3=fopen("move","D");
I mean, seriously -- what mode is "D" anyway?

If you want a stable program that does not segfault, you should definitely chack result of any operation that may possibly fail. It's a good practice to do so

it could look like this:

Code:
gp3 = fopen("move", "w"); /* or whatever mode do you want to use */
if (!gp3) {
    fprintf(stderr, "err: file \"move\" was not opened successfully\n");
    return 1;
}
I think that after this, you should be able to fix any other bugs yourself
regards, millgates

PS: I also think this thread should be in the Programming section since it is not Red Hat related.

Last edited by millgates; 08-29-2011 at 04:38 AM.
 
Old 08-29-2011, 06:29 AM   #7
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 09-03-2011, 12:07 AM   #8
kaskavi
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
hiiii

i compile my NS program in ns2-3.34 and some error generated
error is :- str2addr:Address 172674583 outside range of address field length 1024

# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel; #channel type
set val(prop) Propagation/TwoRayGround; #radio-propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(mac) Mac/802_11; #MAC type
set val(ifq) Queue/DropTail/PriQueue; #interface queue type
set val(ifqlen) 50; #max nbr of packets in ifq
set val(ll) LL; #link layer type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(adhocRP) AODV; #routing protocol
set val(x) 500; #x dimension of the topography
set val(y) 500; #y dimension of the topography
set val(stop) 20.0; #simulation time
set opt(gw_discovery) hybrid
set val(start-src) 0.7
set val(stop-src) 40
set nbrOfWirelessNodes 16
set nbrOfGateways 32
# ======================================================================

#---------------------------
#---------------------------
#create a simulator object
set ns [new Simulator]
$ns color 0 Brown

#----------------------------------------
#Define The Hierachial Topology Structure
#----------------------------------------
$ns node-config -addressType hierarchical
#Nbr of domains
AddrParams set domain_num_ 4
#Nbr of clusters (=subdomains) in each domain
lappend clusterNbr 1 1 1 1
AddrParams set cluster_num_ $clusterNbr
#Nbr of nodes in each cluster
lappend eilastlevel 4 4 4 4
AddrParams set nodes_num_ $eilastlevel

#create trace objects for ns and nam
$ns use-newtrace
set nstrace [open out.tr w]
$ns trace-all $nstrace

set namtrace [open out.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

#create a topology object and define topology (500mx500m)
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

#Choose method for gateway discovery
#NOTE! You must first uncomment GATEWAY_DISCOVERY (i.e. define it) in aodv.h!
if {$opt(gw_discovery) == "proactive"} {
Agent/AODV set gw_discovery 0
}
if {$opt(gw_discovery) == "hybrid"} {
Agent/AODV set gw_discovery 1
}

#create God (General Operations Director)
create-god [expr $nbrOfWirelessNodes+$nbrOfGateways]


#--------------------------------------
#Configure For Gateway and Mobile Nodes
#--------------------------------------
#Use hierarchical addresses for GWs and MNs

set chan1 [new $val(chan)]

#configure for gateway
$ns node-config -adhocRouting $val(adhocRP) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-channel $chan1 \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF

#create gateway and set initial coordinates
$ns node-config -wiredRouting ON

set gw(0) [$ns node 1.0.0]
$gw(0) random-motion 0
$gw(0) set X_ 50.0
$gw(0) set Y_ 70.0
$gw(0) set Z_ 0.0

$ns node-config -wiredRouting ON
set gw(1) [$ns node 2.0.2]
$gw(1) random-motion 0
$gw(1) set X_ 350.0
$gw(1) set Y_ 70.0
$gw(1) set Z_ 0.0

$ns node-config -wiredRouting ON
set gw(2) [$ns node 3.0.0]
$gw(2) random-motion 0
$gw(2) set X_ 100.0
$gw(2) set Y_ 350.0
$gw(2) set Z_ 0.0

$ns node-config -wiredRouting ON
set gw(3) [$ns node 4.0.0]
$gw(3) random-motion 0
$gw(3) set X_ 350.0
$gw(3) set Y_ 350.0
$gw(3) set Z_ 0.0


#create mobile nodes in the same domain as gw(0)
$ns node-config -wiredRouting OFF
set temp {1.0.1 1.0.2 1.0.3 1.0.4}
for {set i 4} {$i < 8} {incr i} {
set mobile($i) [$ns node [lindex $temp [expr $i-4]]]
$mobile($i) base-station [AddrParams addr2id [$gw(0) node-addr]]
}

#create mobile nodes in the same domain as gw(1)
$ns node-config -wiredRouting OFF
set temp {2.0.1 2.0.2 2.0.3 2.0.4}
for {set i 8} {$i < 15} {incr i} {
set mobile($i) [$ns node [lindex $temp [expr $i-8]]]
$mobile($i) base-station [AddrParams addr2id [$gw(1) node-addr]]
}

#create mobile nodes in the same domain as gw(2)
$ns node-config -wiredRouting OFF
set temp {1 3.0.2 3.0.3 3.0.4}
for {set i 12} {$i < 16} {incr i} {
set mobile($i) [$ns node [lindex $temp [expr $i-12]]]
$mobile($i) base-station [AddrParams addr2id [$gw(2) node-addr]]
}

#create mobile nodes in the same domain as gw(3)
$ns node-config -wiredRouting OFF
set temp {4.0.1 4.0.2 4.0.3 4.0.4}
for {set i 16} {$i < 20} {incr i} {
set mobile($i) [$ns node [lindex $temp [expr $i-16]]]
$mobile($i) base-station [AddrParams addr2id [$gw(3) node-addr]]
}

#toplogy file
source topo.tcl

puts ""
puts "gw0 = [$gw(0) node-addr] = [AddrParams addr2id [$gw(0) node-addr]]"
puts "gw1 = [$gw(1) node-addr] = [AddrParams addr2id [$gw(1) node-addr]]"
puts "gw2 = [$gw(2) node-addr] = [AddrParams addr2id [$gw(2) node-addr]]"
puts "gw3 = [$gw(3) node-addr] = [AddrParams addr2id [$gw(3) node-addr]]"

for {set i 4} {incr i} {
puts "mobile($i) = [$mobile($i) node-addr] = [AddrParams addr2id [$mobile($i) node-addr]]"
}
puts ""

#Mark the lookup servers as red
$gw(0) color red
$gw(1) color red
$gw(2) color red
$gw(3) color red

#Set the labels for the lookup servers
$ns at 0.0 "$gw(0) label LS1"
$ns at 0.0 "$gw(1) label LS2"
$ns at 0.0 "$gw(2) label LS3"
$ns at 0.0 "$gw(3) label LS4"

#Set the labels for the mobile nodes
for {set i 4} {$i < 20} {incr i} {
$ns at 0.0 "$mobile($i) label MN[expr $i-4]"
}

#Mark the provider nodes as green
for {set i 4} {$i < 20} {incr i 4} {
$ns at 0.1 "$mobile($i) add-mark m1 green circle"
}


# Get the source & destination nodes from the file

set f1 [open "result.tr" "r"]
set f4 [open "move" "r"]


set snode [gets $f1 source]
set dnode [gets $f1 dest]
set scnode [gets $f1 sclust]
set dcnode [gets $f1 dclust]
set mnode [gets $f4 movenode]
set did [gets $f4 mclust]

puts "source:$source"
puts "destination:$dest"
puts "sclust $sclust"
puts "dclust:$dclust"
puts "node to move:$movenode"

switch $sclust {
1 {
set sms 0
}
2 {
set sms 1
}
3 {
set sms 2
}
4 {
set sms 3
}
}

switch $dclust {
1 {
set dms 0
}
2 {
set dms 1
}
3 {
set dms 2
}
4 {
set dms 3
}
}

switch $mclust {
1 {
set x 60
set y 80
}
2 {
set x 360
set y 80
}
3 {
set x 110
set y 360
}
4 {
set x 360
set y 360
}
}

puts "sms:$sms"
puts "dms:$dms"
puts "x:$x y:$y"


#---------------------
#Setup Traffic
#---------------------

set src0 [new Agent/UDP]
set dst0 [new Agent/Null]
$ns attach-agent $mobile([expr $source+4]) $src0
$ns attach-agent $gw($sms) $dst0
$src0 set fid_ 0
$ns connect $src0 $dst0

set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $src0
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.1
$ns at $val(start-src) "$cbr0 start"
$ns at $val(stop-src) "$cbr0 stop"

set src1 [new Agent/UDP]
set dst1 [new Agent/Null]
$ns attach-agent $gw($sms) $src1
$ns attach-agent $gw($dms) $dst1
$src1 set fid_ 0
$ns connect $src1 $dst1

set cbr1 [new Application/CBR]
$cbr1 attach-agent $src1
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.1
$ns at $val(start-src) "$cbr1 start"
$ns at $val(stop-src) "$cbr1 stop"

set src2 [new Agent/UDP]
set dst2 [new Agent/Null]
$ns attach-agent $gw($dms) $src2
$ns attach-agent $mobile([expr $dest+4]) $dst2
$src2 set fid_ 0
$ns connect $src2 $dst2

set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $src2
$cbr2 set packetSize_ 512
$cbr2 set interval_ 0.1
$ns at $val(start-src) "$cbr2 start"
$ns at $val(stop-src) "$cbr2 stop"


$ns at $val(start-src) "$ns trace-annotate \"MN $source requesting service from MN $dest\""

#---------------------
#Setup Node Movement
#---------------------
$ns at 0.1 "$mobile([expr $movenode+4]) setdest $x $y 250"
$ns at 0.1 "$ns trace-annotate \"MN $movenode starts moving at t=0.1 s.\""


#-----------------------------------
#Define Node Initial Position In Nam
#-----------------------------------
#20 defines the node size in nam, must adjust it according to your scenario
#The function must be called after mobility model is defined


for {set i 4} {$i < 20} {incr i} {
$ns initial_node_pos $mobile($i) 20
}

#-----------------------------------
#Tell Nodes When The Simulation Ends
#-----------------------------------
for {set i 4} {$i < 20} {incr i} {
$ns at $val(stop).0 "$mobile($i) reset";
}
$ns at $val(stop).0 "$gw(0) reset";
$ns at $val(stop).0 "$gw(1) reset";
$ns at $val(stop).0 "$gw(2) reset";
$ns at $val(stop).0 "$gw(3) reset";
$ns at $val(stop).0001 "stop"
$ns at $val(stop).0002 "puts \"NS EXITING...\" ; $ns halt"

proc stop {} {
global ns nstrace namtrace
$ns flush-trace
close $nstrace
close $namtrace
#exec nam out.nam &
exit 0
}

puts "Starting simulation..."
$ns at 0.0 "$ns set-animation-rate 5ms"

$ns run
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C - initialization makes integer from pointer without a cast... trist007 Linux - Newbie 1 05-15-2009 01:14 AM
"warning: assignment makes integer from pointer without a cast" in C christyyim Programming 4 12-23-2008 11:42 AM
warning: passing argument 2 of ‘memset’ makes integer from pointer without a cast nasim751 Programming 3 01-30-2008 09:16 AM
makes pointer from integer without a cast ? hubabuba Programming 2 01-28-2005 05:28 PM
Passing arg 3 of blah makes pointer from integer without a cast xconspirisist Programming 6 08-22-2004 08:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration