def test_get_oper_pg_lsp(self):
        dcbtool_go_pg = """
Command:        Get Oper
Feature:        Priority Groups
Port:           eth3
Status:         Successful
Oper Version:   0
Max Version:    0
Errors:         0x00 - none
Oper Mode:      true
Syncd:          true
up2tc:          0       0       3       1       2       0       4       0
pgpct:          20%     10%     40%     30%     0%      0%      0%      0%
pgid:           0       0       3       1       2       0       f       0
uppct:          25%     25%     100%    100%    100%    25%     100%    25%
pg strict:      0       0       0       0       0       0       0       0
"""

        r = dcbtool.parse(dcbtool_go_pg)
        self.assertEqual(r['Command'], "Get Oper")
        self.assertEqual(r['Feature'], "Priority Groups")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Oper Version'], 0)
        self.assertEqual(r['Max Version'], 0)
        self.assertEqual(r['Errors'], (0, "none"))
        self.assertEqual(r['Oper Mode'], True)
        self.assertEqual(r['Syncd'], True)
        self.assertEqual(r['up2tc'], {
                         0: 0, 1: 0, 2: 3, 3: 1, 4: 2, 5: 0, 6: 4, 7: 0})
        self.assertEqual(r['pgid'], {
                         0: 0, 1: 0, 2: 3, 3: 1, 4: 2, 5: 0, 6: 15, 7: 0})
        self.assertEqual(r['pgpct'], (20, 10, 40, 30, 0, 0, 0, 0))
        self.assertEqual(r['uppct'], (25, 25, 100, 100, 100, 25, 100, 25))
        self.assertEqual(r['pg strict'], dict(((n, False) for n in range(8))))
    def test_get_config_pg(self):
        dcbtool_gc_pg = """
Command:        Get Config
Feature:        Priority Groups
Port:           eth3
Status:         Successful
Enable:         true
Advertise:      true
Willing:        true
up2tc:          0       1       2       3       4       5       6       7
pgpct:          13%     13%     13%     13%     12%     12%     12%     12%
pgid:           0       1       2       3       4       5       6       7
uppct:          100%    100%    100%    100%    100%    100%    100%    100%
pg strict:      0       0       0       0       0       0       0       0
num TC's:       8
"""

        r = dcbtool.parse(dcbtool_gc_pg)
        self.assertEqual(r['Command'], "Get Config")
        self.assertEqual(r['Feature'], "Priority Groups")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Enable'], True)
        self.assertEqual(r['Advertise'], True)
        self.assertEqual(r['Willing'], True)
        self.assertEqual(r['up2tc'], {
                         0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7})
        self.assertEqual(r['pgid'], {
                         0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7})
        self.assertEqual(r['pgpct'], (13, 13, 13, 13, 12, 12, 12, 12))
        self.assertEqual(r['uppct'], (100, 100, 100, 100, 100, 100, 100, 100))
        self.assertEqual(r['pg strict'], dict(((n, False) for n in range(8))))
        self.assertEqual(r["num TC's"], 8)
    def test_get_oper_app_iscsi(self):
        dcbtool_go_app_iscsi = """
Command:        Get Oper
Feature:        Application iSCSI
Port:           eth3
Status:         Successful
Oper Version:   0
Max Version:    0
Errors:         0x00 - none
Oper Mode:      true
Syncd:          true
appcfg:         10
"""

        r = dcbtool.parse(dcbtool_go_app_iscsi)
        self.assertEqual(r['Command'], "Get Oper")
        self.assertEqual(r['Feature'], "Application iSCSI")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Oper Version'], 0)
        self.assertEqual(r['Max Version'], 0)
        self.assertEqual(r['Errors'], (0, "none"))
        self.assertEqual(r['Oper Mode'], True)
        self.assertEqual(r['Syncd'], True)
        self.assertEqual(r['appcfg'], 16)
    def test_get_oper_pfc(self):
        dcbtool_go_pfc = """
Command:        Get Oper
Feature:        Priority Flow Control
Port:           eth3
Status:         Successful
Oper Version:   0
Max Version:    0
Errors:         0x00 - none
Oper Mode:      true
Syncd:          true
pfcup:          0       0       1       1       1       0       1       0
"""

        r = dcbtool.parse(dcbtool_go_pfc)
        self.assertEqual(r['Command'], "Get Oper")
        self.assertEqual(r['Feature'], "Priority Flow Control")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Oper Version'], 0)
        self.assertEqual(r['Max Version'], 0)
        self.assertEqual(r['Errors'], (0, "none"))
        self.assertEqual(r['Oper Mode'], True)
        self.assertEqual(r['Syncd'], True)
        self.assertEqual(r['pfcup'], {
            0: False,
            1: False,
            2: True,
            3: True,
            4: True,
            5: False,
            6: True,
            7: False
        })
        def from_dcbtool_get(cls, output):

            tlvs = dcbtool.parse(output)
            # uppercase Willing
            return cls(
                control=DCBControlModel(
                    enable=DCBTool.dcbtool_guess_enable(tlvs),
                    advertise=DCBTool.dcbtool_guess_advertise(tlvs),
                    willing=DCBTool.dcbtool_guess_willing(tlvs)),
                data=PFCModel(
                    enabled=tlvs['pfcup'],
                    max_tcs=tlvs["num TC's"],
                ))
        def from_dcbtool_get(cls, output):

            tlvs = dcbtool.parse(output)
            selector, protocol = cls.get_protocol_and_selector(tlvs['Feature'])
            priorities = bitmask_to_dict(tlvs['appcfg'])
            applications = dict(
                ((AppPriorityEntry(priority=up, selector=selector,
                 protocol=protocol), True) for up in priorities)
            )
            return cls(
                control=DCBControlModel(
                    enable=DCBTool.dcbtool_guess_enable(tlvs),
                    advertise=DCBTool.dcbtool_guess_advertise(tlvs),
                    willing=DCBTool.dcbtool_guess_willing(tlvs)),
                data=AppModel(applications=applications))
        def from_dcbtool_get(cls, output):

            tlvs = dcbtool.parse(output)
            # uppercase Willing
            tsa_map, up2tc = DCBTool.cee_to_ieee_ets(tlvs['pgid'])

            return cls(
                control=DCBControlModel(
                    enable=DCBTool.dcbtool_guess_enable(tlvs),
                    advertise=DCBTool.dcbtool_guess_advertise(tlvs),
                    willing=DCBTool.dcbtool_guess_willing(tlvs)),
                data=ETSModel(
                    up2tc=up2tc,
                    tcbw=tlvs["pgpct"],
                    tsa=tsa_map,
                ))
    def test_get_config_app_iscsi(self):
        dcbtool_gc_app_iscsi = """
Command:        Get Config
Feature:        Application iSCSI
Port:           eth3
Status:         Successful
Enable:         true
Advertise:      true
Willing:        true
appcfg:         10
"""
        r = dcbtool.parse(dcbtool_gc_app_iscsi)
        self.assertEqual(r['Command'], "Get Config")
        self.assertEqual(r['Feature'], "Application iSCSI")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Enable'], True)
        self.assertEqual(r['Advertise'], True)
        self.assertEqual(r['Willing'], True)
        self.assertEqual(r['appcfg'], 16)
    def test_get_config_pfc(self):
        dcbtool_gc_pfc = """
Command:        Get Config
Feature:        Priority Flow Control
Port:           eth3
Status:         Successful
Enable:         true
Advertise:      true
Willing:        true
pfcup:          0       0       0       0       0       0       0       0
num TC's:       8
"""
        r = dcbtool.parse(dcbtool_gc_pfc)
        self.assertEqual(r['Command'], "Get Config")
        self.assertEqual(r['Feature'], "Priority Flow Control")
        self.assertEqual(r['Port'], "eth3")
        self.assertEqual(r['Status'], "Successful")
        self.assertEqual(r['Enable'], True)
        self.assertEqual(r['Advertise'], True)
        self.assertEqual(r['Willing'], True)
        self.assertEqual(r['pfcup'], dict(((n, False) for n in range(8))))
        self.assertEqual(r["num TC's"], 8)