Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "previous" User PD function #40

Open
sfreemire opened this issue Jun 13, 2024 · 0 comments
Open

Add "previous" User PD function #40

sfreemire opened this issue Jun 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@sfreemire
Copy link
Owner

For IPv6 User PD:
- Increment with "next" as usual.
-Decrement by recreating iterator object and calling it (current count -1) times.

 ```
  # ...
  v6upd_obj = next(self.v6upd_gen)  # Initial User PD creation
  self.updcount = 0
  # ...

  # Increment / decrement User PD 
  match pdchg:
     case 'next':   # <-- for incrementing
        if self.psidstr == self.pslen * '1':   # if all ones:
           self.psdistr = self.pslen * '0'.    # roll over to all zeroes
        else:
           self.psidstr = bin(int(self.psidstr, 2) + 1)[2:].zfill(self.pslen)

        v6upd_obj = next(self.v6upd_gen)       # get "next" from upd generator object
        v6upd_netadr = v6upd_obj.network_address
        v6updbin = f'{v6upd_netadr:b}'
        v6upd_adr = v6upd_obj.with_prefixlen
        self.updcount += 1
           # print(f'Maximum reached, PSID starts over: {self.psidstr}')  # test message

     case 'previous':   # for decrementing
        if self.updcount > 0:  # <-- if '1' in self.psidstr (but not all '1's):
           self.psidstr = bin(int(self.psidstr, 2) -1)[2:].zfill(self.pslen)
           self.v6upd_gen = self.bmrv6p_obj.subnets(new_prefix = self.v6updlen) # <-- re-create upd generator

           for _ in range(self.updcount):  # <-- range should be 1 less than current count (range starts at 0)
              v6upd_obj = next(self.v6upd_gen)  # <-- call "next" upd (updcount - 1) times
           self.updcount -= 1

           v6upd_netadr = v6upd_obj.network_address
           v6updbin = f'{v6upd_netadr:b}'
           v6upd_adr = v6upd_obj.with_prefixlen
        else:
           # print(f'Minimum reached, no change, self.psidstr is: {self.psidstr}')  # test message

     case _:
        pass    # Not needed? Consider error message
@sfreemire sfreemire added the enhancement New feature or request label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant