COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
agent_route.cpp File Reference
#include "support/configCosmos.h"
#include <stdio.h>
#include "agent/agentclass.h"
Include dependency graph for agent_route.cpp:

Macros

#define MAXBUFFERSIZE   2560
 

Functions

int main (int argc, char *argv[])
 

Variables

char agentname [COSMOS_MAX_NAME+1] = "route"
 
int waitsec = 5
 
Agentagent
 
socket_channel rcvchan
 

Macro Definition Documentation

#define MAXBUFFERSIZE   2560

Function Documentation

int main ( int  argc,
char *  argv[] 
)
45 {
46  // Initialize the Agent
47  if (!(agent = new Agent("", "route", 0., MAXBUFFERSIZE)))
48  {
50  }
51 
52  // Preload the information about the interfaces
53  uint32_t addr_out[AGENTMAXIF];
54 // uint32_t addr_to[AGENTMAXIF];
55  for (uint16_t i=0; i<agent->cinfo->agent[0].ifcnt; ++i)
56  {
57 #ifdef COSMOS_WIN_OS
58  addr_out[i] = uint32from((uint8_t *)&agent->cinfo->agent[0].pub[i].caddr.sin_addr.S_un.S_addr, ByteOrder::NETWORK);
59 // addr_to[i] = uint32from((uint8_t *)&agent->cinfo->agent[0].pub[i].baddr.sin_addr.S_un.S_addr, ByteOrder::NETWORK);
60 #else
61  addr_out[i] = uint32from((uint8_t *)&agent->cinfo->agent[0].pub[i].caddr.sin_addr.s_addr, ByteOrder::NETWORK);
62 // addr_to[i] = uint32from((uint8_t *)&agent->cinfo->agent[0].pub[i].baddr.sin_addr.s_addr, ByteOrder::NETWORK);
63 #endif
64  }
65 
66  // Start performing the body of the agent
67  int nbytes;
68  char input[AGENTMAXBUFFER];
69  ElapsedTime ret;
70  while(agent->running())
71  {
72  if (ret.split() > 5.)
73  {
74  agent->post(Agent::AgentMessage::REQUEST, "heartbeat");
75 // agent->post(Agent::AgentMessage::REQUEST, "postsoh");
76  ret.reset();
77  }
78  nbytes = recvfrom(agent->cinfo->agent[0].sub.cudp,input,AGENTMAXBUFFER,0,(struct sockaddr *)&agent->cinfo->agent[0].sub.caddr,(socklen_t *)&agent->cinfo->agent[0].sub.addrlen);
79  if (nbytes > 0)
80  {
81 #ifdef COSMOS_WIN_OS
82  uint32_t addr_in = uint32from((uint8_t *)&agent->cinfo->agent[0].sub.caddr.sin_addr.S_un.S_addr, ByteOrder::NETWORK);
83 #else
84  uint32_t addr_in = uint32from((uint8_t *)&agent->cinfo->agent[0].sub.caddr.sin_addr.s_addr, ByteOrder::NETWORK);
85 #endif
86  bool forward=true;
87  for (uint16_t i=0; i<agent->cinfo->agent[0].ifcnt; ++i)
88  {
89  if (addr_in == addr_out[i])
90  {
91  forward = false;
92  break;
93  }
94  }
95 
96  if (forward)
97  {
98  for (uint16_t i=0; i<agent->cinfo->agent[0].ifcnt; ++i)
99  {
100  uint32_t address_xor = addr_in ^ addr_out[i];
101  if (address_xor > 255)
102  {
103 // printf("%x:%x:%x %d\n%s\n", addr_in, addr_out[i], addr_to[i], address_xor, input);
104  sendto(agent->cinfo->agent[0].pub[i].cudp,(const char *)input,nbytes,0,(struct sockaddr *)&agent->cinfo->agent[0].pub[i].baddr,sizeof(struct sockaddr_in));
105 // fflush(stdout);
106  }
107  }
108  }
109  }
110  }
111 
112  agent->shutdown();
113 }
Network byte order.
int i
Definition: rw_test.cpp:37
#define MAXBUFFERSIZE
Definition: agent_route.cpp:42
uint16_t running()
Check if we&#39;re supposed to be running.
Definition: agentclass.cpp:391
int32_t post(messstruc mess)
Post a Cosmos::Agent::messstruc.
Definition: agentclass.cpp:2074
Definition: agentclass.h:139
int32_t shutdown()
Shutdown agent gracefully.
Definition: agentclass.cpp:366
uint32_t uint32from(uint8_t *pointer, ByteOrder order)
Memory to 32 bit unsigned integer.
Definition: mathlib.cpp:442
Definition: elapsedtime.h:62
#define AGENTMAXIF
Maximum number of supported publication interfaces.
Definition: jsondef.h:440
vector< agentstruc > agent
Single entry vector for agent information.
Definition: jsondef.h:4247
cosmosstruc * cinfo
Definition: agentclass.h:346
#define AGENTMAXBUFFER
Maximum AGENT transfer buffer size.
Definition: jsondef.h:438
#define AGENT_ERROR_JSON_CREATE
Definition: cosmos-errno.h:105
Agent * agent
Definition: agent_route.cpp:39
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
void reset()
ElapsedTime::reset.
Definition: elapsedtime.cpp:278

Variable Documentation

char agentname[COSMOS_MAX_NAME+1] = "route"
int waitsec = 5
Agent* agent
socket_channel rcvchan