1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * Adapted for mlvpn by Laurent Coustet (c) 2015 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef MLVPN_REORDER_H 36 #define MLVPN_REORDER_H 37 38 #include "pkt.h" 39 40 /** 41 * @file 42 * mlvpn reorder 43 * 44 * Reorder library is a component which is designed to 45 * provide ordering of out of ordered packets based on 46 * sequence number present in pkt. 47 * 48 */ 49 50 51 struct mlvpn_reorder_buffer; 52 53 /** 54 * Create a new reorder buffer instance 55 * 56 * Allocate memory and initialize a new reorder buffer in that 57 * memory, returning the reorder buffer pointer to the user 58 * @param size 59 * Max number of elements that can be stored in the reorder buffer 60 * @return 61 * The initialized reorder buffer instance, or NULL on error 62 * On error case, mlvpn_errno will be set appropriately: 63 * - ENOMEM - no appropriate memory area found in which to create memzone 64 * - EINVAL - invalid parameters 65 */ 66 struct mlvpn_reorder_buffer * 67 mlvpn_reorder_create(unsigned int size); 68 69 /** 70 * Initializes given reorder buffer instance 71 * 72 * @param b 73 * Reorder buffer instance to initialize 74 * @param bufsize 75 * Size of the reorder buffer 76 * @param size 77 * Number of elements that can be stored in reorder buffer 78 * @return 79 * The initialized reorder buffer instance, or NULL on error 80 * On error case, mlvpn_errno will be set appropriately: 81 * - EINVAL - invalid parameters 82 */ 83 struct mlvpn_reorder_buffer * 84 mlvpn_reorder_init(struct mlvpn_reorder_buffer *b, unsigned int bufsize, 85 unsigned int size); 86 87 /** 88 * Reset the given reorder buffer instance with initial values. 89 * 90 * @param b 91 * Reorder buffer instance which has to be reset 92 */ 93 void 94 mlvpn_reorder_reset(struct mlvpn_reorder_buffer *b); 95 96 /** 97 * Free reorder buffer instance. 98 * 99 * @param b 100 * reorder buffer instance 101 * @return 102 * None 103 */ 104 void 105 mlvpn_reorder_free(struct mlvpn_reorder_buffer *b); 106 107 /** 108 * Insert given pkt in reorder buffer in its correct position 109 * 110 * The given pkt is to be reordered relative to other pkts in the system. 111 * The pkt must contain a sequence number which is then used to place 112 * the buffer in the correct position in the reorder buffer. Reordered 113 * packets can later be taken from the buffer using the mlvpn_reorder_drain() 114 * API. 115 * 116 * @param b 117 * Reorder buffer where the pkt has to be insemlvpnd. 118 * @param pkt 119 * pkt that needs to be inserted in reorder buffer. 120 * @return 121 * 0 on success 122 * -1 on error 123 * On error case, mlvpn_errno will be set appropriately: 124 * - ENOSPC - Cannot move existing pkts from reorder buffer to accommodate 125 * ealry pkt, but it can be accomodated by performing drain and then insert. 126 * - ERANGE - Too early or late pkt which is vastly out of range of expected 127 * window should be ingnored without any handling. 128 */ 129 int 130 mlvpn_reorder_insert(struct mlvpn_reorder_buffer *b, mlvpn_pkt_t *pkt); 131 132 /** 133 * Fetch reordered buffers 134 * 135 * Returns a set of in-order buffers from the reorder buffer structure. Gaps 136 * may be present in the sequence numbers of the pkt if packets have been 137 * delayed too long before reaching the reorder window, or have been previously 138 * dropped by the system. 139 * 140 * @param b 141 * Reorder buffer instance from which packets are to be drained 142 * @param pkts 143 * array of pkts where reordered packets will be insemlvpnd from reorder buffer 144 * @param max_pkts 145 * the number of elements in the pkts array. 146 * @return 147 * number of pkt pointers written to pkts. 0 <= N < max_pkts. 148 */ 149 unsigned int 150 mlvpn_reorder_drain(struct mlvpn_reorder_buffer *b, mlvpn_pkt_t **pkts, 151 unsigned max_pkts); 152 153 #endif /* MLVPN_REORDER_H */ 154