Rename ofport in switch_port to port_num

As we changed the port from ovs port to a generic port, the ofport
notation is not relevant any more.
We should use the port_num notation that is more generic.

Change-Id: I64574b47719aff8666341fa1cbd7a8fb3e390fc3
Partial-Bug: #1781376
This commit is contained in:
Shachar Snapiri 2018-07-25 17:50:48 +03:00
parent e52ba1ee31
commit ad9add8d6f
18 changed files with 82 additions and 82 deletions

View File

@ -43,29 +43,29 @@ class ClassifierApp(df_base_app.DFlowApp):
@df_base_app.register_event(
switch.SwitchPort, model_constants.EVENT_UPDATED)
def _ovs_port_created(self, ovs_port, orig_ovs_port=None):
ofport = ovs_port.ofport
port_num = ovs_port.port_num
lport_ref = ovs_port.lport
if not lport_ref:
return # Not relevant
if orig_ovs_port and orig_ovs_port.ofport != ofport:
if orig_ovs_port and orig_ovs_port.port_num != port_num:
self._ovs_port_deleted(ovs_port)
if not ofport or ofport == -1:
if not port_num or port_num == -1:
return # Not ready yet, or error
lport = self.nb_api.get(lport_ref)
self._ofport_unique_key_map[ovs_port.id] = (ofport, lport.unique_key)
self._ofport_unique_key_map[ovs_port.id] = (port_num, lport.unique_key)
LOG.info("Add local ovs port %(ovs_port)s, logical port "
"%(lport)s for classification",
{'ovs_port': ofport, 'lport': lport})
self._make_ingress_classification_flow(lport, ofport)
self._make_ingress_dispatch_flow(lport, ofport)
{'switch_port': port_num, 'lport': lport})
self._make_ingress_classification_flow(lport, port_num)
self._make_ingress_dispatch_flow(lport, port_num)
def _make_ingress_dispatch_flow(self, lport,
ofport):
port_num):
port_key = lport.unique_key
match = self.parser.OFPMatch(reg7=port_key)
LOG.debug("match reg7=%(reg7)s for ingress dispatch of %(lport)s",
{'reg7': port_key, 'lport': lport})
actions = [self.parser.OFPActionOutput(ofport,
actions = [self.parser.OFPActionOutput(port_num,
self.ofproto.OFPCML_NO_BUFFER)]
action_inst = self.parser.OFPInstructionActions(
self.ofproto.OFPIT_APPLY_ACTIONS, actions)
@ -76,12 +76,12 @@ class ClassifierApp(df_base_app.DFlowApp):
priority=const.PRIORITY_MEDIUM,
match=match)
def _make_ingress_classification_flow(self, lport, ofport):
match = self.parser.OFPMatch(in_port=ofport)
def _make_ingress_classification_flow(self, lport, port_num):
match = self.parser.OFPMatch(in_port=port_num)
network_id = lport.lswitch.unique_key
LOG.debug("match in_port=%(in_port)s for ingress classification "
"of %(lport)s in network %(network)s",
{'in_port': ofport, 'lport': lport, 'network': network_id})
{'in_port': port_num, 'lport': lport, 'network': network_id})
# Reset in_port to 0 to avoid drop by output command.
actions = [
self.parser.OFPActionSetField(reg6=lport.unique_key),
@ -104,13 +104,13 @@ class ClassifierApp(df_base_app.DFlowApp):
switch.SwitchPort, model_constants.EVENT_DELETED)
def _ovs_port_deleted(self, ovs_port):
try:
ofport, port_key = self._ofport_unique_key_map.pop(ovs_port.id)
port_num, port_key = self._ofport_unique_key_map.pop(ovs_port.id)
except KeyError:
# OvsPort not present in lookup, was either not added, or removed
# by a previous update. In both cases irrelevant.
return
self._del_ingress_dispatch_flow(port_key)
self._del_ingress_classification_flow(ofport)
self._del_ingress_classification_flow(port_num)
def _del_ingress_dispatch_flow(self, port_key):
LOG.debug("delete ingress dispatch flow for port_key=%(port_key)s",
@ -122,10 +122,10 @@ class ClassifierApp(df_base_app.DFlowApp):
priority=const.PRIORITY_MEDIUM,
match=match)
def _del_ingress_classification_flow(self, ofport):
def _del_ingress_classification_flow(self, port_num):
LOG.debug("delete in_port=%(in_port)s ingress classification",
{'in_port': ofport})
match = self.parser.OFPMatch(in_port=ofport)
{'in_port': port_num})
match = self.parser.OFPMatch(in_port=port_num)
self.mod_flow(
table_id=const.INGRESS_CLASSIFICATION_DISPATCH_TABLE,
command=self.ofproto.OFPFC_DELETE,

View File

@ -54,17 +54,17 @@ class MetadataServiceApp(df_base_app.DFlowApp):
def __init__(self, *args, **kwargs):
super(MetadataServiceApp, self).__init__(*args, **kwargs)
self._arp_responder = None
self._ofport = None
self._port_num = None
self._interface_mac = ""
self._ip = cfg.CONF.df_metadata.ip
self._port = cfg.CONF.df_metadata.port
self._interface = cfg.CONF.df_metadata.metadata_interface
def switch_features_handler(self, ev):
if self._interface_mac and self._ofport and self._ofport > 0:
# For reconnection, if the mac and ofport is set, re-download
if self._interface_mac and self._port_num and self._port_num > 0:
# For reconnection, if the mac and port_num is set, re-download
# the flows.
self._add_tap_metadata_port(self._ofport, self._interface_mac)
self._add_tap_metadata_port(self._port_num, self._interface_mac)
@df_base_app.register_event(switch.SwitchPort, model_const.EVENT_CREATED)
@df_base_app.register_event(switch.SwitchPort, model_const.EVENT_UPDATED)
@ -72,19 +72,19 @@ class MetadataServiceApp(df_base_app.DFlowApp):
if ovs_port.name != cfg.CONF.df_metadata.metadata_interface:
return
ofport = ovs_port.ofport
port_num = ovs_port.port_num
mac = ovs_port.mac_in_use
if not ofport or not mac:
if not port_num or not mac:
return
if ofport <= 0:
if port_num <= 0:
return
if ofport == self._ofport and mac == self._interface_mac:
if port_num == self._port_num and mac == self._interface_mac:
return
self._add_tap_metadata_port(ofport, mac)
self._ofport = ofport
self._add_tap_metadata_port(port_num, mac)
self._port_num = port_num
self._interface_mac = mac
@df_base_app.register_event(switch.SwitchPort, model_const.EVENT_DELETED)
@ -95,7 +95,7 @@ class MetadataServiceApp(df_base_app.DFlowApp):
self._remove_metadata_interface_flows()
def _remove_metadata_interface_flows(self):
if not self._ofport:
if not self._port_num:
return
parser = self.parser
@ -105,12 +105,12 @@ class MetadataServiceApp(df_base_app.DFlowApp):
table_id=const.INGRESS_CLASSIFICATION_DISPATCH_TABLE,
command=ofproto.OFPFC_DELETE,
priority=const.PRIORITY_MEDIUM,
match=parser.OFPMatch(in_port=self._ofport))
match=parser.OFPMatch(in_port=self._port_num))
self._ofport = None
self._port_num = None
self._interface_mac = ""
def _add_tap_metadata_port(self, ofport, mac):
def _add_tap_metadata_port(self, port_num, mac):
"""
Add the flows that can be added with the current available information:
Regular Client->Server packets have IP rewritten, and sent to OVS port
@ -118,7 +118,7 @@ class MetadataServiceApp(df_base_app.DFlowApp):
added.
Packets from the OVS port are detected and sent for classification.
"""
self._ofport = ofport
self._port_num = port_num
ofproto = self.ofproto
parser = self.parser
self._add_incoming_flows()
@ -157,7 +157,7 @@ class MetadataServiceApp(df_base_app.DFlowApp):
)
# ARP responder
match = parser.OFPMatch(in_port=ofport,
match = parser.OFPMatch(in_port=port_num,
eth_type=ethernet.ether.ETH_TYPE_ARP)
actions = [
parser.NXActionResubmitTable(
@ -175,7 +175,7 @@ class MetadataServiceApp(df_base_app.DFlowApp):
self._create_arp_responder(mac)
# Response packet
match = parser.OFPMatch(in_port=ofport,
match = parser.OFPMatch(in_port=port_num,
eth_type=ethernet.ether.ETH_TYPE_IP)
actions = [
parser.NXActionResubmitTable(
@ -266,7 +266,7 @@ class MetadataServiceApp(df_base_app.DFlowApp):
dst="ipv4_src",
value=1,),
parser.OFPActionOutput(
self._ofport,
self._port_num,
ofproto.OFPCML_NO_BUFFER,
)
]

View File

@ -66,7 +66,7 @@ class MigrationApp(df_base_app.DFlowApp):
return
# Here It could be either source node or other nodes, so
# get ofport from chassis.
# get port_num from chassis.
remote_chassis = dest_chassis.get_object()
if not remote_chassis:
# chassis has not been online yet.

View File

@ -230,7 +230,7 @@ class ProviderApp(df_base_app.DFlowApp):
{'net_id': network_id})
physical_network = lport.lswitch.physical_network
ofport = self.int_ofports[physical_network]
port_num = self.int_ofports[physical_network]
# Output without updating MAC:
self.mod_flow(
@ -242,7 +242,7 @@ class ProviderApp(df_base_app.DFlowApp):
self.ofproto.OFPIT_APPLY_ACTIONS,
[
self.parser.OFPActionOutput(
ofport,
port_num,
self.ofproto.OFPCML_NO_BUFFER,
),
]
@ -257,7 +257,7 @@ class ProviderApp(df_base_app.DFlowApp):
# If dest MAC is the placeholder, update it to bridge MAC
network_id = lport.lswitch.unique_key
physical_network = lport.lswitch.physical_network
ofport = self.int_ofports[physical_network]
port_num = self.int_ofports[physical_network]
self.mod_flow(
table_id=const.EGRESS_EXTERNAL_TABLE,
@ -274,7 +274,7 @@ class ProviderApp(df_base_app.DFlowApp):
eth_dst=self.bridge_macs[physical_network],
),
self.parser.OFPActionOutput(
ofport,
port_num,
self.ofproto.OFPCML_NO_BUFFER,
),
]

View File

@ -117,9 +117,9 @@ class TunnelingApp(df_base_app.DFlowApp):
def _make_network_match(self, lport):
segmentation_id = lport.lswitch.segmentation_id
ofport = self._get_lport_tunnel_ofport(lport)
port_num = self._get_lport_tunnel_ofport(lport)
return self.parser.OFPMatch(tunnel_id_nxm=segmentation_id,
in_port=ofport)
in_port=port_num)
def _get_lport_tunnel_ofport(self, lport):
network_type = lport.lswitch.network_type
@ -165,7 +165,7 @@ class TunnelingApp(df_base_app.DFlowApp):
def _add_egress_dispatch_flow(self, lport, segmentation_id):
binding = port_locator.get_port_binding(lport)
remote_ip = binding.ip
ofport = self._get_lport_tunnel_ofport(lport)
port_num = self._get_lport_tunnel_ofport(lport)
LOG.debug("set egress dispatch flow %(seg)s peer %(remote_ip)s",
{'seg': segmentation_id,
'remote_ip': remote_ip})
@ -174,7 +174,7 @@ class TunnelingApp(df_base_app.DFlowApp):
actions = [
self.parser.OFPActionSetField(tun_ipv4_dst=remote_ip),
self.parser.OFPActionSetField(tunnel_id_nxm=segmentation_id),
self.parser.OFPActionOutput(port=ofport)]
self.parser.OFPActionOutput(port=port_num)]
ofproto = self.ofproto
action_inst = self.parser.OFPInstructionActions(
ofproto.OFPIT_APPLY_ACTIONS, actions)
@ -248,10 +248,10 @@ class TunnelingApp(df_base_app.DFlowApp):
if peer_ip in peer_ip_list:
continue
peer_ip_list.add(peer_ip)
ofport = self._get_lport_tunnel_ofport(lport)
port_num = self._get_lport_tunnel_ofport(lport)
ofpact_set_field = self.parser.OFPActionSetField
actions += [
ofpact_set_field(tun_ipv4_dst=peer_ip),
ofpact_set_field(tunnel_id_nxm=segmentation_id),
self.parser.OFPActionOutput(port=ofport)]
self.parser.OFPActionOutput(port=port_num)]
return actions

