Skip to content

Resolve "problem with updating connect_to"

Hana Jirovska requested to merge 14-problem-with-updating-connect_to into develop

Closes #14 (closed)

Following the discussion on #14 (closed), I have looked more into the issue of the UPDATE functionality. We have decided to move the functionality to netconf.py so all the extra keyword functionality resides in the same file.

The main underlying problem in #14 (closed) was that two connections were referring to the same anchor and both of them were then updating the properties set from the anchor in a different way. However, when the anchors are used, the updates (with UPDATE keyword, or any mutation) propagate to all the places where a specified anchor was used. To get around this problem, it is simply enough to first define the specific properties and then use the anchor:

connect_to: &connect_to
  node1: NodeA
  node2: NodeB
  port_name_node1: top
  port_name_node2: top
  label: connection

components:
   connection:
      type: Connection
      connect_to:
        node1: NodeC
        node2: NodeD
        << : *connect_to

This is because YAML anchors check what keys are already defined (in this case node1 and node2), and update only keys that are not defined yet. This eliminates the need for the UPDATE keyword in the first place. However, YAML anchors do not check for keys recursively, i.e. in the following example, resulting properties would hold length, and not p_loss_init or p_loss_length.

fibre: &fibre
  type: wrong_connection
  properties:
    length: 0.002
    p_loss_init: 0
    p_loss_length: 0

components:
  connection:
    type: classical_fibre_direct_connection
    properties:
      length: 1
    << : *fibre     

An easy solution for that (for now) is to use anchors that are not nested, such as below. I also changed all the anchors in the test-configs to work with one-level anchors.

fibre_properties: &fibre_prop
  length: 0.002
  p_loss_init: 0
  p_loss_length: 0

components:
  connection:
    type: classical_fibre_direct_connection
    properties:
      length: 1
      << : *fibre_prop     

I realise, however, that this solution is probably far from ideal. I'll continue looking into anchors to see whether I can adjust them to work recursively. (I will be making another issue out of that.) For now, I removed the UPDATE keyword functionality. While it is recursive, it works only if the anchor is used in one place and that doesn't seem very useful. It's in the commit history if we ever decide to go back to it or if you would still find it useful.

Merge request reports