1/** 2 * \file 3 * \brief Network client of the block service 4 */ 5 6/* 7 * Copyright (c) 2014 ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef BLOCK_NETWORK_COMMON_H 16#define BLOCK_NETWORK_COMMON_H 17 18#include <bulk_transfer/bulk_transfer.h> 19#include <bulk_transfer/bulk_net.h> 20 21#include "block_server.h" 22 23 24#if BULK_NET_BACKEND_PROXY 25#include <bulk_transfer/bulk_net_proxy.h> 26#include <bulk_transfer/bulk_local.h> 27#endif 28 29#include <bitmacros.h> // for MIN 30 31#include <lwip/ip_addr.h> 32 33enum block_net_msg_type 34{ 35 BLOCK_NET_MSG_INIT, ///< transfer setup information of the bulk channel 36 BLOCK_NET_MSG_ENDP, ///< bulk endpoint information 37 BLOCK_NET_MSG_FIN, ///< connection teardown 38 BLOCK_NET_MSG_READ, ///< issue a block read request 39 BLOCK_NET_MSG_WRITE, ///< issue a block write request 40 BLOCK_NET_MSG_STATUS, ///< error message 41}; 42 43enum block_net_err 44{ 45 BLOCK_NET_ERR_OK, 46 BLOCK_NET_ERR_BAD_REQUEST, 47 BLOCK_NET_ERR_NO_BUFS, 48 BLOCK_NET_ERR_BLOCK_ID, 49}; 50 51/** 52 * data structure representing the data of the messages transferred over the 53 * service channel 54 */ 55struct block_net_msg 56{ 57 enum block_net_msg_type type; 58 size_t size; 59 union 60 { 61 struct { 62 /* direction */ 63 bool do_bind; 64 struct bulk_net_endpoint_descriptor rx_ep; 65 struct bulk_net_endpoint_descriptor tx_ep; 66 } setup; 67 68 69 70 struct { 71 uint64_t block_id; 72 size_t count; 73 uint32_t req_id; 74 struct bulk_continuation cont; 75 } read; 76 77 struct { 78 uint64_t block_id; 79 size_t count; 80 uint32_t reqid; 81 } write; 82 83 struct { 84 enum block_net_err code; 85 enum block_net_msg_type req; 86 uint32_t reqid; 87 } status; 88 89 90 } msg; 91 92}; 93 94 95struct block_net_service { 96 struct ip_addr ip; 97 uint16_t port; 98 struct tcp_pcb *tpcb; 99 uint32_t bound; 100 struct bulk_channel tx_chan; 101 struct bulk_channel rx_chan; 102#if BULK_NET_BACKEND_PROXY 103 struct bulk_net_proxy tx_proxy; 104 struct bulk_net_proxy rx_proxy; 105 struct bulk_local_endpoint rx_ep; 106 struct bulk_local_endpoint rx_p_ep; 107 struct bulk_local_endpoint tx_ep; 108 struct bulk_local_endpoint tx_p_ep; 109#else 110 struct bulk_net_endpoint_descriptor rx_ep; 111 struct bulk_net_endpoint_descriptor tx_ep; 112#endif 113}; 114 115#endif /* BLOCK_NETWORK_COMMON_H */ 116