View File

@ -286,7 +286,7 @@ class DfLocalController(object):
try:
self._handle_db_change(update)
except Exception as e:
if "ofport is 0" not in str(e):
if "port_num is 0" not in str(e):
LOG.exception(e)
if not self.sync_rate_limiter():
self.sync()

View File

@ -23,7 +23,7 @@ from dragonflow.db.models import mixins
class SwitchPort(mf.ModelBase, mixins.BasicEvents, mixins.Name):
table_name = 'switch_port'
ofport = fields.IntField()
port_num = fields.IntField()
admin_state = df_fields.EnumField(('up', 'down'))
lport = df_fields.ReferenceField(l2.LogicalPort)
type = df_fields.EnumField(

View File

@ -87,9 +87,9 @@ def _is_ovsport_update_valid(action, switch_port):
return False
if action == 'set':
# No need for 'updated' event if the ofport is being deleted
ofport = switch_port.ofport
if (ofport is None) or (ofport < 0):
# No need for 'updated' event if the port_num is being deleted
port_num = switch_port.port_num
if (port_num is None) or (port_num < 0):
return False
return True
@ -122,7 +122,7 @@ def _port_from_idl_row(row):
type=_get_interface_type(row),
)
if row.ofport:
res.ofport = int(row.ofport[0])
res.port_num = int(row.ofport[0])
if row.mac_in_use:
res.mac_in_use = row.mac_in_use[0]

