コード例 #1
0
 /// <summary>
 /// Checks if a given packet matches this rule.
 /// </summary>
 /// <param name="packet">The packet to test.</param>
 /// <returns>True if the packet matches; otherwise false.</returns>
 public Zen <bool> Matches(Zen <Packet> packet)
 {
     // TODO: If ports are zero, do NOT include in predicate (zero implies "ANY")
     return(And(packet.GetDstIp() >= this.DstIpLow,
                packet.GetDstIp() <= this.DstIpHigh,
                packet.GetDstPort() == this.DstPort,
                packet.GetSrcIp() >= this.SrcIpLow,
                packet.GetSrcIp() <= this.SrcIpHigh,
                packet.GetSrcPort() == this.SrcPort));
 }
コード例 #2
0
ファイル: Acl.cs プロジェクト: maxlevatich/Zen
        /// <summary>
        /// Match a packet with this acl.
        /// </summary>
        /// <param name="packet">The packet.</param>
        /// <returns>Whether accepted.</returns>
        public Zen <bool> Match(Zen <Packet> packet)
        {
            var dstIp = packet.GetDstIp();
            var srcIp = packet.GetSrcIp();

            return(And(dstIp >= this.DstIpLow,
                       dstIp <= this.DstIpHigh,
                       srcIp >= this.SrcIpLow,
                       srcIp <= this.SrcIpHigh));
        }
コード例 #3
0
        public Zen <Boolean> Forward(Zen <SimplePacket> p, Zen <IList <Tuple <int, int> > > failedLinks)
        {
            // path generation
            HashSet <List <int> > pathSet = new HashSet <List <int> >();

            for (int i = 0; i < nodes.Count; i++)
            {
                for (int j = 0; j < nodes.Count; j++)
                {
                    var nextHopIp = nodes[i].getNextHop(nodes[j].Address);
                    if (nextHopIp.Value != GlobalVar.NULL_IP.Value)
                    {
                        // there is a route
                        List <int> currRoute = new List <int>();
                        currRoute.Add(i);

                        var currCost = 0;
                        while (nextHopIp.Value != GlobalVar.NULL_IP.Value &&
                               nextHopIp.Value != nodes[j].Address.Value)
                        {
                            currRoute.Add((int)nextHopIp.Value);
                            nextHopIp = nodes[(int)nextHopIp.Value].getNextHop(nodes[j].Address);

                            currCost += 1;
                        }

                        currRoute.Add(j);

                        if (currCost < this.maxCost && !currRoute.Contains((int)this.intermediateNode.Value))
                        {
                            pathSet.Add(currRoute);
                            // Console.WriteLine("Adding path " + nodes[i].Address + " " + nodes[j].Address);
                        }
                    }
                }
            }
            //var a = new List<int>() { 1, 2 };
            //pathSet.Add(a);

            // forwarding w/ Zen
            Zen <Boolean> forwardSuccess = False();

            foreach (List <int> path in pathSet)
            {
                var startNode = nodes[path[0]];
                var endNode   = nodes[path[path.Count - 1]];
                forwardSuccess = If(And(p.GetSrcIp() == startNode.Address, p.GetDstIp() == endNode.Address),
                                    Forward(path.ToArray(), p, failedLinks).HasValue(),
                                    forwardSuccess);
            }
            //Console.WriteLine("Final Expression:");
            //Console.WriteLine(forwardSuccess);
            //Console.WriteLine();
            return(forwardSuccess);
        }
コード例 #4
0
ファイル: Acl.cs プロジェクト: maxlevatich/Zen
        public Zen <bool> Matches(Zen <IpHeader> hdr)
        {
            Zen <bool> dstLowMatch  = this.DstLow.HasValue ? hdr.GetDstIp().GetValue() >= this.DstLow.Value.Value : true;
            Zen <bool> dstHighMatch = this.DstHigh.HasValue ? hdr.GetDstIp().GetValue() <= this.DstHigh.Value.Value : true;
            Zen <bool> srcLowMatch  = this.SrcLow.HasValue ? hdr.GetSrcIp().GetValue() >= this.SrcLow.Value.Value : true;
            Zen <bool> srcHighMatch = this.SrcHigh.HasValue ? hdr.GetSrcIp().GetValue() <= this.SrcHigh.Value.Value : true;

            Zen <bool> dstPortLowMatch  = this.DstPortLow.HasValue ? hdr.GetDstPort() >= this.DstPortLow.Value : true;
            Zen <bool> dstPortHighMatch = this.DstPortHigh.HasValue ? hdr.GetDstPort() <= this.DstPortHigh.Value : true;

            Zen <bool> srcPortLowMatch  = this.SrcPortLow.HasValue ? hdr.GetSrcPort() >= this.SrcPortLow.Value : true;
            Zen <bool> srcPortHighMatch = this.SrcPortHigh.HasValue ? hdr.GetSrcPort() <= this.SrcPortHigh.Value : true;

            Zen <bool> protoLowMatch  = this.ProtocolLow.HasValue ? hdr.GetProtocol() >= this.ProtocolLow.Value : true;
            Zen <bool> protoHighMatch = this.ProtocolHigh.HasValue ? hdr.GetProtocol() <= this.ProtocolHigh.Value : true;

            return(And(
                       dstLowMatch, dstHighMatch,
                       srcLowMatch, srcHighMatch,
                       dstPortHighMatch, dstPortLowMatch,
                       srcPortHighMatch, srcPortLowMatch,
                       protoHighMatch, protoLowMatch));
        }