net: nbuf: Remove unused net_nbuf_push() API

The net_nbuf_push() API is not used by anyone. Semantics are not
clear and following patch requires changes to push api, so removing
this API for now. If needed this can be re-introduced later.

Change-Id: I1d669c861590aa9bc80cc1ccb08144bd6020dac5
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2017-02-07 14:17:14 +02:00 committed by Jukka Rissanen
commit 999338ea94
3 changed files with 3 additions and 214 deletions

View file

@ -587,28 +587,6 @@ struct net_buf *net_nbuf_compact(struct net_buf *buf);
*/ */
bool net_nbuf_is_compact(struct net_buf *buf); bool net_nbuf_is_compact(struct net_buf *buf);
/**
* @brief Create some more space in front of the fragment list.
*
* @details After this there is more space available before the first
* fragment. The existing data needs to be moved "down" which will
* cause a cascading effect on fragment list because fragments are fixed
* size.
*
* @param parent Pointer to parent of the network buffer. If there is
* no parent, then set this parameter NULL.
* @param buf Network buffer
* @param amount Amount of data that is needed in front of the fragment list.
* @param timeout Affects the action taken should the net buf pool be empty.
* If K_NO_WAIT, then return immediately. If K_FOREVER, then
* wait as long as necessary. Otherwise, wait up to the specified
* number of milliseconds before timing out.
*
* @return Pointer to the start of the fragment list if ok, NULL otherwise.
*/
struct net_buf *net_nbuf_push(struct net_buf *parent, struct net_buf *buf,
size_t amount, int32_t timeout);
/** /**
* @brief Remove given amount of data from the beginning of fragment list. * @brief Remove given amount of data from the beginning of fragment list.
* This is similar thing to do as in net_buf_pull() but this function changes * This is similar thing to do as in net_buf_pull() but this function changes

View file

@ -820,39 +820,6 @@ struct net_buf *net_nbuf_compact(struct net_buf *buf)
return first; return first;
} }
struct net_buf *net_nbuf_push(struct net_buf *parent,
struct net_buf *buf,
size_t amount,
int32_t timeout)
{
struct net_buf *frag;
NET_ASSERT_INFO(amount > 3,
"Amount %zu very small and not recommended", amount);
if (amount > buf->len) {
NET_DBG("Cannot move amount %zu because the buf "
"length is only %u bytes", amount, buf->len);
return NULL;
}
frag = net_nbuf_get_reserve_data(net_buf_headroom(buf), timeout);
if (!frag) {
return NULL;
}
net_buf_add(frag, amount);
if (parent) {
net_buf_frag_insert(parent, frag);
} else {
net_buf_frag_insert(frag, buf);
parent = frag;
}
return net_nbuf_compact(parent);
}
struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount) struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount)
{ {
struct net_buf *first; struct net_buf *first;

View file

@ -271,9 +271,8 @@ static int test_fragment_copy(void)
/* Empty data and test data must be the same size in order the test to work */ /* Empty data and test data must be the same size in order the test to work */
static const char test_data[] = { '0', '1', '2', '3', '4', static const char test_data[] = { '0', '1', '2', '3', '4',
'5', '6', '7' }; '5', '6', '7' };
static const char empty_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
#if HEXDUMP
static void hexdump(const char *str, const uint8_t *packet, size_t length) static void hexdump(const char *str, const uint8_t *packet, size_t length)
{ {
int n = 0; int n = 0;
@ -304,162 +303,11 @@ static void hexdump(const char *str, const uint8_t *packet, size_t length)
printk("\n"); printk("\n");
} }
} }
#endif
static int test_fragment_push(void)
{
#define FRAG_COUNT 7
struct net_buf *buf, *frags[FRAG_COUNT], *frag;
uint8_t *ptr;
int i, bytes;
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
frag = NULL;
for (i = 0; i < FRAG_COUNT; i++) {
frags[i] = net_nbuf_get_reserve_data(12, K_FOREVER);
if (frag) {
net_buf_frag_add(frag, frags[i]);
}
frag = frags[i];
/* Copy character test data in front of the fragment */
memcpy(net_buf_add(frags[i], sizeof(test_data)),
test_data, sizeof(test_data));
/* Followed by bytes of zeroes */
memset(net_buf_add(frags[i], sizeof(test_data)), 0,
sizeof(test_data));
}
net_buf_frag_add(buf, frags[0]);
bytes = net_buf_frags_len(buf);
if (bytes != FRAG_COUNT * sizeof(test_data) * 2) {
printk("Push test failed, fragments had %d bytes but "
"should have had %zd\n", bytes,
FRAG_COUNT * sizeof(test_data) * 2);
return -1;
}
if (net_nbuf_is_compact(buf->frags)) {
printk("The buf->frags is not compact. Test fails\n");
return -1;
}
if (net_nbuf_is_compact(buf)) {
printk("The buf is definitely not compact. Test fails\n");
return -1;
}
buf = net_nbuf_compact(buf);
if (!net_nbuf_is_compact(buf)) {
printk("The buf should be in compact form. Test fails\n");
return -1;
}
/* Try compacting again, nothing should happen */
buf = net_nbuf_compact(buf);
if (!net_nbuf_is_compact(buf)) {
printk("The buf should be compacted now. Test fails\n");
return -1;
}
buf = net_nbuf_push(buf, buf->frags, sizeof(empty_data), K_FOREVER);
if (!buf) {
printk("push test failed, even with fragment pointer\n");
return -1;
}
/* Clear the just allocated area */
memcpy(buf->frags->data, empty_data, sizeof(empty_data));
/* The data should look now something like this (frag->data will point
* into this part).
* empty
* test data
* empty
* test data
* empty
* test data
* empty
* test data
* empty
* test data
* empty
*
* Then the second fragment:
* test data
* empty
* test data
* empty
*/
frag = buf->frags;
hexdump("frag 1", frag->data, frag->len);
ptr = frag->data;
for (i = 0; i < frag->len / (sizeof(empty_data) * 2); i++) {
if (memcmp(ptr, empty_data, sizeof(empty_data))) {
printk("%d: No empty data at pos %p\n",
__LINE__, ptr);
return -1;
}
ptr += sizeof(empty_data);
if (memcmp(ptr, test_data, sizeof(test_data))) {
printk("%d: No test data at pos %p\n",
__LINE__, ptr);
return -1;
}
ptr += sizeof(empty_data);
}
/* One empty data at the end of first fragment */
if (memcmp(ptr, empty_data, sizeof(empty_data))) {
printk("%d: No empty data at pos %p\n",
__LINE__, ptr);
return -1;
}
frag = frag->frags;
hexdump("frag 2", frag->data, frag->len);
ptr = frag->data;
for (i = 0; i < frag->len / (sizeof(empty_data) * 2); i++) {
if (memcmp(ptr, test_data, sizeof(test_data))) {
printk("%d: No test data at pos %p\n",
__LINE__, ptr);
return -1;
}
ptr += sizeof(test_data);
if (memcmp(ptr, empty_data, sizeof(empty_data))) {
printk("%d: No empty data at pos %p\n",
__LINE__, ptr);
return -1;
}
ptr += sizeof(empty_data);
}
net_nbuf_unref(buf);
return 0;
}
static int test_fragment_pull(void) static int test_fragment_pull(void)
{ {
#define FRAG_COUNT 7
struct net_buf *buf, *newbuf, *frags[FRAG_COUNT], *frag; struct net_buf *buf, *newbuf, *frags[FRAG_COUNT], *frag;
int i, bytes_before, bytes_after, amount = 10, bytes_before2; int i, bytes_before, bytes_after, amount = 10, bytes_before2;
@ -1348,10 +1196,6 @@ void main(void)
goto fail; goto fail;
} }
if (test_fragment_push() < 0) {
goto fail;
}
if (test_fragment_pull() < 0) { if (test_fragment_pull() < 0) {
goto fail; goto fail;
} }