View File

@ -119,13 +119,13 @@ class OvsApi(object):
self.integration_bridge).execute()
@staticmethod
def _check_ofport(port_name, ofport):
if ofport is None:
LOG.warning("Can't find ofport for port %s.", port_name)
def _check_ofport(port_name, port_num):
if port_num is None:
LOG.warning("Can't find port_num for port %s.", port_name)
return False
if ofport < OFPORT_RANGE_MIN or ofport > OFPORT_RANGE_MAX:
LOG.warning("ofport %(ofport)s for port %(port)s is invalid.",
{'ofport': ofport, 'port': port_name})
if port_num < OFPORT_RANGE_MIN or port_num > OFPORT_RANGE_MAX:
LOG.warning("port_num %(port_num)s for port %(port)s is invalid.",
{'port_num': port_num, 'port': port_name})
return False
return True

View File

@ -243,11 +243,11 @@ class TestDHCPApp(test_base.DFTestBase):
self._create_topology()
self._test_enable_dhcp()
def _check_dhcp_block_rule(self, flows, ofport=None):
def _check_dhcp_block_rule(self, flows, port_num=None):
for flow in flows:
if (int(flow['table']) == constants.DHCP_TABLE and
'drop' in flow['actions']):
if ofport is None or 'inport=' + ofport in flow['match']:
if port_num is None or 'inport=' + port_num in flow['match']:
return True
return False

