blob: ba025abc2d5903ad47e10e06f2a27936aeb465d6 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2# Copyright 2017-present Open Networking Foundation
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
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080018from xosgenx.generator import XOSProcessor
Matteo Scandolo67654fa2017-06-09 09:33:17 -070019from helpers import FakeArgs, XProtoTestHelpers
Sapan Bhatia1e397df2017-05-24 12:17:28 +020020
Matteo Scandolo67654fa2017-06-09 09:33:17 -070021class XProtoRlinkTests(unittest.TestCase):
Sapan Bhatia1e397df2017-05-24 12:17:28 +020022 def test_proto_generator(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070023 target = XProtoTestHelpers.write_tmp_target("""
24{% for m in proto.messages %}
25 {% for r in m.rlinks %}
26 {{ r }}
27 {% endfor %}
28{% endfor %}
29""")
30
Sapan Bhatia1e397df2017-05-24 12:17:28 +020031 xproto = \
32"""
33message VRouterPort (PlCoreBase){
34 optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True];
35 required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False];
36 required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False];
37 required manytoone vrouter_service->VRouterService:device_ports = 4 [db_index = True, null = False, blank = False];
38}
39
40message VRouterService (Service) {
41 optional string rest_hostname = 1 [db_index = False, max_length = 255, null = True, content_type = "stripped", blank = True];
42 required int32 rest_port = 2 [default = 8181, null = False, db_index = False, blank = False];
43 required string rest_user = 3 [default = "onos", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False];
44 required string rest_pass = 4 [default = "rocks", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False];
45}
46
47message VRouterDevice (PlCoreBase){
48 optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True];
49 required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False];
50 required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False];
51 required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False];
52 required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
53}
54"""
Sapan Bhatia1e397df2017-05-24 12:17:28 +020055
Matteo Scandolo67654fa2017-06-09 09:33:17 -070056 args = FakeArgs()
57 args.inputs = xproto
58 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080059 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070060 self.assertIn("'src_port': 'device_ports'", output)
61 self.assertIn("'src_port': 'ports'", output)
Sapan Bhatia1e397df2017-05-24 12:17:28 +020062
63if __name__ == '__main__':
64 unittest.main()
65
66