This repository was archived by the owner on Apr 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
pyof/v0x01/controller2switch
tests/v0x01/test_controller2switch Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,13 +112,20 @@ def _update_actions_len(self):
112112 self .actions_len = ListOfActions (self .actions ).get_size ()
113113
114114 def _validate_in_port (self ):
115- port = self .in_port
116- valid = True
117- if isinstance (port , Port ):
118- if port not in _VIRT_IN_PORTS :
119- valid = False
120- elif isinstance (port , int ) and (port < 1 or port >=
121- Port .OFPP_MAX .value ):
122- valid = False
123- if not valid :
124- raise ValidationError ('{} is not a valid input port.' .format (port ))
115+ """Validate in_port attribute.
116+
117+ A valid port is either:
118+
119+ * Greater than 0 and less than or equals to Port.OFPP_MAX
120+ * One of the valid virtual ports: Port.OFPP_LOCAL,
121+ Port.OFPP_CONTROLLER or Port.OFPP_NONE
122+
123+ Raises:
124+ ValidationError: If in_port is an invalid port.
125+
126+ """
127+ is_valid_range = self .in_port > 0 and self .in_port <= Port .OFPP_MAX
128+ is_valid_virtual_in_ports = self .in_port in _VIRT_IN_PORTS
129+
130+ if (is_valid_range or is_valid_virtual_in_ports ) is False :
131+ raise ValidationError (f'{ self .in_port } is not a valid input port.' )
Original file line number Diff line number Diff line change @@ -45,14 +45,14 @@ def test_invalid_virtual_in_ports(self):
4545
4646 def test_valid_physical_in_ports (self ):
4747 """Physical port limits from 1.0.0 spec."""
48- max_valid = int (Port .OFPP_MAX .value ) - 1
48+ max_valid = int (Port .OFPP_MAX .value )
4949 for in_port in (1 , max_valid ):
5050 self .message .in_port = in_port
5151 self .assertTrue (self .message .is_valid ())
5252
5353 def test_invalid_physical_in_port (self ):
5454 """Physical port limits from 1.0.0 spec."""
55- max_valid = int (Port .OFPP_MAX .value ) - 1
55+ max_valid = int (Port .OFPP_MAX .value )
5656 for in_port in (- 1 , 0 , max_valid + 1 , max_valid + 2 ):
5757 self .message .in_port = in_port
5858 self .assertFalse (self .message .is_valid ())
You can’t perform that action at this time.
0 commit comments