示例#1
0
    def test_vlan(self):
        flow = pb.VLANFlow(match=pb.VLANFlow.Match(
            in_port=1,
            vid=_VID,
            vid_mask=_VID_MASK,
        ),
                           actions=[],
                           goto_table=pb.FlowMod.TERM_MAC)
        mod = pb.FlowMod(cmd="ADD",
                         table=pb.FlowMod.VLAN,
                         re_id=_RE_ID,
                         vlan=flow)

        p = fibcdbm.FIBCPortEntry.new(name=_IFNAME,
                                      port=2,
                                      dp_id=_DP_ID,
                                      re_id=_RE_ID)
        portmap = Mock(spec=fibcdbm.FIBCDbPortMapTable)
        portmap.find_by_vm.return_value = p
        portmap.lower_port.return_value = p

        #exec
        fibccnv.conv_flow(mod, portmap)

        #check
        self.assertEqual(mod.cmd, pb.FlowMod.ADD)
        self.assertEqual(mod.table, pb.FlowMod.VLAN)
        self.assertEqual(mod.re_id, _RE_ID)
        self.assertEqual(mod.vlan.match.in_port, 2)
        self.assertEqual(mod.vlan.match.vid, _VID)
        self.assertEqual(mod.vlan.match.vid_mask, _VID_MASK)
        self.assertEqual(len(mod.vlan.actions), 0)
        self.assertEqual(mod.vlan.goto_table, pb.FlowMod.TERM_MAC)
示例#2
0
    def test_new(self):
        m = pb.VLANFlow.Match(in_port = 1, vid = 10)
        a = [
            pb.VLANFlow.Action(name="SET_VLAN_VID", value=10),
            pb.VLANFlow.Action(name="SET_VRF", value=1)
        ]
        flow = pb.VLANFlow(match=m, actions=a, goto_table=20)
        mod = pb.FlowMod(cmd="ADD", table="VLAN", vlan=flow)

        b = mod.SerializeToString()
        m = api.parse_flow_mod(b)

        self.assertEqual(str(mod), str(m))
示例#3
0
    def _mod_flow_vlan(self, msg):
        re_id = msg["re_id"]
        cmd = msg["cmd"]
        for arg in msg["args"]:
            match = pb.VLANFlow.Match(in_port=arg["port"],
                                      vid=arg.get("vid", 0),
                                      vid_mask=arg.get("mask", 0))

            actions = []
            if arg["vrf"] != 0:
                actions.append(pb.VLANFlow.Action(name="SET_VRF", value=arg["vrf"]))
            if "new_vid" in arg:
                actions.append(pb.VLANFlow.Action(name="PUSH_VLAN", value=arg["new_vid"]))

            flow = pb.VLANFlow(match=match, actions=actions, goto_table=20)
            mod = pb.FlowMod(cmd=cmd, re_id=re_id, table="VLAN", vlan=flow)
            evt = fibcevt.EventFIBCFlowMod(mod)

            self.app.send_event_to_observers(evt)