8000 Fix DPID hex string validation and/or allow python hex() strings · Issue #684 · mininet/mininet · GitHub
[go: up one dir, main page]

Skip to content

Fix DPID hex string validation and/or allow python hex() strings #684

Open

Description

@0xjac

I have just started using Mininet for a networking assignment and so I am not very familiar with.

However I think there is an issue in some cases with the way the default dpid is handled when a dpid is provided.

This issue comes from the mininet.net.node.Switch.defaultDpid method

If this method is called with a dpid value of hex(2) # == '0x2, then the validation (on line 883) will work because int('0x2', 16) == 2.

But in the end, the value returned will be '00000000000000x2' (assuming a dpidLen == 16) which cannot be converted to an integer. When the switch is started it will crash on line 1170 with:

ValueError: invalid literal for int() with base 16: '00000000000000x2'

This weird dpid of '00000000000000x2' comes from the mininet.net.node.Switch.defaultDpid method which insert zeroes in front of a valid hex number but fails to consider the 0x prefix.

I suggest changing the last line from:

return '0' * ( self.dpidLen - len( dpid ) ) + dpid

to:

dpid = hex(int(dpid, 16)).lstrip('-0x')
return '0' * (self.dpidLen - len(dpid)) + dpid

Activity

  1. 0xjac commented on Nov 13, 2016

    @0xjac
    Author

    I am happy to submit a PR with the fix if you agree with my suggestion.

  2. lantz commented on Nov 13, 2016

    @lantz
    Member

    You seem to be misunderstanding the API, which requires a string of hex digits, not a python integer in string form. But I agree that python isn't quite validating the argument as might be expected.

    I've changed the title to perhaps more accurately reflect what you are requesting, though I'm not 100% sure.

  3. changed the title [-]Improper handling of integer base prefix in dpid[/-] [+]Feature request: accept arbitrary-based python numeric strings (or possibly ints) as DPID argument[/+] on Nov 13, 2016
  4. changed the title [-]Feature request: accept arbitrary-based python numeric strings (or possibly ints) as DPID argument[/-] [+]Feature request: accept arbitrary-based python numeric strings (or possibly ints?) as DPID argument[/+] on Nov 13, 2016
  5. 0xjac commented on Nov 13, 2016

    @0xjac
    Author

    Ok I misunderstood the fact that only hex digits should be used. The doc says dpid: dpid hex string (or None to derive from name, e.g. s1 -> 1).

    I agree that from a semantic point of view this may break. On the other hand I would also assume that people may use the builtin hex function to get a hex string and it would be nice to handle those cases.

    Note that the solution above should not break any existing behaviour, so deadbeef would still be a valid dpid.

  6. changed the title [-]Feature request: accept arbitrary-based python numeric strings (or possibly ints?) as DPID argument[/-] [+]Fix argument DPID argument validation and/or allow arbitrary-based python numeric strings[/+] on Nov 13, 2016
  7. changed the title [-]Fix argument DPID argument validation and/or allow arbitrary-based python numeric strings[/-] [+]Fix DPID hex string validation and/or allow arbitrary-based python numeric strings[/+] on Nov 13, 2016
  8. lantz commented on Nov 13, 2016

    @lantz
    Member

    I think this is probably OK, though I'm not quite sure it's exactly the right way to do it.

  9. changed the title [-]Fix DPID hex string validation and/or allow arbitrary-based python numeric strings[/-] [+]Fix DPID hex string validation and/or allow python hex() strings[/+] on Nov 13, 2016
  10. changed the title [-]Fix DPID hex string validation and/or allow python hex() strings[/-] [+]Fix DPID hex string validation and/or allow python `hex()` strings[/+] on Nov 13, 2016
  11. changed the title [-]Fix DPID hex string validation and/or allow python `hex()` strings[/-] [+]Fix DPID hex string validation and/or allow python hex() strings[/+] on Nov 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0