datapath-windows: Add port friendly name to OVS_VPORT_ENTRY
[cascardo/ovs.git] / datapath-windows / ovsext / Vport.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 #ifndef __VPORT_H_
18 #define __VPORT_H_ 1
19
20 #include "Switch.h"
21
22 #define OVS_MAX_DPPORTS             MAXUINT16
23 #define OVS_DPPORT_NUMBER_INVALID   OVS_MAX_DPPORTS
24 /*
25  * The local port (0) is a reserved port, that is not allowed to be be
26  * created by the netlink command vport add. On linux, this port is created
27  * at netlink command datapath new. However, on windows, we do not need to
28  * create it, and more, we shouldn't. The userspace attempts to create two
29  * internal vports, the LOCAL port (0) and the internal port (with any other
30  * port number). The non-LOCAL internal port is used in the userspace when it
31  * requests the internal port.
32  */
33 #define OVS_DPPORT_NUMBER_LOCAL    0
34
35 /*
36  * A Vport, or Virtual Port, is a port on the OVS. It can be one of the
37  * following types. Some of the Vports are "real" ports on the hyper-v switch,
38  * and some are not:
39  * - VIF port (VM's NIC)
40  * - External Adapters (physical NIC)
41  * - Internal Adapter (Virtual adapter exposed on the host).
42  * - Tunnel ports created by OVS userspace.
43  */
44
45 typedef enum {
46     OVS_STATE_UNKNOWN,
47     OVS_STATE_PORT_CREATED,
48     OVS_STATE_NIC_CREATED,
49     OVS_STATE_CONNECTED,
50     OVS_STATE_PORT_TEAR_DOWN,
51     OVS_STATE_PORT_DELETED,
52 } OVS_VPORT_STATE;
53
54 typedef struct _OVS_VPORT_STATS {
55     UINT64 rxPackets;
56     UINT64 txPackets;
57     UINT64 rxBytes;
58     UINT64 txBytes;
59 } OVS_VPORT_STATS;
60
61 typedef struct _OVS_VPORT_ERR_STATS {
62     UINT64  rxErrors;
63     UINT64  txErrors;
64     UINT64  rxDropped;
65     UINT64  txDropped;
66 } OVS_VPORT_ERR_STATS;
67
68 /* used for vport netlink commands. */
69 typedef struct _OVS_VPORT_FULL_STATS {
70     OVS_VPORT_STATS;
71     OVS_VPORT_ERR_STATS;
72 }OVS_VPORT_FULL_STATS;
73 /*
74  * Each internal, external adapter or vritual adapter has
75  * one vport entry. In addition, we have one vport for each
76  * tunnel type, such as vxlan, gre, gre64
77  */
78 typedef struct _OVS_VPORT_ENTRY {
79     LIST_ENTRY             ovsNameLink;
80     LIST_ENTRY             portIdLink;
81     LIST_ENTRY             portNoLink;
82
83     OVS_VPORT_STATE        ovsState;
84     OVS_VPORT_TYPE         ovsType;
85     OVS_VPORT_STATS        stats;
86     OVS_VPORT_ERR_STATS    errStats;
87     UINT32                 portNo;
88     UINT32                 mtu;
89     CHAR                   ovsName[OVS_MAX_PORT_NAME_LENGTH];
90     UINT32                 ovsNameLen;
91
92     PVOID                  priv;
93     NDIS_SWITCH_PORT_ID    portId;
94     NDIS_SWITCH_NIC_INDEX  nicIndex;
95     UINT16                 numaNodeId;
96     NDIS_SWITCH_PORT_STATE portState;
97     NDIS_SWITCH_NIC_STATE  nicState;
98     NDIS_SWITCH_PORT_TYPE  portType;
99
100     UINT8                  permMacAddress[MAC_ADDRESS_LEN];
101     UINT8                  currMacAddress[MAC_ADDRESS_LEN];
102     UINT8                  vmMacAddress[MAC_ADDRESS_LEN];
103
104     NDIS_SWITCH_PORT_NAME  hvPortName;
105     IF_COUNTED_STRING      portFriendlyName;
106     NDIS_SWITCH_NIC_NAME   nicName;
107     NDIS_VM_NAME           vmName;
108     GUID                   netCfgInstanceId;
109     BOOLEAN                isExternal;
110     UINT32                 upcallPid; /* netlink upcall port id */
111 } OVS_VPORT_ENTRY, *POVS_VPORT_ENTRY;
112
113 struct _OVS_SWITCH_CONTEXT;
114
115 POVS_VPORT_ENTRY
116 OvsFindVportByPortNo(struct _OVS_SWITCH_CONTEXT *switchContext,
117                      UINT32 portNo);
118 POVS_VPORT_ENTRY
119 OvsFindVportByOvsName(struct _OVS_SWITCH_CONTEXT *switchContext,
120                       CHAR *name, UINT32 length);
121 POVS_VPORT_ENTRY
122 OvsFindVportByHvName(POVS_SWITCH_CONTEXT switchContext, PSTR name);
123 POVS_VPORT_ENTRY
124 OvsFindVportByPortIdAndNicIndex(struct _OVS_SWITCH_CONTEXT *switchContext,
125                                 NDIS_SWITCH_PORT_ID portId,
126                                 NDIS_SWITCH_NIC_INDEX index);
127
128 NDIS_STATUS OvsAddConfiguredSwitchPorts(struct _OVS_SWITCH_CONTEXT *switchContext);
129 NDIS_STATUS OvsInitConfiguredSwitchNics(struct _OVS_SWITCH_CONTEXT *switchContext);
130
131 VOID OvsClearAllSwitchVports(struct _OVS_SWITCH_CONTEXT *switchContext);
132
133 NDIS_STATUS HvCreateNic(POVS_SWITCH_CONTEXT switchContext,
134                         PNDIS_SWITCH_NIC_PARAMETERS nicParam);
135 NDIS_STATUS HvCreatePort(POVS_SWITCH_CONTEXT switchContext,
136                          PNDIS_SWITCH_PORT_PARAMETERS portParam);
137 VOID HvTeardownPort(POVS_SWITCH_CONTEXT switchContext,
138                     PNDIS_SWITCH_PORT_PARAMETERS portParam);
139 VOID HvDeletePort(POVS_SWITCH_CONTEXT switchContext,
140                   PNDIS_SWITCH_PORT_PARAMETERS portParam);
141 VOID HvConnectNic(POVS_SWITCH_CONTEXT switchContext,
142                   PNDIS_SWITCH_NIC_PARAMETERS nicParam);
143 VOID HvUpdateNic(POVS_SWITCH_CONTEXT switchContext,
144                  PNDIS_SWITCH_NIC_PARAMETERS nicParam);
145 VOID HvDeleteNic(POVS_SWITCH_CONTEXT switchContext,
146                  PNDIS_SWITCH_NIC_PARAMETERS nicParam);
147 VOID HvDisconnectNic(POVS_SWITCH_CONTEXT switchContext,
148                      PNDIS_SWITCH_NIC_PARAMETERS nicParam);
149
150 static __inline BOOLEAN
151 OvsIsTunnelVportType(OVS_VPORT_TYPE ovsType)
152 {
153     return ovsType == OVS_VPORT_TYPE_VXLAN ||
154            ovsType == OVS_VPORT_TYPE_GRE ||
155            ovsType == OVS_VPORT_TYPE_GRE64;
156 }
157
158 static __inline BOOLEAN
159 OvsIsInternalVportType(OVS_VPORT_TYPE ovsType)
160 {
161     return ovsType == OVS_VPORT_TYPE_INTERNAL;
162 }
163
164 static __inline UINT32
165 OvsGetExternalMtu()
166 {
167     return ((POVS_VPORT_ENTRY) OvsGetExternalVport())->mtu;
168 }
169
170 #endif /* __VPORT_H_ */