Exemplo n.º 1
0
 def _check_remote_ifid(self, pcb: PathSegment) -> Optional[ISD_AS]:
     Requires(Acc(pcb.State(), 1 / 20))
     Ensures(Acc(pcb.State(), 1 / 20))
     """
     Checkes whether any PCB markings have unset remote IFID values for
     up/downstream ASes. This can happen during normal startup depending
     on the timing of PCB propagation vs IFID keep-alives, but should
     not happen once the infrastructure is settled.
     Remote IFID is only allowed to be 0 if the corresponding ISD-AS is
     0-0.
     """
     asms = pcb.iter_asms()
     for asm in asms:
         Invariant(Forall(asms, lambda a: (Acc(a.State(), 1 / 4), [])))
         pcbms = asm.iter_pcbms()
         for pcbm in pcbms:
             Invariant(Forall(pcbms, lambda p: (Acc(p.State(), 1 / 4), [])))
             if (pcbm.inIA().to_int() and not Unfolding(
                     Acc(pcbm.State(), 1 / 8),
                     Unfolding(Acc(pcbm.p.State(), 1 / 16), pcbm.p.inIF))):
                 return pcbm.inIA()
             if (pcbm.outIA().to_int() and not Unfolding(
                     Acc(pcbm.State(), 1 / 8),
                     Unfolding(Acc(pcbm.p.State(), 1 / 16), pcbm.p.outIF))):
                 return pcbm.outIA()
     return None
Exemplo n.º 2
0
    def check_filters(self, pcb: PathSegment) -> bool:
        Requires(Acc(pcb.State(), 1 / 10))
        Requires(Acc(self.State(), 1 / 7))
        Requires(self.valid_ranges())
        Ensures(Acc(pcb.State(), 1 / 10))
        Ensures(Acc(self.State(), 1 / 7))
        """
        Runs some checks, including: unwanted ASes and min/max property values.

        :param pcb: beacon to analyze.
        :type pcb: :class:`PathSegment`
        :returns:
            True if any unwanted AS is present or a range is not respected.
        :rtype: bool
        """
        assert isinstance(pcb, PathSegment)
        isd_as = self._check_unwanted_ases(pcb)
        if isd_as:
            logging.warning("PathStore: pcb discarded, unwanted AS(%s): %s",
                            isd_as, pcb.short_desc())
            return False
        reasons = self._check_property_ranges(pcb)
        if reasons:
            logging.info("PathStore: pcb discarded(%s): %s",
                         ", ".join(reasons), pcb.short_desc())
            return False
        ia = self._check_remote_ifid(pcb)
        if ia:
            logging.error(
                "PathStore: pcb discarded, remote IFID of %s unknown", )
            return False
        return True
Exemplo n.º 3
0
    def _check_unwanted_ases(
            self, pcb: PathSegment) -> Optional[ISD_AS]:  # pragma: no cover
        Requires(Acc(pcb.State(), 1 / 20))
        Requires(Acc(self.State(), 1 / 8))
        Ensures(Acc(pcb.State(), 1 / 20))
        Ensures(Acc(self.State(), 1 / 8))
        """
        Checks whether any of the ASes in the path belong to the black list.

        :param pcb: beacon to analyze.
        :type pcb: :class:`PathSegment`
        """
        asms = pcb.iter_asms()
        for asm in asms:
            Invariant(Forall(asms, lambda a: (Acc(a.State(), 1 / 4), [])))
            Invariant(Acc(self.State(), 1 / 9))
            Invariant(Acc(pcb.State(), 1 / 20))
            isd_as = asm.isd_as()
            Unfold(Acc(self.State(), 1 / 10))
            if isd_as in self.unwanted_ases:
                Fold(Acc(self.State(), 1 / 10))
                return isd_as
            Fold(Acc(self.State(), 1 / 10))