module opendaylight-meter-types {
    namespace "urn:opendaylight:meter:types";
    prefix meter;

    import ietf-yang-types {prefix yang; revision-date "2013-07-15";}
    import openflow-protocol { prefix ofproto; revision-date "2013-07-31"; }
    import openflow-types { prefix oft; revision-date "2013-07-31"; }


    revision "2013-09-18" {
        description "Initial revision of meter service";
    }

    typedef meter-id {
        type uint32;
    }
    typedef band-id {
    	type uint32;
    }
    
    typedef meter-flags {        
        type bits {
            bit meter-kbps;
            bit meter-pktps;
            bit meter-burst;
            bit meter-stats;
        }        
    }
    
    identity meter-capability {
    	description "Base identity for all the supported meter capabilities/flags";
    }
    identity meter-kbps {
    	base meter-capability;
    	description "Rate value in kb/s (kilo-bit per second)";
    } 
    identity meter-pktps {
    	base meter-capability;
    	description "Rate value in packet/sec.";
    } 
    identity meter-burst {
    	base meter-capability;
    	description "Do burst size.";
    } 
    identity meter-stats {
    	base meter-capability;
    	description "Collect statistics.";
    } 
    
    typedef meter-band-type {
        type bits {
            bit ofpmbt-drop;
            bit ofpmbt-dscp-remark;
            bit ofpmbt-experimenter;               
        }
    }
    
    identity meter-band {
    	description "Base identity for all the band type available";
    }
    identity meter-band-drop {
    	base meter-band;
    	description "Drop packet";
    }
    identity meter-band-dscp-remark {
    	base meter-band;
    	description "Remark DSCP in the IP header";
    }
    identity meter-band-experimenter {
    	base meter-band;
    	description "Experimenter meter band";
    }

    grouping band-type {
        choice band-type {
            case drop {
                leaf drop-rate {
                    description "Rate for dropping packets";
                    type uint32;
                }
                
                leaf drop-burst-size {
                    description "Size of bursts";
                    type uint32;
                }
            }

            case dscp-remark {
                leaf dscp-remark-rate {
                    description "Rate for remarking packets";
                    type uint32;
                }
                
                leaf dscp-remark-burst-size {
                    description "Size of bursts";
                    type uint32;
                }
                
                leaf prec_level {
                    description "Number of drop precedence level to add";
                    type uint8;
                }
            }
            
            case experimenter {
                leaf experimenter-type {
                    description "Meter band type";
                    type meter-band-type;
                }

                leaf experimenter-rate {
                    description "Rate for remarking packets";
                    type uint32;
                }
                
                leaf experimenter-burst-size {
                    description "Size of bursts";
                    type uint32;
                }
                
                leaf experimenter {
                    description "Experimenter id";
                    type uint32;
                }
            }
        }
    }
    
    typedef meter-ref {
        type instance-identifier;
    }
    
    grouping meter {
        
        leaf flags {
           description "Meter configuration flags";
           type meter-flags;        
        }
        
        leaf meter-id {
            description "Meter instance";
            type meter-id;
        }       
        
        leaf barrier {
            description "If true, barrier message is sent";
            type boolean; 
        }
        
        leaf meter-name {
            description "Name of meter instance";
            type string;
        }
        
        leaf container-name {
            description "Name of container";
            type string; 
        }
        
        container meter-band-headers {
            list meter-band-header {
                key "band-id";
                leaf band-id {
                    description "Meter band id";
                    type band-id;
                }
                
                container meter-band-types {
                    leaf flags {
                        description "Meter band flags";
                        type meter-band-type;
                    }
                }
            
                leaf band-rate {
                    description "Rate for this band";
                    type uint32;
                }
        
                leaf band-burst-size {
                    description "Size of bursts";
                    type uint32;
                }
                uses band-type;
            }
        }
    }
    
    grouping meter-statistics {
            
        leaf meter-id {
            type meter-id;
        }
        
        leaf flow-count {
            type yang:counter32;
        }
        
        leaf packet-in-count {
            type yang:counter64;
        } 
        
        leaf byte-in-count {
            type yang:counter64;
        }

        container duration {
            leaf second {
                type yang:counter32;
            }
            leaf nanosecond {
                type yang:counter32;
            }
        }
        
        container meter-band-stats {
            list band-stat {
                key "band-id";
                leaf band-id {
                    type band-id;
                }
            
                leaf packet-band-count {
                    type yang:counter64;
                } 
        
                leaf byte-band-count {
                    type yang:counter64;
                }
            }       
        }
    }

    grouping meter-features {
		            
        leaf max_meter {
            type yang:counter32;
        }
           
    	leaf-list meter-band-supported {
	    	type identityref {
	    		base meter-band;
	    	}
	   	}
        
    	leaf-list meter-capabilities-supported {
	    	type identityref {
	    		base meter-capability;
	    	}
	   	}
        
        leaf max_bands {
            type uint8;
        }
        
        leaf max_color {
            type uint8;
        }
    }

    grouping meter-stats-config-request {
        list meter-stats {
            key "meter-id";         
            leaf meter-id {
                type meter-id;
            }           
        }
    }
    
    grouping meter-statistics-reply {
        list meter-stats {
            key "meter-id";
            uses meter-statistics;
        }
    }
    
    grouping meter-config-stats-reply {
        list meter-config-stats {
            key "meter-id";
            uses meter;
        } 
    }
    
    grouping meter-features-reply {
    	uses meter-features;
    }

    container meter-message {
        uses meter;
        uses ofproto:ofHeader;

        leaf command {
            type oft:meter-mod-command;
        }
    }
    
}