コード例 #1
0
        /// <summary>
        /// Find pods can only be reached from pods of same user.
        /// </summary>
        /// <param name="matrix">ingress reachability matrix.</param>
        /// <param name="userHashmap">user-pod mapping.</param>
        /// <param name="pods">all pods.</param>
        /// <param name="userKey">key of user label.</param>
        /// <returns>list of pods can only be reached from pods of same user.</returns>
        public static Zen <IList <ushort> > UserCrossCheck(
            Zen <IList <bool> >[] matrix,
            Zen <IDictionary <int, IList <bool> > > userHashmap,
            Zen <Pod>[] pods,
            Zen <string> userKey)
        {
            var n = pods.Length;
            Zen <IList <ushort> > podList = EmptyList <ushort>();

            for (int i = 0; i < n; ++i)
            {
                var userString = pods[i].LabelValue(userKey);
                if (userString == null)
                {
                    continue;
                }
                var veriSet = userHashmap.Get(userString.GetHashCode()).Value();
                veriSet = veriSet.Not().And(matrix[i]);
                var c = If <ushort>(veriSet.All(r => r.Equals(False())), (ushort)i, ushort.MaxValue);
                // if this pod can only be reached from same user's pods, add it to list
                if (!c.EqualToNumber(ushort.MaxValue))
                {
                    podList = podList.AddBack(c);
                }
            }
            return(podList);
        }
コード例 #2
0
        /// <summary>
        /// Find pods are all reachable/isolated.
        /// </summary>
        /// <param name="matrix">ingress reachability matrix.</param>
        /// <param name="reach">reachable or isolated flag.</param>
        /// <returns>list of reachable/isolated pods index.</returns>
        public static Zen <IList <ushort> > AllReachableCheck(Zen <IList <bool> >[] matrix, Zen <bool> reach)
        {
            int n = matrix.Length;
            Zen <IList <ushort> > podList = EmptyList <ushort>();

            for (var i = 0; i < n; ++i)
            {
                var c = If(reach, If <ushort>(matrix[i].All(r => r.Equals(reach)), (ushort)i, ushort.MaxValue), IsolatedCheckHelper(matrix[i], (ushort)i, 1));
                if (c.EqualToNumber((ushort)i))
                {
                    podList = podList.AddBack(c);
                }
            }
            return(podList);
        }
コード例 #3
0
        /// <summary>
        /// Find isolated pods to pod index.
        /// </summary>
        /// <param name="matrix">egress reachability matrix.</param>
        /// <param name="index">pod is being checked.</param>
        /// <returns>list of pods cant be reached from pod index.</returns>
        public static Zen <IList <ushort> > SystemIsolationCheck(
            Zen <IList <bool> >[] matrix,
            Zen <ushort> index)
        {
            var n       = matrix.Length;
            var ind     = ushort.Parse(index.ToString());
            var veriSet = matrix[ind].Not();
            Zen <IList <ushort> > cList = EmptyList <ushort>();

            for (int i = 0; i < n; ++i)
            {
                var c = If <ushort>(veriSet.At((ushort)i).Value().Equals(True()), (ushort)i, ushort.MaxValue);
                if (c.EqualToNumber((ushort)i))
                {
                    cList = cList.AddBack(c);
                }
            }
            return(cList);
        }