Skip to content

Commit

Permalink
Implement tagged/untagged port lists for VLANs
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhandreke committed Aug 14, 2012
1 parent 60c749b commit 16f8db7
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions hpswitch/vlan.py
Expand Up @@ -164,13 +164,6 @@ def remove_ipv6_address(self, address):
(("hpicfIpAddressRowStatus", self.ifindex, 2, 16) + ipv6_address_tuple, rfc1902.Integer(6))
)


@staticmethod
def _get_port_list_port_value(port_list, port):
byte_position = (port.base_port - 1) / 8
bit_position = 7 - ((port.base_port - 1) % 8)
return (ord(port_list[byte_position]) & (1 << bit_position)) != 0

@staticmethod
def _set_port_list_port_status(port_list, port, status):
"""
Expand All @@ -189,11 +182,27 @@ def _set_port_list_port_status(port_list, port, status):
new_port_list = port_list[:byte_position] + newbyte + port_list[(byte_position + 1):]
return new_port_list

def _get_port_list_enabled_ports(self, port_list):
"""
Return a list of Ports corresponding to the ports marked as enabled in the given `port_list`.
"""
enabled_ports = []
byte_count = 0
for byte in port_list:
for bit in range(0, 8):
# Mask the byte with a bit field with only the bit we are interested in set
if (ord(byte) & (1 << (7 - bit))) != 0:
enabled_ports.append(port.Port(self.switch, base_port=byte_count * 8 + (bit + 1)))
byte_count += 1
return enabled_ports


def _get_tagged_ports(self):
"""
Get a list of ports that have this VLAN configured as tagged.
"""
raise NotImplementedError
dot1qVlanStaticEgressPorts = self.switch.snmp_get(("dot1qVlanStaticEgressPorts", self.vid))
return self._get_port_list_enabled_ports(dot1qVlanStaticEgressPorts)

tagged_ports = property(_get_tagged_ports)

Expand All @@ -218,7 +227,8 @@ def _get_untagged_ports(self):
"""
Get a list of ports that have this VLAN configured as untagged.
"""
raise NotImplementedError
dot1qVlanStaticUntaggedPorts = self.switch.snmp_get(("dot1qVlanStaticUntaggedPorts", self.vid))
return self._get_port_list_enabled_ports(dot1qVlanStaticUntaggedPorts)

untagged_ports = property(_get_untagged_ports)

Expand Down

0 comments on commit 16f8db7

Please sign in to comment.