View File

@ -105,8 +105,8 @@ class TestOVSFlowsForActivePortDectionApp(test_base.DFTestBase):
vm_port = objects.PortTestObj(self.neutron, self.nb_api, network_id,
vm_port_id)
of_port = self.vswitch_api.get_port_ofport_by_id(vm_port_id)
self.assertIsNotNone(of_port)
port_num = self.vswitch_api.get_port_ofport_by_id(vm_port_id)
self.assertIsNotNone(port_num)
vm_lport = vm_port.get_logical_port()
self.assertIsNotNone(vm_lport)
result = self._check_sending_arp_reply_to_controller_flows(

View File

@ -79,12 +79,12 @@ class TestL2FLows(test_base.DFTestBase):
tunnel_key = port.unique_key
tunnel_key_hex = hex(tunnel_key)
n_type = network.get_network()['network']['provider:network_type']
ofport = self.vswitch_api.get_vtp_ofport(n_type)
port_num = self.vswitch_api.get_vtp_ofport(n_type)
r = self._check_tunnel_flows(ovs.dump(self.integration_bridge),
metadataid,
hex(segmentation_id),
tunnel_key_hex,
mac, ofport)
mac, port_num)
for key, value in r.items():
self.assertIsNotNone(value, key)
vm.close()
@ -152,7 +152,7 @@ class TestL2FLows(test_base.DFTestBase):
network.close()
def _check_tunnel_flows(self, flows, metadtata, segmentation_id,
port_key_hex, mac, tunnel_ofport):
port_key_hex, mac, tunnel_port_num):
l2_lookup_unicast_match = 'metadata=0x' + metadtata + \
',dl_dst=' + mac
l2_lookup_unicast_action = 'goto_table:' + \
@ -167,7 +167,7 @@ class TestL2FLows(test_base.DFTestBase):
str(const.EGRESS_TABLE) + ')'
ingress_match = ('tun_id=' + str(segmentation_id)
+ ",in_port=" + str(tunnel_ofport))
+ ",in_port=" + str(tunnel_port_num))
ingress_action = 'set_field:0x' + metadtata + '->metadata,' + \
'goto_table:' + \
str(const.INGRESS_DESTINATION_PORT_LOOKUP_TABLE)

View File

@ -39,7 +39,7 @@ class TestOvsdbMonitor(test_base.DFTestBase):
return False
elif _interface.lport is None:
return False
elif _interface.ofport <= 0:
elif _interface.port_num <= 0:
return False
elif _interface.admin_state != "up":
return False

View File

