6 * Global mngt variables
9 fwp_participant_t *fwp_participant_this;
10 fwp_participant_t *fwp_participant_mngr;
12 /*fwp_endpoint_d_t fwp_mngt_repointd;*/
25 int fwp_mngt_send(fwp_msg_type_t type,fwp_msgb_t *msgb,
26 fwp_participant_t *source, fwp_participant_t *dest)
28 fwp_msgb_push(msgb, sizeof(struct fwp_msg_header));
29 fwp_msg_header_in(msgb->data, type, source->id);
31 fwp_send(dest->epointd, msgb->data, msgb->len);
36 int fwp_mngt_recv(fwp_msg_type_t *type, fwp_participant_id_t *participant_id,
41 fwp_msgb_reset_data(msgb);
42 size = fwp_recv(fwp_participant_this->epointd, msgb->data,
44 fwp_msgb_put(msgb, size);
46 fwp_msg_header_out(msgb->data, type, participant_id);
47 fwp_msgb_pull(msgb, sizeof(struct fwp_msg_header));
49 FWP_DEBUG("Received msg: type=%d from nodeid=%d appid=%d\n", *type,
50 participant_id->node_id, participant_id->app_id);
55 int fwp_mngt_service_vres_create(fwp_vres_d_t* fwp_service_vresd)
57 struct fwp_vres_params fwp_service_vparams;
59 /* TODO: Add to contract table */
60 /* create service vres */
61 fwp_service_vparams.ac_id = FWP_AC_BK;
62 fwp_service_vparams.budget = 100;
63 fwp_service_vparams.period_usec = 1000;
65 if ((fwp_vres_create(&fwp_service_vparams, fwp_service_vresd) < 0)) {
66 fprintf(stderr,"Unable to open service vres\n");
70 FWP_DEBUG("Service vres negotiated\n");
75 /* Launch discovery/connect process to
76 * introduce itself to fwp manager and get description of manager*/
77 int fwp_mngt_connect()
79 fwp_participant_info_t my_info, mngr_info;
80 fwp_participant_id_t participant_id;
82 fwp_msg_type_t msg_type;
85 /* Create discovery endpoint */
86 FWP_DEBUG("Service vres created\n");
87 fwp_mngt_service_vres_create(&fwp_participant_mngr->vresd);
89 FWP_DEBUG("Discovery send endpoint created\n");
90 fwp_send_endpoint_create(fwp_participant_mngr->id.node_id,
91 fwp_participant_mngr->stream_id,
92 0, &fwp_participant_mngr->epointd);
93 fwp_send_endpoint_bind(fwp_participant_mngr->epointd,
94 fwp_participant_mngr->vresd);
96 /* prepare hello message */
97 msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
98 sizeof(struct fwp_msg_hello));
99 fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
101 my_info.id = fwp_participant_this->id;
102 my_info.stream_id = fwp_participant_this->stream_id;
104 fwp_msg_hello_in(msgb->tail, &my_info);
105 fwp_msgb_put(msgb, sizeof(struct fwp_msg_hello));
107 /* Send hello to manager */
108 fwp_mngt_send(FWP_MSG_HELLO, msgb,
109 fwp_participant_this, fwp_participant_mngr);
111 /* receive hello from manager */
112 fwp_mngt_recv(&msg_type, &participant_id, msgb);
113 FWP_DEBUG("Received HELLO msg from nodeid= %d appid= %d\n",
114 participant_id.node_id, participant_id.app_id);
116 /* Process hello msg from manager */
117 fwp_msg_hello_out(msgb->data, &mngr_info);
118 fwp_participant_mngr->id = mngr_info.id;
119 fwp_participant_mngr->stream_id = mngr_info.stream_id;
120 FWP_DEBUG("Received HELLO msg contains nodeid= %d appid= %d\n",
121 mngr_info.id.node_id, mngr_info.id.app_id);
123 /* unbind and delete discovery mngr send endoint */
124 fwp_send_endpoint_unbind(fwp_participant_mngr->epointd);
125 /*fwp_endpoint_free(fwp_participant_mngr->epointd)*/
127 /* Create mngt send endpoint to manager */
128 fwp_send_endpoint_create(fwp_participant_mngr->id.node_id,
129 fwp_participant_mngr->stream_id, 0,
130 &fwp_participant_mngr->epointd);
131 FWP_DEBUG("Management send endpoint created\n");
132 fwp_send_endpoint_bind(fwp_participant_mngr->epointd,
133 fwp_participant_mngr->vresd);
139 fwp_participant_info_t my_info, mngr_info;
140 unsigned int node_id;
144 /* Create fwp_participant_this */
146 my_info.id.node_id = inet_addr(fwp_configuration.my_addr);
147 if (my_info.id.node_id == inet_addr("127.0.0.1")) {
148 /* if default then check env variable */
149 value = getenv("FWP_MY_ADDR");
151 my_info.id.node_id = inet_addr(value);
154 fwp_configuration.my_node_id = my_info.id.node_id;
155 my_info.id.app_id = getpid();
156 my_info.stream_id = fwp_configuration.my_stream_id;
158 fwp_participant_this = fwp_participant_create(&my_info);
159 fwp_receive_endpoint_create(my_info.stream_id, 0,
160 &fwp_participant_this->epointd);
162 fwp_endpoint_get_params(&(fwp_participant_this->id.node_id),
163 &fwp_participant_this->stream_id,
165 fwp_participant_this->epointd);
167 fwp_endpoint_get_params(&node_id,
168 &fwp_participant_this->stream_id,
170 fwp_participant_this->epointd);
171 FWP_DEBUG("Participant_this created node_id id= %d stream id= %d\n",
172 fwp_participant_this->id.node_id,
173 fwp_participant_this->stream_id);
175 /* Create fwp_participant_mngr */
177 mngr_info.id.node_id = inet_addr(fwp_configuration.mngr_addr);
178 FWP_DEBUG("mngr node=%s node_id=%d\n",
179 fwp_configuration.mngr_addr,
180 mngr_info.id.node_id);
181 if (mngr_info.id.node_id == inet_addr("255.255.255.255")) {
182 /* if default then check env variable */
183 value = getenv("FWP_MNGR_ADDR");
185 mngr_info.id.node_id = inet_addr(value);
188 fwp_configuration.mngr_node_id = mngr_info.id.node_id;
189 mngr_info.id.app_id = getpid();
190 mngr_info.stream_id = fwp_configuration.mngr_stream_id;
192 if ((mngr_info.id.node_id == inet_addr("127.0.0.1")) &&
193 (my_info.stream_id == mngr_info.stream_id)) {
195 FWP_DEBUG("I am FWP manager\n");
196 fwp_participant_mngr = fwp_participant_this;
198 fwp_participant_mngr = fwp_participant_create(&mngr_info);
199 /* Connet to FWP manager */