I am using 32-bit Ubuntu 11.04 (silly me) on a 64-bit x-86 system. Does this has anything to do with the byte alignment problems ?
I am developing a controller to communicate with the Open Flow switch. The openflow protocol defines a set of specs based on which switches are built. The problem is when I try to communicate with the switch everything goes fine until I send or receive a struct that contains a 64 bit date type (uint64_t). The specific structs that are used for sending and receiving features are
Expand|Select|Wrap|Line Numbers
- /// features req
- struct ofp_header {
- uint8_t version; /* OFP_VERSION. */
- uint8_t type; /* One of the OFPT_ constants. */
- uint16_t length; /* Length including this ofp_header. */
- uint32_t xid; /* Transaction id associated with this packet.
- Replies use the same id as was in the request
- to facilitate pairing. */
- };
- assert(sizeof(struct ofp_header) == 8);
- /* Switch features. */
- struct ofp_switch_features {
- struct ofp_header header;
- uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for a MAC address, while the upper 16-bits are implementer-defined. */
- uint32_t n_buffers; /* Max packets buffered at once. */
- uint8_t n_tables; /* Number of tables supported by datapath. */
- uint8_t pad[3]; /* Align to 64-bits. */
- /* Features. */ /* Bitmap of support "ofp_capabilities". */
- uint32_t capabilities; /* Bitmap of supported "ofp_action_type"s. */
- uint32_t actions;
- /* Port info.*/
- struct ofp_phy_port ports[0]; /* Port definitions. The number of ports is inferred from the length field in the header. */
- };
- assert(sizeof(struct ofp_switch_features) == 32);
The problem is when I communicate using any other structs that have data types less than 64-bit everything goes fine. When I receive features reply it shows the right values but after that if i receive any other struct it shows garbage values. Even if i receive features reply again i get garbage values. In short if at any point of code I receive features request or any other struct defined in the specs that has a data type of 64-bit the next structs receive garbage values. The code used for sending and receiving features request is as follows
Expand|Select|Wrap|Line Numbers
- ////// features request and reply ////////////
- ofp_header features_req;
- features_req.version=OFP_VERSION;
- features_req.type=OFPT_FEATURES_REQUEST;
- features_req.length= htons(sizeof features_req);
- features_req.xid = htonl(rcv_hello.xid);
- if (send(connected, &features_req, sizeof(features_req), 0)==-1) {
- printf("Error in sending message\n");
- exit(-1);
- }
- printf("features req sent!\n");
- ofp_switch_features features_rep={0};
- if (recv(connected, &features_rep, sizeof(features_rep), 0)==-1) {
- printf("Error in receiving message\n");
- exit(-1);
- }
- printf("message type : %d\n",features_rep.header.type);
- printf("version : %d\n",features_rep.header.version);
- printf("message length: %d\n",ntohs(features_rep.header.length));
- printf("xid : %d\n",ntohl(features_rep.header.xid));
- printf("buffers: %d\n",ntohl(features_rep.n_buffers));
- printf("tables: %d\n",features_rep.n_tables);
Abdullah