Click
Loading...
Searching...
No Matches
simclick.h
1#ifndef SIMCLICK_H
2#define SIMCLICK_H
3/*
4 * simclick.h
5 *
6 * API for sending packets to Click. Mostly intended for use
7 * by a network simulator which wants to use Click to do routing.
8 *
9 */
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15/*
16 * Packet types used - generally going to be ethernet, but could
17 * possibly be something else I suppose...
18 */
19#define SIMCLICK_PTYPE_UNKNOWN 0
20#define SIMCLICK_PTYPE_ETHER 1
21#define SIMCLICK_PTYPE_IP 2
22
23/*
24 * Not a whole lot to this. We have to create a click router object
25 * and also send packets and trigger events.
26 */
27
28/*
29 * This contains per packet data we need to preserve when the packet gets
30 * dragged through click. Heavily biased towards ns-2 right now.
31 */
32typedef struct {
33 int id; /* Simulator ID number for the packet */
34 int fid; /* Simulator flow ID number for the packet */
35 int simtype; /* Original simulator packet type - useful
36 * for morphing between raw and simulator
37 * packet types */
38} simclick_simpacketinfo;
39
40
41/*
42 * Opaque handles for the sim and click instances
43 */
44typedef struct simclick_node {
45 void *clickinfo;
46 struct timeval curtime;
47} simclick_node_t;
48
49int simclick_click_create(simclick_node_t *sim, const char *router_file);
50
51int simclick_click_send(simclick_node_t *sim,
52 int ifid,int type,const unsigned char* data,int len,
53 simclick_simpacketinfo* pinfo);
54int simclick_sim_send(simclick_node_t *sim,
55 int ifid,int type, const unsigned char* data,int len,
56 simclick_simpacketinfo*);
57
58void simclick_click_run(simclick_node_t *sim);
59
60void simclick_click_kill(simclick_node_t *sim);
61
62/*
63 * simclick_click_read_handler will allocate a buffer of adequate length
64 * to receive the handler information. This buffer must be freed
65 * by the caller. If a non-null value for the "memalloc" parameter
66 * is passed in, simclick_click_read_handler will use that function
67 * to allocate the memory. If there's a null value there, "malloc" will
68 * be used by default. The "memparam" parameter is a caller-specified
69 * value which will be passed back to the memory allocation function.
70 */
71typedef void* (*SIMCLICK_MEM_ALLOC)(size_t,void*);
72char* simclick_click_read_handler(simclick_node_t *sim,
73 const char* elementname,
74 const char* handlername,
75 SIMCLICK_MEM_ALLOC memalloc,
76 void* memparam);
77
78int simclick_click_write_handler(simclick_node_t *sim,
79 const char* elemname, const char* handlername,
80 const char* writestring);
81
82/*
83 * We also provide a gettimeofday substitute which utilizes the
84 * state info passed to us by the simulator.
85 */
86int simclick_gettimeofday(struct timeval* tv);
87
88/*
89 * The simulated system also has to provide a few services to click,
90 * notably some way of injecting packets back into the system,
91 * mapping interface names to id numbers, and arranging for click
92 * to execute at a specified time in the future.
93 * We implement
94 */
95#define SIMCLICK_VERSION 0 // none
96#define SIMCLICK_SUPPORTS 1 // int call
97#define SIMCLICK_IFID_FROM_NAME 2 // const char *ifname
98#define SIMCLICK_IPADDR_FROM_NAME 3 // const char *ifname, char *buf, int len
99#define SIMCLICK_MACADDR_FROM_NAME 4 // const char *ifname, char *buf, int len
100#define SIMCLICK_SCHEDULE 5 // struct timeval *when
101#define SIMCLICK_GET_NODE_NAME 6 // char *buf, int len
102#define SIMCLICK_IF_READY 7 // int ifid
103#define SIMCLICK_TRACE 8 // const char *event
104#define SIMCLICK_GET_NODE_ID 9 // none
105#define SIMCLICK_GET_NEXT_PKT_ID 10 // none
106#define SIMCLICK_CHANGE_CHANNEL 11 // int ifid, int channelid
107#define SIMCLICK_IF_PROMISC 12 // int ifid
108#define SIMCLICK_IPPREFIX_FROM_NAME 13 // const char *ifname, char *buf, int len
109#define SIMCLICK_GET_RANDOM_INT 14 // uint32_t *result, uint32_t max
110#define SIMCLICK_GET_DEFINES 15 // char *buf, size_t *size
111
112int simclick_sim_command(simclick_node_t *sim, int cmd, ...);
113int simclick_click_command(simclick_node_t *sim, int cmd, ...);
114
115#ifdef __cplusplus
116}
117#endif
118#endif