Skip to content
Snippets Groups Projects
Commit f19ad697 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Renamed Link attribute current_capacity_gbps to used_capacity_gbps
parent f14940f3
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!160Resolve "(CTTC) Forecaster component"
...@@ -99,23 +99,23 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) ...@@ -99,23 +99,23 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link)
}) })
topology_uuids.add(endpoint_topology_uuid) topology_uuids.add(endpoint_topology_uuid)
total_capacity_gbps, current_capacity_gbps = None, None total_capacity_gbps, used_capacity_gbps = None, None
if request.HasField('attributes'): if request.HasField('attributes'):
attributes = request.attributes attributes = request.attributes
if attributes.HasField('total_capacity_gbps'): if attributes.HasField('total_capacity_gbps'):
total_capacity_gbps = attributes.total_capacity_gbps total_capacity_gbps = attributes.total_capacity_gbps
if attributes.HasField('current_capacity_gbps'): if attributes.HasField('used_capacity_gbps'):
current_capacity_gbps = attributes.current_capacity_gbps used_capacity_gbps = attributes.used_capacity_gbps
elif total_capacity_gbps is not None: elif total_capacity_gbps is not None:
current_capacity_gbps = total_capacity_gbps used_capacity_gbps = total_capacity_gbps
link_data = [{ link_data = [{
'link_uuid' : link_uuid, 'link_uuid' : link_uuid,
'link_name' : link_name, 'link_name' : link_name,
'total_capacity_gbps' : total_capacity_gbps, 'total_capacity_gbps' : total_capacity_gbps,
'current_capacity_gbps': current_capacity_gbps, 'used_capacity_gbps' : used_capacity_gbps,
'created_at' : now, 'created_at' : now,
'updated_at' : now, 'updated_at' : now,
}] }]
def callback(session : Session) -> Tuple[bool, List[Dict]]: def callback(session : Session) -> Tuple[bool, List[Dict]]:
...@@ -123,10 +123,10 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) ...@@ -123,10 +123,10 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link)
stmt = stmt.on_conflict_do_update( stmt = stmt.on_conflict_do_update(
index_elements=[LinkModel.link_uuid], index_elements=[LinkModel.link_uuid],
set_=dict( set_=dict(
link_name = stmt.excluded.link_name, link_name = stmt.excluded.link_name,
total_capacity_gbps = stmt.excluded.total_capacity_gbps, total_capacity_gbps = stmt.excluded.total_capacity_gbps,
current_capacity_gbps = stmt.excluded.current_capacity_gbps, used_capacity_gbps = stmt.excluded.used_capacity_gbps,
updated_at = stmt.excluded.updated_at, updated_at = stmt.excluded.updated_at,
) )
) )
stmt = stmt.returning(LinkModel.created_at, LinkModel.updated_at) stmt = stmt.returning(LinkModel.created_at, LinkModel.updated_at)
......
...@@ -22,19 +22,19 @@ from ._Base import _Base ...@@ -22,19 +22,19 @@ from ._Base import _Base
class LinkModel(_Base): class LinkModel(_Base):
__tablename__ = 'link' __tablename__ = 'link'
link_uuid = Column(UUID(as_uuid=False), primary_key=True) link_uuid = Column(UUID(as_uuid=False), primary_key=True)
link_name = Column(String, nullable=False) link_name = Column(String, nullable=False)
total_capacity_gbps = Column(Float, nullable=True) total_capacity_gbps = Column(Float, nullable=True)
current_capacity_gbps = Column(Float, nullable=True) used_capacity_gbps = Column(Float, nullable=True)
created_at = Column(DateTime, nullable=False) created_at = Column(DateTime, nullable=False)
updated_at = Column(DateTime, nullable=False) updated_at = Column(DateTime, nullable=False)
#topology_links = relationship('TopologyLinkModel', back_populates='link') #topology_links = relationship('TopologyLinkModel', back_populates='link')
link_endpoints = relationship('LinkEndPointModel') # lazy='joined', back_populates='link' link_endpoints = relationship('LinkEndPointModel') # lazy='joined', back_populates='link'
__table_args__ = ( __table_args__ = (
CheckConstraint(total_capacity_gbps >= 0, name='check_value_total_capacity_gbps' ), CheckConstraint(total_capacity_gbps >= 0, name='check_value_total_capacity_gbps'),
CheckConstraint(current_capacity_gbps >= 0, name='check_value_current_capacity_gbps'), CheckConstraint(used_capacity_gbps >= 0, name='check_value_used_capacity_gbps' ),
) )
def dump_id(self) -> Dict: def dump_id(self) -> Dict:
...@@ -52,9 +52,9 @@ class LinkModel(_Base): ...@@ -52,9 +52,9 @@ class LinkModel(_Base):
if self.total_capacity_gbps is not None: if self.total_capacity_gbps is not None:
attributes : Dict = result.setdefault('attributes', dict()) attributes : Dict = result.setdefault('attributes', dict())
attributes.setdefault('total_capacity_gbps', self.total_capacity_gbps) attributes.setdefault('total_capacity_gbps', self.total_capacity_gbps)
if self.current_capacity_gbps is not None: if self.used_capacity_gbps is not None:
attributes : Dict = result.setdefault('attributes', dict()) attributes : Dict = result.setdefault('attributes', dict())
attributes.setdefault('current_capacity_gbps', self.current_capacity_gbps) attributes.setdefault('used_capacity_gbps', self.used_capacity_gbps)
return result return result
class LinkEndPointModel(_Base): class LinkEndPointModel(_Base):
......
...@@ -73,7 +73,7 @@ DEVICE_R3_NAME, DEVICE_R3_ID, DEVICE_R3 = compose_device('R3', ['1.1', '1.2', '2 ...@@ -73,7 +73,7 @@ DEVICE_R3_NAME, DEVICE_R3_ID, DEVICE_R3 = compose_device('R3', ['1.1', '1.2', '2
# ----- Link ----------------------------------------------------------------------------------------------------------- # ----- Link -----------------------------------------------------------------------------------------------------------
def compose_link( def compose_link(
name : str, endpoint_ids : List[Tuple[str, str]], name : str, endpoint_ids : List[Tuple[str, str]],
total_capacity_gbps : Optional[float] = None, current_capacity_gbps : Optional[float] = None total_capacity_gbps : Optional[float] = None, used_capacity_gbps : Optional[float] = None
) -> Tuple[str, Dict, Dict]: ) -> Tuple[str, Dict, Dict]:
link_id = json_link_id(name) link_id = json_link_id(name)
endpoint_ids = [ endpoint_ids = [
...@@ -81,22 +81,21 @@ def compose_link( ...@@ -81,22 +81,21 @@ def compose_link(
for device_id, endpoint_name in endpoint_ids for device_id, endpoint_name in endpoint_ids
] ]
link = json_link( link = json_link(
name, endpoint_ids, total_capacity_gbps=total_capacity_gbps, name, endpoint_ids, total_capacity_gbps=total_capacity_gbps, used_capacity_gbps=used_capacity_gbps
current_capacity_gbps=current_capacity_gbps
) )
return name, link_id, link return name, link_id, link
LINK_R1_R2_NAME, LINK_R1_R2_ID, LINK_R1_R2 = compose_link( LINK_R1_R2_NAME, LINK_R1_R2_ID, LINK_R1_R2 = compose_link(
'R1==R2', [(DEVICE_R1_ID, '1.2'), (DEVICE_R2_ID, '1.1')], 'R1==R2', [(DEVICE_R1_ID, '1.2'), (DEVICE_R2_ID, '1.1')],
total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
) )
LINK_R2_R3_NAME, LINK_R2_R3_ID, LINK_R2_R3 = compose_link( LINK_R2_R3_NAME, LINK_R2_R3_ID, LINK_R2_R3 = compose_link(
'R2==R3', [(DEVICE_R2_ID, '1.3'), (DEVICE_R3_ID, '1.2')], 'R2==R3', [(DEVICE_R2_ID, '1.3'), (DEVICE_R3_ID, '1.2')],
total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
) )
LINK_R1_R3_NAME, LINK_R1_R3_ID, LINK_R1_R3 = compose_link( LINK_R1_R3_NAME, LINK_R1_R3_ID, LINK_R1_R3 = compose_link(
'R1==R3', [(DEVICE_R1_ID, '1.3'), (DEVICE_R3_ID, '1.1')], 'R1==R3', [(DEVICE_R1_ID, '1.3'), (DEVICE_R3_ID, '1.1')],
total_capacity_gbps=100, # current_capacity_gbps=None => current_capacity_gbps=total_capacity_gbps total_capacity_gbps=100, # used_capacity_gbps=None => used_capacity_gbps=total_capacity_gbps
) )
......
...@@ -98,8 +98,8 @@ def test_link(context_client : ContextClient) -> None: ...@@ -98,8 +98,8 @@ def test_link(context_client : ContextClient) -> None:
assert response.HasField('attributes') assert response.HasField('attributes')
assert response.attributes.HasField('total_capacity_gbps') assert response.attributes.HasField('total_capacity_gbps')
assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12 assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12
assert response.attributes.HasField('current_capacity_gbps') assert response.attributes.HasField('used_capacity_gbps')
assert abs(response.attributes.current_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12 assert abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12
# ----- List when the object exists -------------------------------------------------------------------------------- # ----- List when the object exists --------------------------------------------------------------------------------
response = context_client.ListLinkIds(Empty()) response = context_client.ListLinkIds(Empty())
...@@ -117,7 +117,7 @@ def test_link(context_client : ContextClient) -> None: ...@@ -117,7 +117,7 @@ def test_link(context_client : ContextClient) -> None:
LINK_UPDATED = copy.deepcopy(LINK_R1_R2) LINK_UPDATED = copy.deepcopy(LINK_R1_R2)
LINK_UPDATED['name'] = new_link_name LINK_UPDATED['name'] = new_link_name
LINK_UPDATED['attributes']['total_capacity_gbps'] = 200 LINK_UPDATED['attributes']['total_capacity_gbps'] = 200
LINK_UPDATED['attributes']['current_capacity_gbps'] = 50 LINK_UPDATED['attributes']['used_capacity_gbps'] = 50
response = context_client.SetLink(Link(**LINK_UPDATED)) response = context_client.SetLink(Link(**LINK_UPDATED))
assert response.link_uuid.uuid == link_uuid assert response.link_uuid.uuid == link_uuid
...@@ -135,8 +135,8 @@ def test_link(context_client : ContextClient) -> None: ...@@ -135,8 +135,8 @@ def test_link(context_client : ContextClient) -> None:
assert response.HasField('attributes') assert response.HasField('attributes')
assert response.attributes.HasField('total_capacity_gbps') assert response.attributes.HasField('total_capacity_gbps')
assert abs(response.attributes.total_capacity_gbps - 200) < 1.e-12 assert abs(response.attributes.total_capacity_gbps - 200) < 1.e-12
assert response.attributes.HasField('current_capacity_gbps') assert response.attributes.HasField('used_capacity_gbps')
assert abs(response.attributes.current_capacity_gbps - 50) < 1.e-12 assert abs(response.attributes.used_capacity_gbps - 50) < 1.e-12
# ----- List when the object is modified --------------------------------------------------------------------------- # ----- List when the object is modified ---------------------------------------------------------------------------
response = context_client.ListLinkIds(Empty()) response = context_client.ListLinkIds(Empty())
...@@ -152,8 +152,8 @@ def test_link(context_client : ContextClient) -> None: ...@@ -152,8 +152,8 @@ def test_link(context_client : ContextClient) -> None:
assert response.links[0].HasField('attributes') assert response.links[0].HasField('attributes')
assert response.links[0].attributes.HasField('total_capacity_gbps') assert response.links[0].attributes.HasField('total_capacity_gbps')
assert abs(response.links[0].attributes.total_capacity_gbps - 200) < 1.e-12 assert abs(response.links[0].attributes.total_capacity_gbps - 200) < 1.e-12
assert response.links[0].attributes.HasField('current_capacity_gbps') assert response.links[0].attributes.HasField('used_capacity_gbps')
assert abs(response.links[0].attributes.current_capacity_gbps - 50) < 1.e-12 assert abs(response.links[0].attributes.used_capacity_gbps - 50) < 1.e-12
# ----- Check relation was created --------------------------------------------------------------------------------- # ----- Check relation was created ---------------------------------------------------------------------------------
response = context_client.GetTopology(TopologyId(**TOPOLOGY_ID)) response = context_client.GetTopology(TopologyId(**TOPOLOGY_ID))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment