blob: 7508411bb204d5c6bb0b04dc4cedbb44363ff8ad [file] [log] [blame]
Shad Ansari4dade922017-12-13 19:06:49 +00001#
2# Copyright 2017 the original author or authors.
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#
16from enum import Enum
17from scapy.fields import PadField
18from scapy.packet import Raw
19
20
21class OmciUninitializedFieldError(Exception): pass
22
23
24class FixedLenField(PadField):
25 """
26 This Pad field limits parsing of its content to its size
27 """
28 def __init__(self, fld, align, padwith='\x00'):
29 super(FixedLenField, self).__init__(fld, align, padwith)
30
31 def getfield(self, pkt, s):
32 remain, val = self._fld.getfield(pkt, s[:self._align])
33 if isinstance(val.payload, Raw) and \
34 not val.payload.load.replace(self._padwith, ''):
35 # raw payload is just padding
36 val.remove_payload()
37 return remain + s[self._align:], val
38
39
40def bitpos_from_mask(mask, lsb_pos=0, increment=1):
41 """
42 Turn a decimal value (bitmask) into a list of indices where each
43 index value corresponds to the bit position of a bit that was set (1)
44 in the mask. What numbers are assigned to the bit positions is controlled
45 by lsb_pos and increment, as explained below.
46 :param mask: a decimal value used as a bit mask
47 :param lsb_pos: The decimal value associated with the LSB bit
48 :param increment: If this is +i, then the bit next to LSB will take
49 the decimal value of lsb_pos + i.
50 :return: List of bit positions where the bit was set in mask
51 """
52 out = []
53 while mask:
54 if mask & 0x01:
55 out.append(lsb_pos)
56 lsb_pos += increment
57 mask >>= 1
58 return sorted(out)
59
60
61class AttributeAccess(Enum):
62 Readable = 1
63 R = 1
64 Writable = 2
65 W = 2
66 SetByCreate = 3
67 SBC = 3
68
69
70OmciNullPointer = 0xffff
71
72
73class EntityOperations(Enum):
74 # keep these numbers match msg_type field per OMCI spec
75 Create = 4
76 CreateComplete = 5
77 Delete = 6
78 Set = 8
79 Get = 9
80 GetComplete = 10
81 GetAllAlarms = 11
82 GetAllAlarmsNext = 12
83 MibUpload = 13
84 MibUploadNext = 14
85 MibReset = 15
86 AlarmNotification = 16
87 AttributeValueChange = 17
88 Test = 18
89 StartSoftwareDownload = 19
90 DownlaodSection = 20
91 EndSoftwareDownload = 21
92 ActivateSoftware = 22
93 CommitSoftware = 23
94 SynchronizeTime = 24
95 Reboot = 25
96 GetNext = 26
97 TestResult = 27
98 GetCurrentData = 28
99
100