Skip to content

Commit

Permalink
Use the scheme of ordered interfaces for service instance
Browse files Browse the repository at this point in the history
Change-Id: I144d6912d41736f60ec8f77697fd35f45d0c63c5
  • Loading branch information
rrugge committed Aug 26, 2014
1 parent 401a72c commit cfe7291
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
27 changes: 0 additions & 27 deletions src/config/common/svc_info.py
Expand Up @@ -24,33 +24,6 @@
_SNAT_SVC_TYPE = 'source-nat'
_LB_SVC_TYPE = 'loadbalancer'

def get_left_vn(parent_str, vn):
if vn is None:
return None
if vn == "":
return(parent_str + ':' + _SVC_VN_LEFT)
else:
return vn
# end get_left_vn

def get_right_vn(parent_str, vn):
if vn is None:
return None
if vn == "":
return(parent_str + ':' + _SVC_VN_RIGHT)
else:
return vn
# end get_right_vn

def get_management_vn(parent_str, vn):
if vn is None:
return None
if vn == "":
return(parent_str + ':' + _SVC_VN_MGMT)
else:
return vn
# end get_management_vn

def get_management_if_str():
return _MGMT_STR

Expand Down
39 changes: 31 additions & 8 deletions src/config/schema-transformer/to_bgp.py
Expand Up @@ -131,6 +131,35 @@ def locate(cls, name, *args):

# end DictST

def get_si_vns(si_obj, si_props):
left_vn = None
right_vn = None

st_refs = si_obj.get_service_template_refs()
uuid = st_refs[0]['uuid']
st_obj = _vnc_lib.service_template_read(id=uuid)
st_props = st_obj.get_service_template_properties()
if st_props.get_ordered_interfaces():
st_if_list = st_props.get_interface_type()
si_if_list = si_props.get_interface_list()
for idx in range(0, len(st_if_list)):
st_if = st_if_list[idx]
si_if = si_if_list[idx]
if st_if.get_service_interface_type() == 'left':
left_vn = si_if.get_virtual_network()
elif st_if.get_service_interface_type() == 'right':
right_vn = si_if.get_virtual_network()
else:
left_vn = si_props.get_left_virtual_network()
right_vn = si_props.get_right_virtual_network()

if left_vn == "":
left_vn = parent_str + ':' + svc_info.get_left_vn_name()
if right_vn == "":
right_vn = parent_str + ':' + svc_info.get_right_vn_name()

return left_vn, right_vn
# end get_si_vns

