blob: c0ad406b3fa1b7d5f80c0f851927082269f4bf67 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
Matteo Scandolo67654fa2017-06-09 09:33:17 -070016import unittest
Scott Baker1f7791d2018-10-04 13:21:20 -070017from xosgenx.generator import XOSProcessor, XOSProcessorArgs
18from helpers import XProtoTestHelpers
Sapan Bhatia1e397df2017-05-24 12:17:28 +020019
Zack Williams045b63d2019-01-22 16:30:57 -070020
Matteo Scandolo67654fa2017-06-09 09:33:17 -070021class XProtoRlinkTests(unittest.TestCase):
Sapan Bhatia1e397df2017-05-24 12:17:28 +020022 def test_proto_generator(self):
Zack Williams045b63d2019-01-22 16:30:57 -070023 target = XProtoTestHelpers.write_tmp_target(
24 """
Matteo Scandolo67654fa2017-06-09 09:33:17 -070025{% for m in proto.messages %}
26 {% for r in m.rlinks %}
27 {{ r }}
28 {% endfor %}
29{% endfor %}
Sapan Bhatia1e397df2017-05-24 12:17:28 +020030"""
Zack Williams045b63d2019-01-22 16:30:57 -070031 )
32
33 xproto = """
Sapan Bhatia1e397df2017-05-24 12:17:28 +020034message VRouterPort (PlCoreBase){
35 optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True];
36 required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False];
37 required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False];
38 required manytoone vrouter_service->VRouterService:device_ports = 4 [db_index = True, null = False, blank = False];
39}
40
41message VRouterService (Service) {
42 optional string rest_hostname = 1 [db_index = False, max_length = 255, null = True, content_type = "stripped", blank = True];
43 required int32 rest_port = 2 [default = 8181, null = False, db_index = False, blank = False];
44 required string rest_user = 3 [default = "onos", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False];
45 required string rest_pass = 4 [default = "rocks", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False];
46}
47
48message VRouterDevice (PlCoreBase){
49 optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True];
50 required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False];
51 required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False];
52 required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False];
53 required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
54}
55"""
Sapan Bhatia1e397df2017-05-24 12:17:28 +020056
Scott Baker1f7791d2018-10-04 13:21:20 -070057 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -070058 args.inputs = xproto
59 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080060 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070061 self.assertIn("'src_port': 'device_ports'", output)
62 self.assertIn("'src_port': 'ports'", output)
Sapan Bhatia1e397df2017-05-24 12:17:28 +020063
Zack Williams045b63d2019-01-22 16:30:57 -070064
65if __name__ == "__main__":
Sapan Bhatia1e397df2017-05-24 12:17:28 +020066 unittest.main()