# Buggy code
def log(self, log_file):
    mac_table = {}
    if not log_file:
        # default to FAUCET default
        log_file = "/var/log/ryu/faucet/faucet.log"
    # NOTE very fragile, prone to errors
    try:
        with open(log_file, "r") as f:
            for line in f:
                if "L2 learned" in line:
                    learned_mac = line.split()
                    data = {
                        "ip-address": learned_mac[16][0:-1],
                        "ip-state": "L2 learned",
                        "mac": learned_mac[10],
                        "segment": learned_mac[7][1:-1],
                        "port": learned_mac[19],
                        "tenant": learned_mac[21] + learned_mac[22],
                    }
                    if learned_mac[10] in mac_table:
                        dup = False
                        for d in mac_table[learned_mac[10]]:
                            if data == d:
                                dup = True
                        if dup:
                            mac_table[learned_mac[10]].remove(data)
                        mac_table[learned_mac[10]].insert(0, data)
                    else:
                        mac_table[learned_mac[10]] = [data]
    except Exception as e:
        self.logger.debug("error {0}".format(str(e)))
    return mac_table


# Traceback (ValueError)
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]: Traceback (most recent call last):
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:   File "/tmp/poseidonWork/poseidon/poseidonMonitor/poseidonMonitor.py", line 538, in <module>
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:     main(skip_rabbit=False)
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:   File "/tmp/poseidonWork/poseidon/poseidonMonitor/poseidonMonitor.py", line 528, in main
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:     pmain.process()
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:   File "/tmp/poseidonWork/poseidon/poseidonMonitor/poseidonMonitor.py", line 419, in process
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:     self.uss.mirror_endpoint(endpoint_hash)
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:   File "/tmp/poseidonWork/poseidon/poseidonMonitor/NorthBoundControllerAbstraction/UpdateSwitchState.py", line 150, in mirror_endpoint
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:     self.sdnc.mirror_ip(my_ip)
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:   File "/tmp/poseidonWork/poseidon/poseidonMonitor/NorthBoundControllerAbstraction/proxy/faucet/faucet.py", line 178, in mirror_ip
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]:     'mirror', int(port), switch):
2018-03-05T11:55:18+00:00 172.17.0.1 plugin[788]: ValueError: invalid literal for int() with base 10: '192.168.1.255)'

# Fixed code
def log(self, log_file):
    mac_table = {}
    if not log_file:
        # default to FAUCET default
        log_file = "/var/log/ryu/faucet/faucet.log"
    # NOTE very fragile, prone to errors
    try:
        with open(log_file, "r") as f:
            for line in f:
                if "L2 learned" in line:
                    learned_mac = line.split()
                    data = {
                        "ip-address": learned_mac[16][0:-1],
                        "ip-state": "L2 learned",
                        "mac": learned_mac[10],
                        "segment": learned_mac[7][1:-1],
                        "port": learned_mac[22],
                        "tenant": learned_mac[24] + learned_mac[25],
                    }
                    if learned_mac[10] in mac_table:
                        dup = False
                        for d in mac_table[learned_mac[10]]:
                            if data == d:
                                dup = True
                        if dup:
                            mac_table[learned_mac[10]].remove(data)
                        mac_table[learned_mac[10]].insert(0, data)
                    else:
                        mac_table[learned_mac[10]] = [data]
    except Exception as e:
        self.logger.debug("error {0}".format(str(e)))
    return mac_table