def _access_control_list_update(acl_obj, name, obj, entries):
if acl_obj is None:
Expand Down Expand Up @@ -685,10 +714,7 @@ def _get_routing_instance_from_route(self, next_hop):
_sandesh._logger.debug("%s: route table next hop must be service "
"instance with auto policy", self.name)
return None
left_vn_str = svc_info.get_left_vn(si.get_parent_fq_name_str(),
si_props.left_virtual_network)
right_vn_str = svc_info.get_right_vn(si.get_parent_fq_name_str(),
si_props.right_virtual_network)
left_vn_str, right_vn_str = get_si_vns(si, si_props)
if (not left_vn_str or not right_vn_str):
_sandesh._logger.debug("%s: route table next hop service instance "
"must have left and right virtual networks",
Expand Down Expand Up @@ -2914,10 +2940,7 @@ def add_service_instance_properties(self, idents, meta):
return
si = _vnc_lib.service_instance_read(fq_name_str=si_name)
si_props = si.get_service_instance_properties()
left_vn_str = svc_info.get_left_vn(si.get_parent_fq_name_str(),
si_props.left_virtual_network)
right_vn_str = svc_info.get_right_vn(si.get_parent_fq_name_str(),
si_props.right_virtual_network)
left_vn_str, right_vn_str = get_si_vns(si, si_props)
if (not left_vn_str or not right_vn_str):
_sandesh._logger.debug(
"%s: route table next hop service instance must "
Expand Down
4 changes: 3 additions & 1 deletion src/config/svc-monitor/svc_monitor/instance_manager.py
Expand Up @@ -527,7 +527,9 @@ def _create_snat_vn(self, proj_obj, si_obj, si_props, vn_fq_name_str):
vn_id = self._create_svc_vn(vn_name, snat_cidr, proj_obj)

if vn_fq_name_str != ':'.join(vn_fq_name):
si_props.set_left_virtual_network(':'.join(vn_fq_name))
left_if = ServiceInstanceInterfaceType(
virtual_network=':'.join(vn_fq_name))
si_props.insert_interface_list(0, left_if)
si_obj.set_service_instance_properties(si_props)
self._vnc_lib.service_instance_update(si_obj)
self.logger.log("Info: SI %s updated with left vn %s" %
Expand Down
8 changes: 7 additions & 1 deletion src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Expand Up @@ -2906,10 +2906,16 @@ def _router_set_external_gateway(self, router_obj, ext_net_obj):
si_created = True
#TODO(ethuleau): For the fail-over SNAT set scale out to 2
si_prop_obj = ServiceInstanceType(
right_virtual_network=ext_net_obj.get_fq_name_str(),
scale_out=ServiceScaleOutType(max_instances=1,
auto_scale=True),
auto_policy=True)

# set right interface in order of [left, right] to match template
left_if = ServiceInstanceInterfaceType()
right_if = ServiceInstanceInterfaceType(
virtual_network=ext_net_obj.get_fq_name_str())
si_prop_obj.set_interface_list([left_if, right_if])

si_obj.set_service_instance_properties(si_prop_obj)
si_obj.set_service_template(st_obj)
if si_created:
Expand Down
20 changes: 7 additions & 13 deletions src/vnsw/agent/oper/service_instance.cc
Expand Up @@ -177,20 +177,14 @@ static void FindAndSetInterfaces(
const autogen::ServiceInstanceType &si_properties =
svc_instance->properties();

properties->interface_count = 0;
/*
* The outside virtual-network is always specified (by the
* process that creates the service-instance).
*/
if (si_properties.right_virtual_network.length()) {
properties->interface_count += 1;
}
/*
* The inside virtual-network is optional for loadbalancer.
*/
if (si_properties.left_virtual_network.length()) {
properties->interface_count += 1;
}
properties->interface_count = si_properties.interface_list.size();
std::string left_netname = si_properties.interface_list[0].virtual_network;
std::string right_netname = si_properties.interface_list[1].virtual_network;

/*
* Lookup for VMI nodes
Expand All @@ -211,11 +205,11 @@ static void FindAndSetInterfaces(
}

std::string netname = vn_node->name();
if (netname == si_properties.left_virtual_network) {
if (netname == left_netname) {
properties->vmi_inside = IdPermsGetUuid(vmi->id_perms());
properties->mac_addr_inside = vmi->mac_addresses().at(0);
properties->ip_addr_inside = FindInterfaceIp(graph, adj);
} else if (netname == si_properties.right_virtual_network) {
} else if (netname == right_netname) {
properties->vmi_outside = IdPermsGetUuid(vmi->id_perms());
properties->mac_addr_outside = vmi->mac_addresses().at(0);
properties->ip_addr_outside = FindInterfaceIp(graph, adj);
Expand All @@ -231,11 +225,11 @@ static void FindAndSetInterfaces(
const autogen::VnSubnetsType &subnets = ipam->data();
for (unsigned int i = 0; i < subnets.ipam_subnets.size(); ++i) {
int prefix_len = subnets.ipam_subnets[i].subnet.ip_prefix_len;
if (netname == si_properties.left_virtual_network &&
if (netname == left_netname &&
SubNetContainsIpv4(subnets.ipam_subnets[i],
properties->ip_addr_inside)) {
properties->ip_prefix_len_inside = prefix_len;
} else if (netname == si_properties.right_virtual_network &&
} else if (netname == right_netname &&
SubNetContainsIpv4(subnets.ipam_subnets[i],
properties->ip_addr_outside)) {
properties->ip_prefix_len_outside = prefix_len;
Expand Down

0 comments on commit cfe7291

Please sign in to comment.