save loops

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Tue Dec 02 08:29:59 2014 +0000
Revision:
1:3be7b7d050f4
Parent:
0:df6fdd9b99f0
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:df6fdd9b99f0 1 /*
mbedalvaro 0:df6fdd9b99f0 2 * Definitions for tcp compression routines.
mbedalvaro 0:df6fdd9b99f0 3 *
mbedalvaro 0:df6fdd9b99f0 4 * $Id: vj.h,v 1.7 2010/02/22 17:52:09 goldsimon Exp $
mbedalvaro 0:df6fdd9b99f0 5 *
mbedalvaro 0:df6fdd9b99f0 6 * Copyright (c) 1989 Regents of the University of California.
mbedalvaro 0:df6fdd9b99f0 7 * All rights reserved.
mbedalvaro 0:df6fdd9b99f0 8 *
mbedalvaro 0:df6fdd9b99f0 9 * Redistribution and use in source and binary forms are permitted
mbedalvaro 0:df6fdd9b99f0 10 * provided that the above copyright notice and this paragraph are
mbedalvaro 0:df6fdd9b99f0 11 * duplicated in all such forms and that any documentation,
mbedalvaro 0:df6fdd9b99f0 12 * advertising materials, and other materials related to such
mbedalvaro 0:df6fdd9b99f0 13 * distribution and use acknowledge that the software was developed
mbedalvaro 0:df6fdd9b99f0 14 * by the University of California, Berkeley. The name of the
mbedalvaro 0:df6fdd9b99f0 15 * University may not be used to endorse or promote products derived
mbedalvaro 0:df6fdd9b99f0 16 * from this software without specific prior written permission.
mbedalvaro 0:df6fdd9b99f0 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
mbedalvaro 0:df6fdd9b99f0 18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
mbedalvaro 0:df6fdd9b99f0 19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
mbedalvaro 0:df6fdd9b99f0 20 *
mbedalvaro 0:df6fdd9b99f0 21 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
mbedalvaro 0:df6fdd9b99f0 22 * - Initial distribution.
mbedalvaro 0:df6fdd9b99f0 23 */
mbedalvaro 0:df6fdd9b99f0 24
mbedalvaro 0:df6fdd9b99f0 25 #ifndef VJ_H
mbedalvaro 0:df6fdd9b99f0 26 #define VJ_H
mbedalvaro 0:df6fdd9b99f0 27
mbedalvaro 0:df6fdd9b99f0 28 #include "lwip/ip.h"
mbedalvaro 0:df6fdd9b99f0 29 #include "lwip/tcp_impl.h"
mbedalvaro 0:df6fdd9b99f0 30
mbedalvaro 0:df6fdd9b99f0 31 #define MAX_SLOTS 16 /* must be > 2 and < 256 */
mbedalvaro 0:df6fdd9b99f0 32 #define MAX_HDR 128
mbedalvaro 0:df6fdd9b99f0 33
mbedalvaro 0:df6fdd9b99f0 34 /*
mbedalvaro 0:df6fdd9b99f0 35 * Compressed packet format:
mbedalvaro 0:df6fdd9b99f0 36 *
mbedalvaro 0:df6fdd9b99f0 37 * The first octet contains the packet type (top 3 bits), TCP
mbedalvaro 0:df6fdd9b99f0 38 * 'push' bit, and flags that indicate which of the 4 TCP sequence
mbedalvaro 0:df6fdd9b99f0 39 * numbers have changed (bottom 5 bits). The next octet is a
mbedalvaro 0:df6fdd9b99f0 40 * conversation number that associates a saved IP/TCP header with
mbedalvaro 0:df6fdd9b99f0 41 * the compressed packet. The next two octets are the TCP checksum
mbedalvaro 0:df6fdd9b99f0 42 * from the original datagram. The next 0 to 15 octets are
mbedalvaro 0:df6fdd9b99f0 43 * sequence number changes, one change per bit set in the header
mbedalvaro 0:df6fdd9b99f0 44 * (there may be no changes and there are two special cases where
mbedalvaro 0:df6fdd9b99f0 45 * the receiver implicitly knows what changed -- see below).
mbedalvaro 0:df6fdd9b99f0 46 *
mbedalvaro 0:df6fdd9b99f0 47 * There are 5 numbers which can change (they are always inserted
mbedalvaro 0:df6fdd9b99f0 48 * in the following order): TCP urgent pointer, window,
mbedalvaro 0:df6fdd9b99f0 49 * acknowlegement, sequence number and IP ID. (The urgent pointer
mbedalvaro 0:df6fdd9b99f0 50 * is different from the others in that its value is sent, not the
mbedalvaro 0:df6fdd9b99f0 51 * change in value.) Since typical use of SLIP links is biased
mbedalvaro 0:df6fdd9b99f0 52 * toward small packets (see comments on MTU/MSS below), changes
mbedalvaro 0:df6fdd9b99f0 53 * use a variable length coding with one octet for numbers in the
mbedalvaro 0:df6fdd9b99f0 54 * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
mbedalvaro 0:df6fdd9b99f0 55 * range 256 - 65535 or 0. (If the change in sequence number or
mbedalvaro 0:df6fdd9b99f0 56 * ack is more than 65535, an uncompressed packet is sent.)
mbedalvaro 0:df6fdd9b99f0 57 */
mbedalvaro 0:df6fdd9b99f0 58
mbedalvaro 0:df6fdd9b99f0 59 /*
mbedalvaro 0:df6fdd9b99f0 60 * Packet types (must not conflict with IP protocol version)
mbedalvaro 0:df6fdd9b99f0 61 *
mbedalvaro 0:df6fdd9b99f0 62 * The top nibble of the first octet is the packet type. There are
mbedalvaro 0:df6fdd9b99f0 63 * three possible types: IP (not proto TCP or tcp with one of the
mbedalvaro 0:df6fdd9b99f0 64 * control flags set); uncompressed TCP (a normal IP/TCP packet but
mbedalvaro 0:df6fdd9b99f0 65 * with the 8-bit protocol field replaced by an 8-bit connection id --
mbedalvaro 0:df6fdd9b99f0 66 * this type of packet syncs the sender & receiver); and compressed
mbedalvaro 0:df6fdd9b99f0 67 * TCP (described above).
mbedalvaro 0:df6fdd9b99f0 68 *
mbedalvaro 0:df6fdd9b99f0 69 * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
mbedalvaro 0:df6fdd9b99f0 70 * is logically part of the 4-bit "changes" field that follows. Top
mbedalvaro 0:df6fdd9b99f0 71 * three bits are actual packet type. For backward compatibility
mbedalvaro 0:df6fdd9b99f0 72 * and in the interest of conserving bits, numbers are chosen so the
mbedalvaro 0:df6fdd9b99f0 73 * IP protocol version number (4) which normally appears in this nibble
mbedalvaro 0:df6fdd9b99f0 74 * means "IP packet".
mbedalvaro 0:df6fdd9b99f0 75 */
mbedalvaro 0:df6fdd9b99f0 76
mbedalvaro 0:df6fdd9b99f0 77 /* packet types */
mbedalvaro 0:df6fdd9b99f0 78 #define TYPE_IP 0x40
mbedalvaro 0:df6fdd9b99f0 79 #define TYPE_UNCOMPRESSED_TCP 0x70
mbedalvaro 0:df6fdd9b99f0 80 #define TYPE_COMPRESSED_TCP 0x80
mbedalvaro 0:df6fdd9b99f0 81 #define TYPE_ERROR 0x00
mbedalvaro 0:df6fdd9b99f0 82
mbedalvaro 0:df6fdd9b99f0 83 /* Bits in first octet of compressed packet */
mbedalvaro 0:df6fdd9b99f0 84 #define NEW_C 0x40 /* flag bits for what changed in a packet */
mbedalvaro 0:df6fdd9b99f0 85 #define NEW_I 0x20
mbedalvaro 0:df6fdd9b99f0 86 #define NEW_S 0x08
mbedalvaro 0:df6fdd9b99f0 87 #define NEW_A 0x04
mbedalvaro 0:df6fdd9b99f0 88 #define NEW_W 0x02
mbedalvaro 0:df6fdd9b99f0 89 #define NEW_U 0x01
mbedalvaro 0:df6fdd9b99f0 90
mbedalvaro 0:df6fdd9b99f0 91 /* reserved, special-case values of above */
mbedalvaro 0:df6fdd9b99f0 92 #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
mbedalvaro 0:df6fdd9b99f0 93 #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
mbedalvaro 0:df6fdd9b99f0 94 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
mbedalvaro 0:df6fdd9b99f0 95
mbedalvaro 0:df6fdd9b99f0 96 #define TCP_PUSH_BIT 0x10
mbedalvaro 0:df6fdd9b99f0 97
mbedalvaro 0:df6fdd9b99f0 98
mbedalvaro 0:df6fdd9b99f0 99 /*
mbedalvaro 0:df6fdd9b99f0 100 * "state" data for each active tcp conversation on the wire. This is
mbedalvaro 0:df6fdd9b99f0 101 * basically a copy of the entire IP/TCP header from the last packet
mbedalvaro 0:df6fdd9b99f0 102 * we saw from the conversation together with a small identifier
mbedalvaro 0:df6fdd9b99f0 103 * the transmit & receive ends of the line use to locate saved header.
mbedalvaro 0:df6fdd9b99f0 104 */
mbedalvaro 0:df6fdd9b99f0 105 struct cstate {
mbedalvaro 0:df6fdd9b99f0 106 struct cstate *cs_next; /* next most recently used state (xmit only) */
mbedalvaro 0:df6fdd9b99f0 107 u_short cs_hlen; /* size of hdr (receive only) */
mbedalvaro 0:df6fdd9b99f0 108 u_char cs_id; /* connection # associated with this state */
mbedalvaro 0:df6fdd9b99f0 109 u_char cs_filler;
mbedalvaro 0:df6fdd9b99f0 110 union {
mbedalvaro 0:df6fdd9b99f0 111 char csu_hdr[MAX_HDR];
mbedalvaro 0:df6fdd9b99f0 112 struct ip_hdr csu_ip; /* ip/tcp hdr from most recent packet */
mbedalvaro 0:df6fdd9b99f0 113 } vjcs_u;
mbedalvaro 0:df6fdd9b99f0 114 };
mbedalvaro 0:df6fdd9b99f0 115 #define cs_ip vjcs_u.csu_ip
mbedalvaro 0:df6fdd9b99f0 116 #define cs_hdr vjcs_u.csu_hdr
mbedalvaro 0:df6fdd9b99f0 117
mbedalvaro 0:df6fdd9b99f0 118
mbedalvaro 0:df6fdd9b99f0 119 struct vjstat {
mbedalvaro 0:df6fdd9b99f0 120 unsigned long vjs_packets; /* outbound packets */
mbedalvaro 0:df6fdd9b99f0 121 unsigned long vjs_compressed; /* outbound compressed packets */
mbedalvaro 0:df6fdd9b99f0 122 unsigned long vjs_searches; /* searches for connection state */
mbedalvaro 0:df6fdd9b99f0 123 unsigned long vjs_misses; /* times couldn't find conn. state */
mbedalvaro 0:df6fdd9b99f0 124 unsigned long vjs_uncompressedin; /* inbound uncompressed packets */
mbedalvaro 0:df6fdd9b99f0 125 unsigned long vjs_compressedin; /* inbound compressed packets */
mbedalvaro 0:df6fdd9b99f0 126 unsigned long vjs_errorin; /* inbound unknown type packets */
mbedalvaro 0:df6fdd9b99f0 127 unsigned long vjs_tossed; /* inbound packets tossed because of error */
mbedalvaro 0:df6fdd9b99f0 128 };
mbedalvaro 0:df6fdd9b99f0 129
mbedalvaro 0:df6fdd9b99f0 130 /*
mbedalvaro 0:df6fdd9b99f0 131 * all the state data for one serial line (we need one of these per line).
mbedalvaro 0:df6fdd9b99f0 132 */
mbedalvaro 0:df6fdd9b99f0 133 struct vjcompress {
mbedalvaro 0:df6fdd9b99f0 134 struct cstate *last_cs; /* most recently used tstate */
mbedalvaro 0:df6fdd9b99f0 135 u_char last_recv; /* last rcvd conn. id */
mbedalvaro 0:df6fdd9b99f0 136 u_char last_xmit; /* last sent conn. id */
mbedalvaro 0:df6fdd9b99f0 137 u_short flags;
mbedalvaro 0:df6fdd9b99f0 138 u_char maxSlotIndex;
mbedalvaro 0:df6fdd9b99f0 139 u_char compressSlot; /* Flag indicating OK to compress slot ID. */
mbedalvaro 0:df6fdd9b99f0 140 #if LINK_STATS
mbedalvaro 0:df6fdd9b99f0 141 struct vjstat stats;
mbedalvaro 0:df6fdd9b99f0 142 #endif
mbedalvaro 0:df6fdd9b99f0 143 struct cstate tstate[MAX_SLOTS]; /* xmit connection states */
mbedalvaro 0:df6fdd9b99f0 144 struct cstate rstate[MAX_SLOTS]; /* receive connection states */
mbedalvaro 0:df6fdd9b99f0 145 };
mbedalvaro 0:df6fdd9b99f0 146
mbedalvaro 0:df6fdd9b99f0 147 /* flag values */
mbedalvaro 0:df6fdd9b99f0 148 #define VJF_TOSS 1U /* tossing rcvd frames because of input err */
mbedalvaro 0:df6fdd9b99f0 149
mbedalvaro 0:df6fdd9b99f0 150 extern void vj_compress_init (struct vjcompress *comp);
mbedalvaro 0:df6fdd9b99f0 151 extern u_int vj_compress_tcp (struct vjcompress *comp, struct pbuf *pb);
mbedalvaro 0:df6fdd9b99f0 152 extern void vj_uncompress_err (struct vjcompress *comp);
mbedalvaro 0:df6fdd9b99f0 153 extern int vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp);
mbedalvaro 0:df6fdd9b99f0 154 extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp);
mbedalvaro 0:df6fdd9b99f0 155
mbedalvaro 0:df6fdd9b99f0 156 #endif /* VJ_H */