コード例 #1
0
    def __cmp__(self, other):
        if not hasattr(other, "sessionIpAddrType"):
            return 0
        if self.sessionIpAddrType != other.sessionIpAddrType:
            return self.sessionIpAddrType.__cmp__(other.sessionIpAddrType)

        if not hasattr(other, "ccapLcceIpAddr"):
            return 0
        if self.ccapLcceIpAddr != other.ccapLcceIpAddr:
            return Convert.compare_ip(self.ccapLcceIpAddr,
                                      other.ccapLcceIpAddr)

        if not hasattr(other, "rpdLcceIpAddr"):
            return 0
        if self.rpdLcceIpAddr != other.rpdLcceIpAddr:
            return Convert.compare_ip(self.rpdLcceIpAddr,
                                      other.rpdLcceIpAddr)

        if not hasattr(other, "direction"):
            return 0
        if self.direction != other.direction:
            return self.direction.__cmp__(other.direction)

        if not hasattr(other, "l2tpSessionId"):
            return 0
        if self.l2tpSessionId != other.l2tpSessionId:
            return self.l2tpSessionId.__cmp__(other.l2tpSessionId)

        return 0
コード例 #2
0
    def __cmp__(self, other):
        """
        the function is used for comparation, the compared sequence is defined in TLV definition.
        :param other: the object who has the IpAddrType, GroupIpAddr, SrcIpAddr, SessionId
        :return:
        """
        if not hasattr(other, "IpAddrType"):
            return 0

        if self.IpAddrType != other.IpAddrType:
            return self.IpAddrType.__cmp__(other.IpAddrType)

        if not hasattr(other, "GroupIpAddr"):
            return 0

        if self.GroupIpAddr != other.GroupIpAddr:
            return Convert.compare_ip(self.GroupIpAddr, other.GroupIpAddr)

        if not hasattr(other, "SrcIpAddr"):
            return 0

        if self.SrcIpAddr != other.SrcIpAddr:
            return Convert.compare_ip(self.SrcIpAddr, other.SrcIpAddr)

        if not hasattr(other, "SessionId"):
            return 0

        return self.SessionId.__cmp__(other.SessionId)
コード例 #3
0
ファイル: test_utils.py プロジェクト: hujiangyi/or
 def test_compip(self):
     ret = Convert.compare_ip("10.79.41.31", "10.79.41.31")
     self.assertEquals(ret, 0)
     ret = Convert.compare_ip("10.79.41.30", "10.79.41.31")
     self.assertEquals(ret, -1)
     ret = Convert.compare_ip("10.79.41.30", "10.25.41.31")
     self.assertEquals(ret, 1)
     ret = Convert.compare_ip("fe80::6a5b:35ff:feb2:8dcf",
                              "fe80::6a5b:35ff:feb2:8d6f")
     self.assertEquals(ret, 1)
コード例 #4
0
    def __cmp__(self, other):
        if not hasattr(other, "EnetPortIndex"):
            return 0

        if self.EnetPortIndex != other.EnetPortIndex:
            return self.EnetPortIndex - other.EnetPortIndex

        if not hasattr(other, "AddrType"):
            return 0

        if self.AddrType != other.AddrType:
            return self.AddrType - other.AddrType

        if not hasattr(other, "IpAddress"):
            return 0

        if self.IpAddress != other.IpAddress:
            return Convert.compare_ip(self.IpAddress, other.IpAddres)

        return 0