Debian Codegraph @

neutron_vpnaas/db/vpn/vpn_models.py

raw
1 # (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # 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, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from neutron_lib.db import constants as db_const
17 from neutron_lib.db import model_base
18 import sqlalchemy as sa
19 from sqlalchemy import orm
20
21 from neutron.db.models import l3
22 from neutron.db import models_v2
23
24 from neutron_vpnaas.services.vpn.common import constants
25
26
27 AUTH_ALGORITHM_ENUM_VALUES = [
28 'sha1', 'sha256', 'sha384', 'sha512',
29 'aes-xcbc', 'aes-cmac',
30 ]
31
32 ENCRYPTION_ALGORITHM_ENUM_VALUES = [
33 '3des',
34 'aes-128', 'aes-192', 'aes-256',
35 'aes-128-ctr', 'aes-192-ctr', 'aes-256-ctr',
36 'aes-128-ccm-8', 'aes-192-ccm-8', 'aes-256-ccm-8',
37 'aes-128-ccm-12', 'aes-192-ccm-12', 'aes-256-ccm-12',
38 'aes-128-ccm-16', 'aes-192-ccm-16', 'aes-256-ccm-16',
39 'aes-128-gcm-8', 'aes-192-gcm-8', 'aes-256-gcm-8',
40 'aes-128-gcm-12', 'aes-192-gcm-12', 'aes-256-gcm-12',
41 'aes-128-gcm-16', 'aes-192-gcm-16', 'aes-256-gcm-16',
42 ]
43
44 PFS_ENUM_VALUES = [
45 'group2', 'group5', 'group14', 'group15',
46 'group16', 'group17', 'group18', 'group19', 'group20', 'group21',
47 'group22', 'group23', 'group24', 'group25', 'group26', 'group27',
48 'group28', 'group29', 'group30', 'group31',
49 ]
50
51
52 class IPsecPeerCidr(model_base.BASEV2):
53 """Internal representation of a IPsec Peer Cidrs."""
54
55 cidr = sa.Column(sa.String(32), nullable=False, primary_key=True)
56 ipsec_site_connection_id = sa.Column(
57 sa.String(36),
58 sa.ForeignKey('ipsec_site_connections.id',
59 ondelete="CASCADE"),
60 primary_key=True)
61
62
63 class IPsecPolicy(model_base.BASEV2, model_base.HasId, model_base.HasProject):
64 """Represents a v2 IPsecPolicy Object."""
65 __tablename__ = 'ipsecpolicies'
66 name = sa.Column(sa.String(db_const.NAME_FIELD_SIZE))
67 description = sa.Column(sa.String(db_const.DESCRIPTION_FIELD_SIZE))
68 transform_protocol = sa.Column(sa.Enum("esp", "ah", "ah-esp",
69 name="ipsec_transform_protocols"),
70 nullable=False)
71 auth_algorithm = sa.Column(sa.Enum(*AUTH_ALGORITHM_ENUM_VALUES,
72 name="vpn_auth_algorithms"),
73 nullable=False)
74 encryption_algorithm = sa.Column(sa.Enum(*ENCRYPTION_ALGORITHM_ENUM_VALUES,
75 name="vpn_encrypt_algorithms"),
76 nullable=False)
77 encapsulation_mode = sa.Column(sa.Enum("tunnel", "transport",
78 name="ipsec_encapsulations"),
79 nullable=False)
80 lifetime_units = sa.Column(sa.Enum("seconds", "kilobytes",
81 name="vpn_lifetime_units"),
82 nullable=False)
83 lifetime_value = sa.Column(sa.Integer, nullable=False)
84 pfs = sa.Column(sa.Enum(*PFS_ENUM_VALUES, name="vpn_pfs"), nullable=False)
85
86
87 class IKEPolicy(model_base.BASEV2, model_base.HasId, model_base.HasProject):
88 """Represents a v2 IKEPolicy Object."""
89 __tablename__ = 'ikepolicies'
90 name = sa.Column(sa.String(db_const.NAME_FIELD_SIZE))
91 description = sa.Column(sa.String(db_const.DESCRIPTION_FIELD_SIZE))
92 auth_algorithm = sa.Column(sa.Enum(*AUTH_ALGORITHM_ENUM_VALUES,
93 name="vpn_auth_algorithms"),
94 nullable=False)
95 encryption_algorithm = sa.Column(sa.Enum(*ENCRYPTION_ALGORITHM_ENUM_VALUES,
96 name="vpn_encrypt_algorithms"),
97 nullable=False)
98 phase1_negotiation_mode = sa.Column(sa.Enum("main", 'aggressive',
99 name="ike_phase1_mode"),
100 nullable=False)
101 lifetime_units = sa.Column(sa.Enum("seconds", "kilobytes",
102 name="vpn_lifetime_units"),
103 nullable=False)
104 lifetime_value = sa.Column(sa.Integer, nullable=False)
105 ike_version = sa.Column(sa.Enum("v1", "v2", name="ike_versions"),
106 nullable=False)
107 pfs = sa.Column(sa.Enum(*PFS_ENUM_VALUES, name="vpn_pfs"), nullable=False)
108
109
110 class IPsecSiteConnection(model_base.BASEV2, model_base.HasId,
111 model_base.HasProject):
112 """Represents a IPsecSiteConnection Object."""
113 __tablename__ = 'ipsec_site_connections'
114 name = sa.Column(sa.String(db_const.NAME_FIELD_SIZE))
115 description = sa.Column(sa.String(db_const.DESCRIPTION_FIELD_SIZE))
116 peer_address = sa.Column(sa.String(255), nullable=False)
117 peer_id = sa.Column(sa.String(255), nullable=False)
118 local_id = sa.Column(sa.String(255), nullable=True)
119 route_mode = sa.Column(sa.String(8), nullable=False)
120 mtu = sa.Column(sa.Integer, nullable=False)
121 initiator = sa.Column(sa.Enum("bi-directional", "response-only",
122 name="vpn_initiators"), nullable=False)
123 auth_mode = sa.Column(sa.String(16), nullable=False)
124 psk = sa.Column(sa.String(255), nullable=False)
125 dpd_action = sa.Column(sa.Enum("hold", "clear",
126 "restart", "disabled",
127 "restart-by-peer", name="vpn_dpd_actions"),
128 nullable=False)
129 dpd_interval = sa.Column(sa.Integer, nullable=False)
130 dpd_timeout = sa.Column(sa.Integer, nullable=False)
131 status = sa.Column(sa.String(16), nullable=False)
132 admin_state_up = sa.Column(sa.Boolean(), nullable=False)
133 vpnservice_id = sa.Column(sa.String(36),
134 sa.ForeignKey('vpnservices.id'),
135 nullable=False)
136 ipsecpolicy_id = sa.Column(sa.String(36),
137 sa.ForeignKey('ipsecpolicies.id'),
138 nullable=False)
139 ikepolicy_id = sa.Column(sa.String(36),
140 sa.ForeignKey('ikepolicies.id'),
141 nullable=False)
142 ipsecpolicy = orm.relationship(
143 IPsecPolicy, backref='ipsec_site_connection')
144 ikepolicy = orm.relationship(IKEPolicy, backref='ipsec_site_connection')
145 peer_cidrs = orm.relationship(IPsecPeerCidr,
146 backref='ipsec_site_connection',
147 lazy='joined',
148 cascade='all, delete, delete-orphan')
149 local_ep_group_id = sa.Column(sa.String(36),
150 sa.ForeignKey('vpn_endpoint_groups.id'))
151 peer_ep_group_id = sa.Column(sa.String(36),
152 sa.ForeignKey('vpn_endpoint_groups.id'))
153 local_ep_group = orm.relationship("VPNEndpointGroup",
154 foreign_keys=local_ep_group_id)
155 peer_ep_group = orm.relationship("VPNEndpointGroup",
156 foreign_keys=peer_ep_group_id)
157
158
159 class VPNService(model_base.BASEV2, model_base.HasId, model_base.HasProject):
160 """Represents a v2 VPNService Object."""
161 name = sa.Column(sa.String(db_const.NAME_FIELD_SIZE))
162 description = sa.Column(sa.String(db_const.DESCRIPTION_FIELD_SIZE))
163 status = sa.Column(sa.String(16), nullable=False)
164 admin_state_up = sa.Column(sa.Boolean(), nullable=False)
165 external_v4_ip = sa.Column(sa.String(16))
166 external_v6_ip = sa.Column(sa.String(64))
167 subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'))
168 router_id = sa.Column(sa.String(36), sa.ForeignKey('routers.id'),
169 nullable=False)
170 subnet = orm.relationship(models_v2.Subnet)
171 router = orm.relationship(l3.Router)
172 ipsec_site_connections = orm.relationship(
173 IPsecSiteConnection,
174 backref='vpnservice',
175 cascade="all, delete-orphan")
176 flavor_id = sa.Column(sa.String(36), sa.ForeignKey(
177 'flavors.id', name='fk_vpnservices_flavors_id'))
178
179
180 class VPNEndpoint(model_base.BASEV2):
181 """Endpoints used in VPN connections.
182
183 All endpoints in a group must be of the same type. Note: the endpoint
184 is an 'opaque' field used to hold different endpoint types, and be
185 flexible enough to use for future types.
186 """
187 __tablename__ = 'vpn_endpoints'
188 endpoint = sa.Column(sa.String(255), nullable=False, primary_key=True)
189 endpoint_group_id = sa.Column(sa.String(36),
190 sa.ForeignKey('vpn_endpoint_groups.id',
191 ondelete="CASCADE"),
192 primary_key=True)
193
194
195 class VPNEndpointGroup(model_base.BASEV2, model_base.HasId,
196 model_base.HasProject):
197 """Collection of endpoints of a specific type, for VPN connections."""
198 __tablename__ = 'vpn_endpoint_groups'
199 name = sa.Column(sa.String(db_const.NAME_FIELD_SIZE))
200 description = sa.Column(sa.String(db_const.DESCRIPTION_FIELD_SIZE))
201 endpoint_type = sa.Column(sa.Enum(*constants.VPN_SUPPORTED_ENDPOINT_TYPES,
202 name="endpoint_type"),
203 nullable=False)
204 endpoints = orm.relationship(VPNEndpoint,
205 backref='endpoint_group',
206 lazy='joined',
207 cascade='all, delete, delete-orphan')