Code Duplication    Length = 15-32 lines in 2 locations

models/evc.py 2 locations

@@ 733-764 (lines=32) @@
730
731
        return flow_mod
732
733
    def _prepare_push_flow(self, *args, queue_id=None):
734
        """Prepare push flow.
735
736
        Arguments:
737
            in_interface(str): Interface input.
738
            out_interface(str): Interface output.
739
            in_vlan(str): Vlan input.
740
            out_vlan(str): Vlan output.
741
742
        Return:
743
            dict: An python dictionary representing a FlowMod
744
745
        """
746
        # assign all arguments
747
        in_interface, out_interface, in_vlan, out_vlan = args
748
749
        flow_mod = self._prepare_flow_mod(
750
            in_interface, out_interface, queue_id
751
        )
752
753
        # the service tag must be always pushed
754
        new_action = {"action_type": "set_vlan", "vlan_id": out_vlan}
755
        flow_mod["actions"].insert(0, new_action)
756
757
        new_action = {"action_type": "push_vlan", "tag_type": "s"}
758
        flow_mod["actions"].insert(0, new_action)
759
760
        if in_vlan:
761
            # if in_vlan is set, it must be included in the match
762
            flow_mod["match"]["dl_vlan"] = in_vlan
763
            new_action = {"action_type": "pop_vlan"}
764
            flow_mod["actions"].insert(0, new_action)
765
        return flow_mod
766
767
    def _prepare_pop_flow(
@@ 767-781 (lines=15) @@
764
            flow_mod["actions"].insert(0, new_action)
765
        return flow_mod
766
767
    def _prepare_pop_flow(
768
        self, in_interface, out_interface, in_vlan, out_vlan, queue_id=None
769
    ):
770
        # pylint: disable=too-many-arguments
771
        """Prepare pop flow."""
772
        flow_mod = self._prepare_flow_mod(
773
            in_interface, out_interface, queue_id
774
        )
775
        flow_mod["match"]["dl_vlan"] = out_vlan
776
        if in_vlan:
777
            new_action = {"action_type": "set_vlan", "vlan_id": in_vlan}
778
            flow_mod["actions"].insert(0, new_action)
779
            new_action = {"action_type": "push_vlan", "tag_type": "c"}
780
            flow_mod["actions"].insert(0, new_action)
781
        new_action = {"action_type": "pop_vlan"}
782
        flow_mod["actions"].insert(0, new_action)
783
        return flow_mod
784