Coverage for d7a/d7anp/control.py: 70%
20 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19from d7a.d7anp.addressee import IdType, NlsMethod
20from d7a.support.schema import Validatable, Types
22class Control(Validatable):
24 SCHEMA = [{
25 "has_no_origin_access_id": Types.BOOLEAN(),
26 "has_hopping": Types.BOOLEAN(),
27 "origin_id_type": Types.ENUM(IdType, allowedvalues=[IdType.UID, IdType.VID, IdType.NOID, IdType.NBID]),
28 "nls_method": Types.ENUM(NlsMethod),
29 }]
31 def __init__(self, has_no_origin_access_id, has_hopping, nls_method, origin_id_type):
32 self.has_no_origin_access_id = has_no_origin_access_id
33 self.nls_method = nls_method
34 self.has_hopping = has_hopping
35 self.origin_id_type = origin_id_type
36 super(Control, self).__init__()
38 @staticmethod
39 def parse(bitstream):
40 return Control(
41 has_no_origin_access_id=bitstream.read("bool"),
42 has_hopping=bitstream.read("bool"),
43 origin_id_type=IdType(bitstream.read("uint:2")),
44 nls_method=NlsMethod(bitstream.read("uint:4")),
45 )
47 def __iter__(self):
48 byte = 0
49 if self.has_no_origin_access_id: byte |= 1 << 7
50 if self.has_multi_hop: byte |= 1 << 6
51 if self.origin_id_type: byte |= 1 << 4
52 byte += self.nls_method
53 yield byte