Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 1 | #!/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 | # |
| 17 | from constants import Constants as C |
| 18 | |
| 19 | class Capabilities: |
| 20 | |
| 21 | def __init__(self): |
Khen Nursimulu | aaac7ee | 2016-12-11 22:03:52 -0500 | [diff] [blame] | 22 | self.server_caps = self._get_server_capabilities() |
Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 23 | self.client_caps = set() |
| 24 | |
| 25 | def add_client_capability(self, cap): |
| 26 | self.client_caps.add(cap) |
| 27 | |
Khen Nursimulu | aaac7ee | 2016-12-11 22:03:52 -0500 | [diff] [blame] | 28 | #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, |
| 33 | "urn:opencord:params:xml:ns:voltha:ietf-voltha", |
| 34 | "urn:opencord:params:xml:ns:voltha:ietf-openflow_13", |
| 35 | "urn:opencord:params:xml:ns:voltha:ietf-meta", |
| 36 | "urn:opencord:params:xml:ns:voltha:ietf-logical_device", |
| 37 | "urn:opencord:params:xml:ns:voltha:ietf-health", |
| 38 | "urn:opencord:params:xml:ns:voltha:ietf-device", |
| 39 | "urn:opencord:params:xml:ns:voltha:ietf-empty", |
| 40 | "urn:opencord:params:xml:ns:voltha:ietf-common", |
| 41 | "urn:opencord:params:xml:ns:voltha:ietf-any", |
| 42 | "urn:opencord:params:xml:ns:voltha:ietf-adapter" |
| 43 | ) |
| 44 | |
| 45 | #TODO: A schema exchange will also need to happen |
| 46 | |
| 47 | description = """ |
| 48 | |
| 49 | Option 1: Client already have the yang model for voltha and adapters: |
| 50 | <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 51 | <capabilities> |
| 52 | <capability> |
| 53 | urn:ietf:params:netconf:base:1.1 |
| 54 | </capability> |
| 55 | <capability> |
| 56 | urn:cord:voltha:1.0 |
| 57 | </capability> |
| 58 | <capability> |
| 59 | urn:cord:voltha:adpater_x:1.0 |
| 60 | </capability> |
| 61 | |
| 62 | |
| 63 | Option 2: NETCONF-MONITORING - schema exchanges |
| 64 | |
| 65 | server expose capabilities |
| 66 | |
| 67 | <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 68 | <capabilities> |
| 69 | <capability> |
| 70 | urn:ietf:params:netconf:base:1.1 |
| 71 | </capability> |
| 72 | <capability> |
| 73 | urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&revision=2010-10-04 |
| 74 | </capability> |
| 75 | |
| 76 | client request schemas |
| 77 | |
| 78 | <rpc message-id="101" |
| 79 | xmlns="urn:ietf:params:xml:ns:netconf:base:1.1"> |
| 80 | <get> |
| 81 | <filter type="subtree"> |
| 82 | <netconf-state xmlns= |
| 83 | "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"> |
| 84 | <schemas/> |
| 85 | </netconf-state> |
| 86 | </filter> |
| 87 | </get> |
| 88 | </rpc> |
| 89 | |
| 90 | server sends back schemas |
| 91 | |
| 92 | <rpc-reply message-id="101" |
| 93 | xmlns="urn:ietf:params:xml:ns:netconf:base:1.1"> |
| 94 | <data> |
| 95 | <netconf-state |
| 96 | xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"> |
| 97 | <schemas> |
| 98 | <schema> |
| 99 | <identifier>voltha</identifier> |
| 100 | <version>1.0</version> |
| 101 | <format>yang</format> |
| 102 | <namespace>urn:cord:voltha</namespace> |
| 103 | <location>NETCONF</location> |
| 104 | </schema> |
| 105 | <schema> |
| 106 | <identifier>adapter_x</identifier> |
| 107 | <version>x_release</version> |
| 108 | <format>yang</format> |
| 109 | <namespace>urn:cord:voltha:adapter_x</namespace> |
| 110 | <location>NETCONF</location> |
| 111 | </schema> |
| 112 | </schemas> |
| 113 | </netconf-state> |
| 114 | </data> |
| 115 | </rpc-reply> |
| 116 | |
| 117 | |
| 118 | client requests each schema instance |
| 119 | |
| 120 | <rpc message-id="102" |
| 121 | xmlns="urn:ietf:params:xml:ns:netconf:base:1.1"> |
| 122 | <get-schema |
| 123 | xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"> |
| 124 | <identifer>voltha</identifer> |
| 125 | <version>1.0</version> |
| 126 | </get-schema> |
| 127 | </rpc> |
| 128 | |
| 129 | <rpc-reply message-id="102" |
| 130 | xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> |
| 131 | <data |
| 132 | xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"> |
| 133 | module voltha { |
| 134 | //default format (yang) returned |
| 135 | //voltha version 0.1 yang module |
| 136 | //contents here ... |
| 137 | } |
| 138 | </data> |
| 139 | </rpc-reply> |
| 140 | |
| 141 | |
| 142 | GETTING DATA |
| 143 | |
| 144 | Use filter: |
| 145 | 1) namespace filter |
| 146 | <filter type="subtree"> |
| 147 | <top xmlns="http://example.com/schema/1.2/config"/> |
| 148 | </filter> |
| 149 | |
| 150 | 2) <filter type="subtree"> |
| 151 | <adapters xmlns="urn:cord:voltha:adapter_x"> |
| 152 | <adapter> |
| 153 | <id>uuid</id> |
| 154 | <config/> |
| 155 | </adapter> |
| 156 | </adapters> |
| 157 | </filter> |
| 158 | |
| 159 | /voltha/adapters/<adapter>/[<id>, <vendor>, <version>, <config>, <additonal_desc>] |
| 160 | |
| 161 | """ |