9 #define INPUT_BUF_SIZE 256
10 #define MAX_NR_ARGS 100
23 static int forward(struct peerd *peer, struct peer_req *pr)
26 r = submit_peer_req(peer, pr);
28 printf("couldn't forward request");
34 static int complete_forwarded(struct peerd *peer, struct peer_req *pr)
36 struct xseg_request *req = pr->req;
38 // assert mio->src_portno != NoPort
39 if (req->state & XS_SERVED)
41 else if (req->state & XS_FAILED)
44 printf("invalid state\n");
50 int dispatch(struct peerd *peer, struct peer_req *pr, struct xseg_request *xreq,
51 enum dispatch_reason reason)
53 struct xseg_request *req = pr->req;
54 if (req->state & (XS_SERVED | XS_FAILED)){
55 log_pr("completing", pr);
56 complete_forwarded(peer, pr);
59 log_pr("forwarding", pr);
65 int mpause(struct peerd *peer)
67 struct xseg *xseg = peer->xseg;
68 struct xseg_port *port = xseg_get_port(xseg, peer->portno_start);
72 xlock_acquire(&port->rq_lock, peer->portno_start);
73 xlock_acquire(&port->pq_lock, peer->portno_start);
77 int munpause(struct peerd *peer)
79 struct xseg *xseg = peer->xseg;
80 struct xseg_port *port = xseg_get_port(xseg, peer->portno_start);
84 xlock_release(&port->rq_lock);
85 xlock_release(&port->pq_lock);
89 struct peerd *main_peer;
94 struct peerd * peer = main_peer;
95 char buf[INPUT_BUF_SIZE];
98 unsigned int portno = NoPort, dstgw, srcgw;
101 printf("waitin next line\n");
102 if (fgets(buf, INPUT_BUF_SIZE, stdin)) {
103 nl = strchr(buf, '\n');
106 buf[INPUT_BUF_SIZE -1] = 0;
107 printf("got line input\n");
108 ret = sscanf(buf, "set srcgw %u %u", &portno, &srcgw);
110 printf("found setsrcgw\n");
111 xseg_set_srcgw(peer->xseg, (uint32_t) portno, (uint32_t) srcgw);
114 ret = sscanf(buf, "set dstgw %u %u", &portno, &dstgw);
116 printf("found set dstgw\n");
117 xseg_set_dstgw(peer->xseg, (uint32_t) portno, (uint32_t) dstgw);
120 ret = sscanf(buf, "getandset srcgw %u %u", &portno, &srcgw);
122 printf("found getand set srcgw\n");
123 xseg_getandset_srcgw(peer->xseg, (uint32_t) portno, (uint32_t) srcgw);
126 ret = sscanf(buf, "getandset dstgw %u %u", &portno, &dstgw);
128 printf("found getandset dstgw\n");
129 xseg_getandset_dstgw(peer->xseg, (uint32_t) portno, (uint32_t) dstgw);
132 ret = sscanf(buf, "pause %u", &portno);
134 printf("found pause\n");
138 ret = sscanf(buf, "unpause %u", &portno);
140 printf("found unpause\n");
150 int custom_peer_init(struct peerd *peer, int argc, char *argv[])
153 struct monitor_io *mio;
154 struct monitord *monitor;
156 monitor = malloc(sizeof(struct monitord));
159 peer->priv = monitor;
160 monitor->mon_portno = NoPort;
163 for (i = 0; i < peer->nr_ops; i++) {
164 mio = malloc(sizeof(struct monitor_io));
167 peer->peer_reqs[i].priv = mio;
168 mio->src_portno = NoPort;
171 for (i = 1; i < argc; i++) {
172 if (!strcmp(argv[i], "-mp") && (i + 1 < argc)) {
173 monitor->mon_portno = atoi(argv[i+1]);
180 peer->interactive_func = main_loop;