2 * Copyright (c) 2014 VMware, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This file contains the definition of the switch object for the OVS.
25 #include "BufferMgmt.h"
26 #define OVS_MAX_VPORT_ARRAY_SIZE 1024
27 #define OVS_MAX_PID_ARRAY_SIZE 1024
29 #define OVS_VPORT_MASK (OVS_MAX_VPORT_ARRAY_SIZE - 1)
30 #define OVS_PID_MASK (OVS_MAX_PID_ARRAY_SIZE - 1)
32 #define OVS_INTERNAL_VPORT_DEFAULT_INDEX 0
34 //Tunnel port indicies
35 #define RESERVED_START_INDEX1 1
36 #define OVS_TUNNEL_INDEX_START RESERVED_START_INDEX1
37 #define OVS_VXLAN_VPORT_INDEX 2
38 #define OVS_GRE_VPORT_INDEX 3
39 #define OVS_GRE64_VPORT_INDEX 4
40 #define OVS_TUNNEL_INDEX_END OVS_GRE64_VPORT_INDEX
42 #define OVS_MAX_PHYS_ADAPTERS 32
43 #define OVS_MAX_IP_VPOR 32
45 #define OVS_HASH_BASIS 0x13578642
47 typedef struct _OVS_VPORT_ENTRY *POVS_VPORT_ENTRY;
49 typedef struct _OVS_DATAPATH
51 PLIST_ENTRY flowTable; // Contains OvsFlows.
52 UINT32 nFlows; // Number of entries in flowTable.
54 // List_Links queues[64]; // Hash table of queue IDs.
57 UINT64 hits; // Number of flow table hits.
58 UINT64 misses; // Number of flow table misses.
59 UINT64 lost; // Number of dropped misses.
61 /* Used to protect the flows in the flowtable. */
62 PNDIS_RW_LOCK_EX lock;
63 } OVS_DATAPATH, *POVS_DATAPATH;
68 * The context allocated per switch., For OVS, we only
69 * support one switch which corresponding to one datapath.
70 * Each datapath can have multiple logical bridges configured
71 * which is maintained by vswitchd.
74 typedef enum OVS_SWITCH_DATAFLOW_STATE
78 } OVS_SWITCH_DATAFLOW_STATE, *POVS_SWITCH_DATAFLOW_STATE;
80 typedef enum OVS_SWITCH_CONTROFLOW_STATE
85 } OVS_SWITCH_CONTROLFLOW_STATE, *POVS_SWITCH_CONTROLFLOW_STATE;
87 // XXX: Take care of alignment and grouping members by cacheline
88 typedef struct _OVS_SWITCH_CONTEXT
90 /* Coarse and fine-grained switch states. */
91 OVS_SWITCH_DATAFLOW_STATE dataFlowState;
92 OVS_SWITCH_CONTROLFLOW_STATE controlFlowState;
94 BOOLEAN isActivateFailed;
98 NDIS_SWITCH_PORT_ID externalPortId;
99 NDIS_SWITCH_PORT_ID internalPortId;
100 POVS_VPORT_ENTRY externalVport; // the virtual adapter vport
101 POVS_VPORT_ENTRY internalVport;
104 * XXX when we support multiple VXLAN ports, we will need a list entry
107 POVS_VPORT_ENTRY vxlanVport;
109 PLIST_ENTRY ovsPortNameHashArray; // based on ovsName
110 PLIST_ENTRY portIdHashArray; // based on portId
111 PLIST_ENTRY portNoHashArray; // based on ovs port number
112 PLIST_ENTRY pidHashArray; // based on packet pids
114 UINT32 numPhysicalNics;
115 UINT32 numVports; // include validation port
116 UINT32 lastPortIndex;
118 /* Lock taken over the switch. This protects the ports on the switch. */
119 PNDIS_RW_LOCK_EX dispatchLock;
122 OVS_DATAPATH datapath;
124 /* Handle to the OVSExt filter driver. Same as 'gOvsExtDriverHandle'. */
125 NDIS_HANDLE NdisFilterHandle;
127 /* Handle and callbacks exposed by the underlying hyper-v switch. */
128 NDIS_SWITCH_CONTEXT NdisSwitchContext;
129 NDIS_SWITCH_OPTIONAL_HANDLERS NdisSwitchHandlers;
131 volatile LONG pendingInjectedNblCount;
132 volatile LONG pendingOidCount;
134 OVS_NBL_POOL ovsPool;
135 } OVS_SWITCH_CONTEXT, *POVS_SWITCH_CONTEXT;
139 OvsAcquireDatapathRead(OVS_DATAPATH *datapath,
140 LOCK_STATE_EX *lockState,
144 NdisAcquireRWLockRead(datapath->lock, lockState,
145 dispatch ? NDIS_RWL_AT_DISPATCH_LEVEL : 0);
149 OvsAcquireDatapathWrite(OVS_DATAPATH *datapath,
150 LOCK_STATE_EX *lockState,
154 NdisAcquireRWLockWrite(datapath->lock, lockState,
155 dispatch ? NDIS_RWL_AT_DISPATCH_LEVEL : 0);
160 OvsReleaseDatapath(OVS_DATAPATH *datapath,
161 LOCK_STATE_EX *lockState)
164 NdisReleaseRWLock(datapath->lock, lockState);
168 PVOID OvsGetExternalVport();
170 #endif /* __SWITCH_H_ */