blob: 78f5cf451cf577c168032ed40e1c1987f334d138 [file] [log] [blame]
Khen Nursimulua7b842a2016-12-03 23:28:42 -05001#!/usr/bin/env python
2#
3# Copyright 2016 the original author or authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17from constants import Constants as C
18
19class Capabilities:
20
21 def __init__(self):
Khen Nursimuluaaac7ee2016-12-11 22:03:52 -050022 self.server_caps = self._get_server_capabilities()
Khen Nursimulua7b842a2016-12-03 23:28:42 -050023 self.client_caps = set()
24
25 def add_client_capability(self, cap):
26 self.client_caps.add(cap)
27
Khen Nursimuluaaac7ee2016-12-11 22:03:52 -050028 #TODO: This will be automatically generated from the voltha proto files
29 def _get_server_capabilities(self):
30 return (
31 C.NETCONF_BASE_10,
32 C.NETCONF_BASE_11,
Khen Nursimulu7626ce12016-12-21 11:51:46 -050033 "urn:ietf:params:netconf:capability:writable-running:1.0",
Khen Nursimuluaaac7ee2016-12-11 22:03:52 -050034 "urn:opencord:params:xml:ns:voltha:ietf-voltha",
35 "urn:opencord:params:xml:ns:voltha:ietf-openflow_13",
36 "urn:opencord:params:xml:ns:voltha:ietf-meta",
37 "urn:opencord:params:xml:ns:voltha:ietf-logical_device",
38 "urn:opencord:params:xml:ns:voltha:ietf-health",
39 "urn:opencord:params:xml:ns:voltha:ietf-device",
40 "urn:opencord:params:xml:ns:voltha:ietf-empty",
41 "urn:opencord:params:xml:ns:voltha:ietf-common",
42 "urn:opencord:params:xml:ns:voltha:ietf-any",
43 "urn:opencord:params:xml:ns:voltha:ietf-adapter"
44 )
45
46 #TODO: A schema exchange will also need to happen
47
48 description = """
49
50 Option 1: Client already have the yang model for voltha and adapters:
51 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
52 <capabilities>
53 <capability>
54 urn:ietf:params:netconf:base:1.1
55 </capability>
56 <capability>
57 urn:cord:voltha:1.0
58 </capability>
59 <capability>
60 urn:cord:voltha:adpater_x:1.0
61 </capability>
62
63
64 Option 2: NETCONF-MONITORING - schema exchanges
65
66 server expose capabilities
67
68 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
69 <capabilities>
70 <capability>
71 urn:ietf:params:netconf:base:1.1
72 </capability>
73 <capability>
74 urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&revision=2010-10-04
75 </capability>
76
77 client request schemas
78
79 <rpc message-id="101"
80 xmlns="urn:ietf:params:xml:ns:netconf:base:1.1">
81 <get>
82 <filter type="subtree">
83 <netconf-state xmlns=
84 "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
85 <schemas/>
86 </netconf-state>
87 </filter>
88 </get>
89 </rpc>
90
91 server sends back schemas
92
93 <rpc-reply message-id="101"
94 xmlns="urn:ietf:params:xml:ns:netconf:base:1.1">
95 <data>
96 <netconf-state
97 xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
98 <schemas>
99 <schema>
100 <identifier>voltha</identifier>
101 <version>1.0</version>
102 <format>yang</format>
103 <namespace>urn:cord:voltha</namespace>
104 <location>NETCONF</location>
105 </schema>
106 <schema>
107 <identifier>adapter_x</identifier>
108 <version>x_release</version>
109 <format>yang</format>
110 <namespace>urn:cord:voltha:adapter_x</namespace>
111 <location>NETCONF</location>
112 </schema>
113 </schemas>
114 </netconf-state>
115 </data>
116 </rpc-reply>
117
118
119 client requests each schema instance
120
121 <rpc message-id="102"
122 xmlns="urn:ietf:params:xml:ns:netconf:base:1.1">
123 <get-schema
124 xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
125 <identifer>voltha</identifer>
126 <version>1.0</version>
127 </get-schema>
128 </rpc>
129
130 <rpc-reply message-id="102"
131 xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
132 <data
133 xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
134 module voltha {
135 //default format (yang) returned
136 //voltha version 0.1 yang module
137 //contents here ...
138 }
139 </data>
140 </rpc-reply>
141
142
143 GETTING DATA
144
145 Use filter:
146 1) namespace filter
147 <filter type="subtree">
148 <top xmlns="http://example.com/schema/1.2/config"/>
149 </filter>
150
151 2) <filter type="subtree">
152 <adapters xmlns="urn:cord:voltha:adapter_x">
153 <adapter>
154 <id>uuid</id>
155 <config/>
156 </adapter>
157 </adapters>
158 </filter>
159
160 /voltha/adapters/<adapter>/[<id>, <vendor>, <version>, <config>, <additonal_desc>]
161
162 """