datapath-windows: Rename switch context's nameHashArray and vport's nameLink login...
[cascardo/ovs.git] / datapath-windows / ovsext / Switch.h
1 /*
2  * Copyright (c) 2014 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 /*
18  * This file contains the definition of the switch object for the OVS.
19  */
20
21 #ifndef __SWITCH_H_
22 #define __SWITCH_H_ 1
23
24 #include "NetProto.h"
25 #include "BufferMgmt.h"
26 #define OVS_MAX_VPORT_ARRAY_SIZE 1024
27
28 #define OVS_VPORT_MASK (OVS_MAX_VPORT_ARRAY_SIZE - 1)
29
30 #define OVS_INTERNAL_VPORT_DEFAULT_INDEX 0
31
32 //Tunnel port indicies
33 #define RESERVED_START_INDEX1    1
34 #define OVS_TUNNEL_INDEX_START RESERVED_START_INDEX1
35 #define OVS_VXLAN_VPORT_INDEX    2
36 #define OVS_GRE_VPORT_INDEX      3
37 #define OVS_GRE64_VPORT_INDEX    4
38 #define OVS_TUNNEL_INDEX_END OVS_GRE64_VPORT_INDEX
39
40 #define OVS_EXTERNAL_VPORT_START 8
41 #define OVS_EXTERNAL_VPORT_END   40
42 #define OVS_INTERNAL_VPORT_START 40
43 #define OVS_INTERNAL_VPOR_END    72
44 #define OVS_VM_VPORT_START       72
45 #define OVS_VM_VPORT_MAX         0xffff
46 #define OVS_VPORT_INDEX(_portNo)    ((_portNo) & 0xffffff)
47 #define OVS_VPORT_PORT_NO(_index, _gen) \
48           (((_index) & 0xffffff) | ((UINT32)(_gen) << 24))
49 #define OVS_VPORT_GEN(portNo) (portNo >> 24)
50
51 #define OVS_MAX_PHYS_ADAPTERS    32
52 #define OVS_MAX_IP_VPOR          32
53
54 #define OVS_HASH_BASIS   0x13578642
55
56 typedef struct _OVS_VPORT_ENTRY *POVS_VPORT_ENTRY;
57
58 typedef struct _OVS_DATAPATH
59 {
60    PLIST_ENTRY             flowTable;       // Contains OvsFlows.
61    UINT32                  nFlows;          // Number of entries in flowTable.
62
63    // List_Links              queues[64];      // Hash table of queue IDs.
64
65    /* Statistics. */
66    UINT64                  hits;            // Number of flow table hits.
67    UINT64                  misses;          // Number of flow table misses.
68    UINT64                  lost;            // Number of dropped misses.
69
70    /* Used to protect the flows in the flowtable. */
71    PNDIS_RW_LOCK_EX        lock;
72 } OVS_DATAPATH, *POVS_DATAPATH;
73
74 /*
75  * OVS_SWITCH_CONTEXT
76  *
77  * The context allocated per switch., For OVS, we only
78  * support one switch which corresponding to one datapath.
79  * Each datapath can have multiple logical bridges configured
80  * which is maintained by vswitchd.
81  */
82
83 typedef enum OVS_SWITCH_DATAFLOW_STATE
84 {
85     OvsSwitchPaused,
86     OvsSwitchRunning
87 } OVS_SWITCH_DATAFLOW_STATE, *POVS_SWITCH_DATAFLOW_STATE;
88
89 typedef enum OVS_SWITCH_CONTROFLOW_STATE
90 {
91     OvsSwitchUnknown,
92     OvsSwitchAttached,
93     OvsSwitchDetached
94 } OVS_SWITCH_CONTROLFLOW_STATE, *POVS_SWITCH_CONTROLFLOW_STATE;
95
96 // XXX: Take care of alignment and grouping members by cacheline
97 typedef struct _OVS_SWITCH_CONTEXT
98 {
99     /* Coarse and fine-grained switch states. */
100     OVS_SWITCH_DATAFLOW_STATE dataFlowState;
101     OVS_SWITCH_CONTROLFLOW_STATE controlFlowState;
102     BOOLEAN                 isActivated;
103     BOOLEAN                 isActivateFailed;
104
105     UINT32                  dpNo;
106
107     NDIS_SWITCH_PORT_ID     externalPortId;
108     NDIS_SWITCH_PORT_ID     internalPortId;
109     POVS_VPORT_ENTRY        externalVport;  // the virtual adapter vport
110     POVS_VPORT_ENTRY        internalVport;
111
112     PVOID                  *vportArray;
113     PLIST_ENTRY             ovsPortNameHashArray;  // based on ovsName
114     PLIST_ENTRY             portHashArray;  // based on portId
115
116     UINT32                  numPhysicalNics;
117     UINT32                  numVports;     // include validation port
118     UINT32                  lastPortIndex;
119
120     /* Lock taken over the switch. This protects the ports on the switch. */
121     PNDIS_RW_LOCK_EX        dispatchLock;
122
123     /* The flowtable. */
124     OVS_DATAPATH            datapath;
125
126     /* Handle to the OVSExt filter driver. Same as 'gOvsExtDriverHandle'. */
127     NDIS_HANDLE NdisFilterHandle;
128
129     /* Handle and callbacks exposed by the underlying hyper-v switch. */
130     NDIS_SWITCH_CONTEXT NdisSwitchContext;
131     NDIS_SWITCH_OPTIONAL_HANDLERS NdisSwitchHandlers;
132
133     volatile LONG pendingInjectedNblCount;
134     volatile LONG pendingOidCount;
135
136     OVS_NBL_POOL            ovsPool;
137 } OVS_SWITCH_CONTEXT, *POVS_SWITCH_CONTEXT;
138
139
140 static __inline VOID
141 OvsAcquireDatapathRead(OVS_DATAPATH *datapath,
142                        LOCK_STATE_EX *lockState,
143                        BOOLEAN dispatch)
144 {
145     ASSERT(datapath);
146     NdisAcquireRWLockRead(datapath->lock, lockState, dispatch);
147 }
148
149 static __inline VOID
150 OvsAcquireDatapathWrite(OVS_DATAPATH *datapath,
151                         LOCK_STATE_EX *lockState,
152                         BOOLEAN dispatch)
153 {
154     ASSERT(datapath);
155     NdisAcquireRWLockWrite(datapath->lock, lockState, dispatch);
156 }
157
158
159 static __inline VOID
160 OvsReleaseDatapath(OVS_DATAPATH *datapath,
161                    LOCK_STATE_EX *lockState)
162 {
163     ASSERT(datapath);
164     NdisReleaseRWLock(datapath->lock, lockState);
165 }
166
167
168 PVOID OvsGetVportFromIndex(UINT16 index);
169 PVOID OvsGetExternalVport();
170
171 #endif /* __SWITCH_H_ */