@ -57,13 +57,13 @@ class TestRemotePort(test_base.DFTestBase):
network_obj = network.get_network()['network']
network_type = network_obj['provider:network_type']
segmentation_id = network_obj['provider:segmentation_id']
ofport = self.vswitch_api.get_vtp_ofport(network_type)
port_num = self.vswitch_api.get_vtp_ofport(network_type)
port_unique_key = port.get_logical_port().unique_key
match = "reg7=" + str(hex(port_unique_key))
action = ("set_field:10.10.10.10" +
"->tun_dst,set_field:" + str(hex(segmentation_id)) +
"->tun_id,output:" + str(ofport))
"->tun_id,output:" + str(port_num))
ovs = utils.OvsFlowsParser()
matched = False
for flow in ovs.dump(self.integration_bridge):

View File

@ -292,7 +292,7 @@ fake_local_port1 = make_fake_local_port(
fake_ovs_port1 = switch.SwitchPort(
id='fake_ovs_port1',
ofport=2,
port_num=2,
name='tap-fake_port1',
admin_state='up',
type=constants.SWITCH_COMPUTE_INTERFACE,
@ -310,7 +310,7 @@ fake_local_port2 = make_fake_local_port(
fake_ovs_port2 = switch.SwitchPort(
id='fake_ovs_port2',
ofport=3,
port_num=3,
name='tap-fake_port2',
admin_state='up',
type=constants.SWITCH_COMPUTE_INTERFACE,

View File

@ -60,7 +60,7 @@ class TestClassifierAppForVlan(testscenarios.WithScenarios,
self.app.mod_flow.assert_not_called()
ovs_port = switch.SwitchPort(id='fake_ovs_port',
lport=fake_local_vlan_port.id,
ofport=1, admin_state='up',
port_num=1, admin_state='up',
type=constants.SWITCH_COMPUTE_INTERFACE)
self.controller.update(ovs_port)
port_key = fake_local_vlan_port.unique_key
@ -71,8 +71,8 @@ class TestClassifierAppForVlan(testscenarios.WithScenarios,
priority=const.PRIORITY_MEDIUM,
match=match)
self.app.mod_flow.reset_mock()
ofport = ovs_port.ofport
match = self.app.parser.OFPMatch(in_port=ofport)
port_num = ovs_port.port_num
match = self.app.parser.OFPMatch(in_port=port_num)
if self.order == SCENARIO_ORDER_DELETE_LPORT_FIRST:
self.controller.delete(fake_local_vlan_port)
self.controller.delete(ovs_port)

View File

@ -38,7 +38,7 @@ class TestMetadataServiceApp(test_app_base.DFAppTestBase):
self.controller.update(
switch.SwitchPort(
id='fake_ovs_port',
ofport=1,
port_num=1,
name=self.meta_app._interface,
)
)
@ -49,7 +49,7 @@ class TestMetadataServiceApp(test_app_base.DFAppTestBase):
self.controller.update(
switch.SwitchPort(
id='fake_ovs_port',
ofport=1,
port_num=1,
name='no-interface',
mac_in_use='aa:bb:cc:dd:ee:ff',
)
@ -61,7 +61,7 @@ class TestMetadataServiceApp(test_app_base.DFAppTestBase):
self.controller.update(
switch.SwitchPort(
id='fake_ovs_port',
ofport=1,
port_num=1,
name=self.meta_app._interface,
mac_in_use='aa:bb:cc:dd:ee:ff',
)
@ -73,7 +73,7 @@ class TestMetadataServiceApp(test_app_base.DFAppTestBase):
self.controller.update(
switch.SwitchPort(
id='fake_ovs_port1',
ofport=1,
port_num=1,
name=self.meta_app._interface,
mac_in_use='aa:bb:cc:dd:ee:ff',
)

View File

@ -24,7 +24,7 @@ class TestDFIdl(tests_base.BaseTestCase):
impl_idl._is_ovsport_update_valid(
'set',
switch.SwitchPort(
ofport=1,
port_num=1,
name='qg-some-uuid',
),
),
@ -45,7 +45,7 @@ class TestDFIdl(tests_base.BaseTestCase):
impl_idl._is_ovsport_update_valid(
'set',
switch.SwitchPort(
ofport=-1,
port_num=-1,
name='tap-uuid',
),
),
@ -56,7 +56,7 @@ class TestDFIdl(tests_base.BaseTestCase):
impl_idl._is_ovsport_update_valid(
'set',
switch.SwitchPort(
ofport=1,
port_num=1,
type=constants.SWITCH_PATCH_INTERFACE,
name='tap-uuid',
),
@ -68,7 +68,7 @@ class TestDFIdl(tests_base.BaseTestCase):
impl_idl._is_ovsport_update_valid(
'set',
switch.SwitchPort(
ofport=1,
port_num=1,
type=constants.SWITCH_COMPUTE_INTERFACE,
name='tap-uuid',
),