9a453791f92475af0b039564ed8fc3cd2dd61648
[cascardo/ovs.git] / datapath-windows / ovsext / Stt.h
1 /*
2  * Copyright (c) 2015 VMware, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __OVS_STT_H_
18 #define __OVS_STT_H_ 1
19
20 #define STT_TCP_PORT 7471
21 #define STT_TCP_PORT_NBO 0x2f1d
22
23 #define MAX_IP_TOTAL_LEN 65535
24
25 // STT defines.
26 #define STT_SEQ_LEN_SHIFT 16
27 #define STT_SEQ_OFFSET_MASK ((1 << STT_SEQ_LEN_SHIFT) - 1)
28 #define STT_FRAME_LEN(seq) ((seq) >> STT_SEQ_LEN_SHIFT)
29 #define STT_SEGMENT_OFF(seq) ((seq) & STT_SEQ_OFFSET_MASK)
30
31 #define STT_CSUM_VERIFIED   (1 << 0)
32 #define STT_CSUM_PARTIAL    (1 << 1)
33 #define STT_PROTO_IPV4      (1 << 2)
34 #define STT_PROTO_TCP       (1 << 3)
35 #define STT_PROTO_TYPES     (STT_PROTO_IPV4 | STT_PROTO_TCP)
36
37 #define STT_HASH_TABLE_SIZE ((UINT32)1 << 10)
38 #define STT_HASH_TABLE_MASK (STT_HASH_TABLE_SIZE - 1)
39 #define STT_ENTRY_TIMEOUT 300000000   // 30s
40 #define STT_CLEANUP_INTERVAL 300000000 // 30s
41
42 #define STT_ETH_PAD 2
43 typedef struct SttHdr {
44     UINT8    version;
45     UINT8    flags;
46     UINT8    l4Offset;
47     UINT8    reserved;
48     UINT16   mss;
49     UINT16   vlanTCI;
50     UINT64   key;
51 } SttHdr, *PSttHdr;
52
53 #define STT_HDR_LEN (sizeof(SttHdr) + STT_ETH_PAD)
54
55 typedef struct _OVS_STT_VPORT {
56     UINT16 dstPort;
57     UINT64 ackNo;
58     UINT64 ipId;
59
60     UINT64 inPkts;
61     UINT64 outPkts;
62     UINT64 slowInPkts;
63     UINT64 slowOutPkts;
64 } OVS_STT_VPORT, *POVS_STT_VPORT;
65
66 typedef struct _OVS_STT_PKT_KEY {
67     UINT32 sAddr;
68     UINT32 dAddr;
69     UINT32 ackSeq;
70 } OVS_STT_PKT_KEY, *POVS_STT_PKT_KEY;
71
72 typedef struct _OVS_STT_PKT_ENTRY {
73     OVS_STT_PKT_KEY     ovsPktKey;
74     UINT64              timeout;
75     UINT32              recvdLen;
76     SttHdr              sttHdr;
77     PCHAR               packetBuf;
78     LIST_ENTRY          link;
79 } OVS_STT_PKT_ENTRY, *POVS_STT_PKT_ENTRY;
80
81 typedef struct _OVS_STT_THREAD_CTX {
82     KEVENT      event;
83     PVOID       threadObject;
84     UINT32      exit;
85 } OVS_STT_THREAD_CTX, *POVS_STT_THREAD_CTX;
86
87 NTSTATUS OvsInitSttTunnel(POVS_VPORT_ENTRY vport,
88                           UINT16 udpDestPort);
89
90 VOID OvsCleanupSttTunnel(POVS_VPORT_ENTRY vport);
91
92 NDIS_STATUS OvsEncapStt(POVS_VPORT_ENTRY vport,
93                         PNET_BUFFER_LIST curNbl,
94                         OvsIPv4TunnelKey *tunKey,
95                         POVS_SWITCH_CONTEXT switchContext,
96                         POVS_PACKET_HDR_INFO layers,
97                         PNET_BUFFER_LIST *newNbl);
98
99
100 NDIS_STATUS OvsDecapStt(POVS_SWITCH_CONTEXT switchContext,
101                         PNET_BUFFER_LIST curNbl,
102                         OvsIPv4TunnelKey *tunKey,
103                         PNET_BUFFER_LIST *newNbl);
104
105 NTSTATUS OvsInitSttDefragmentation();
106
107 VOID OvsCleanupSttDefragmentation(VOID);
108
109 static __inline UINT32
110 OvsGetSttTunHdrSize(VOID)
111 {
112     return sizeof (EthHdr) + sizeof(IPHdr) + sizeof(TCPHdr) +
113                   STT_HDR_LEN;
114 }
115
116 #endif /*__OVS_STT_H_ */