~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to ofproto/ofproto.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    /* OFOPERATION_MODIFY: The old actions, if the actions are changing. */
127
127
    struct ofpact *ofpacts;
128
128
    size_t ofpacts_len;
 
129
    uint32_t meter_id;
129
130
 
130
131
    /* OFOPERATION_DELETE. */
131
132
    enum ofp_flow_removed_reason reason; /* Reason flow was removed. */
196
197
 
197
198
/* OpenFlow. */
198
199
static enum ofperr add_flow(struct ofproto *, struct ofconn *,
199
 
                            const struct ofputil_flow_mod *,
 
200
                            struct ofputil_flow_mod *,
200
201
                            const struct ofp_header *);
201
 
static void delete_flow__(struct rule *, struct ofopgroup *);
202
 
static bool handle_openflow(struct ofconn *, struct ofpbuf *);
 
202
static void delete_flow__(struct rule *, struct ofopgroup *,
 
203
                          enum ofp_flow_removed_reason);
 
204
static bool handle_openflow(struct ofconn *, const struct ofpbuf *);
203
205
static enum ofperr handle_flow_mod__(struct ofproto *, struct ofconn *,
204
 
                                     const struct ofputil_flow_mod *,
 
206
                                     struct ofputil_flow_mod *,
205
207
                                     const struct ofp_header *);
 
208
static void calc_duration(long long int start, long long int now,
 
209
                          uint32_t *sec, uint32_t *nsec);
206
210
 
207
211
/* ofproto. */
208
212
static uint64_t pick_datapath_id(const struct ofproto *);
209
213
static uint64_t pick_fallback_dpid(void);
210
214
static void ofproto_destroy__(struct ofproto *);
211
215
static void update_mtu(struct ofproto *, struct ofport *);
 
216
static void meter_delete(struct ofproto *, uint32_t first, uint32_t last);
212
217
 
213
218
/* unixctl. */
214
219
static void ofproto_unixctl_init(void);
218
223
static size_t n_ofproto_classes;
219
224
static size_t allocated_ofproto_classes;
220
225
 
 
226
unsigned flow_eviction_threshold = OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT;
 
227
enum ofproto_flow_miss_model flow_miss_model = OFPROTO_HANDLE_MISS_AUTO;
 
228
 
221
229
/* Map from datapath name to struct ofproto, for use by unixctl commands. */
222
230
static struct hmap all_ofprotos = HMAP_INITIALIZER(&all_ofprotos);
223
231
 
226
234
 
227
235
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
228
236
 
 
237
/* The default value of true waits for flow restore. */
 
238
static bool flow_restore_wait = true;
 
239
 
229
240
/* Must be called to initialize the ofproto library.
230
241
 *
231
242
 * The caller may pass in 'iface_hints', which contains an shash of
403
414
    hmap_insert(&all_ofprotos, &ofproto->hmap_node,
404
415
                hash_string(ofproto->name, 0));
405
416
    ofproto->datapath_id = 0;
406
 
    ofproto_set_flow_eviction_threshold(ofproto,
407
 
                                        OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT);
408
417
    ofproto->forward_bpdu = false;
409
418
    ofproto->fallback_dpid = pick_fallback_dpid();
410
419
    ofproto->mfr_desc = NULL;
419
428
    ofproto->max_ports = OFPP_MAX;
420
429
    ofproto->tables = NULL;
421
430
    ofproto->n_tables = 0;
 
431
    hindex_init(&ofproto->cookies);
422
432
    list_init(&ofproto->expirable);
423
433
    ofproto->connmgr = connmgr_create(ofproto, datapath_name, datapath_name);
424
434
    ofproto->state = S_OPENFLOW;
436
446
    error = ofproto->ofproto_class->construct(ofproto);
437
447
    if (error) {
438
448
        VLOG_ERR("failed to open datapath %s: %s",
439
 
                 datapath_name, strerror(error));
 
449
                 datapath_name, ovs_strerror(error));
440
450
        ofproto_destroy__(ofproto);
441
451
        return error;
442
452
    }
443
453
 
444
454
    /* The "max_ports" member should have been set by ->construct(ofproto).
445
455
     * Port 0 is not a valid OpenFlow port, so mark that as unavailable. */
446
 
    ofproto->ofp_port_ids = bitmap_allocate(ofproto->max_ports);
 
456
    ofproto->ofp_port_ids = bitmap_allocate(ofp_to_u16(ofproto->max_ports));
447
457
    bitmap_set1(ofproto->ofp_port_ids, 0);
448
458
 
449
459
    /* Check that hidden tables, if any, are at the end. */
458
468
    ofproto->datapath_id = pick_datapath_id(ofproto);
459
469
    init_ports(ofproto);
460
470
 
 
471
    /* Initialize meters table. */
 
472
    if (ofproto->ofproto_class->meter_get_features) {
 
473
        ofproto->ofproto_class->meter_get_features(ofproto,
 
474
                                                   &ofproto->meter_features);
 
475
    } else {
 
476
        memset(&ofproto->meter_features, 0, sizeof ofproto->meter_features);
 
477
    }
 
478
    ofproto->meters = xzalloc((ofproto->meter_features.max_meters + 1)
 
479
                              * sizeof(struct meter *));
 
480
 
461
481
    *ofprotop = ofproto;
462
482
    return 0;
463
483
}
492
512
 * Reserved ports numbered OFPP_MAX and higher are special and not subject to
493
513
 * the 'max_ports' restriction. */
494
514
void
495
 
ofproto_init_max_ports(struct ofproto *ofproto, uint16_t max_ports)
 
515
ofproto_init_max_ports(struct ofproto *ofproto, ofp_port_t max_ports)
496
516
{
497
 
    ovs_assert(max_ports <= OFPP_MAX);
 
517
    ovs_assert(ofp_to_u16(max_ports) <= ofp_to_u16(OFPP_MAX));
498
518
    ofproto->max_ports = max_ports;
499
519
}
500
520
 
561
581
/* Sets the number of flows at which eviction from the kernel flow table
562
582
 * will occur. */
563
583
void
564
 
ofproto_set_flow_eviction_threshold(struct ofproto *ofproto, unsigned threshold)
565
 
{
566
 
    if (threshold < OFPROTO_FLOW_EVICTION_THRESHOLD_MIN) {
567
 
        ofproto->flow_eviction_threshold = OFPROTO_FLOW_EVICTION_THRESHOLD_MIN;
568
 
    } else {
569
 
        ofproto->flow_eviction_threshold = threshold;
570
 
    }
 
584
ofproto_set_flow_eviction_threshold(unsigned threshold)
 
585
{
 
586
    flow_eviction_threshold = MAX(OFPROTO_FLOW_EVICTION_THRESHOLD_MIN,
 
587
                                  threshold);
 
588
}
 
589
 
 
590
/* Sets the path for handling flow misses. */
 
591
void
 
592
ofproto_set_flow_miss_model(unsigned model)
 
593
{
 
594
    flow_miss_model = model;
571
595
}
572
596
 
573
597
/* If forward_bpdu is true, the NORMAL action will forward frames with
640
664
        return oso ? EOPNOTSUPP : 0;
641
665
    }
642
666
}
 
667
 
 
668
int
 
669
ofproto_set_ipfix(struct ofproto *ofproto,
 
670
                  const struct ofproto_ipfix_bridge_exporter_options *bo,
 
671
                  const struct ofproto_ipfix_flow_exporter_options *fo,
 
672
                  size_t n_fo)
 
673
{
 
674
    if (ofproto->ofproto_class->set_ipfix) {
 
675
        return ofproto->ofproto_class->set_ipfix(ofproto, bo, fo, n_fo);
 
676
    } else {
 
677
        return (bo || fo) ? EOPNOTSUPP : 0;
 
678
    }
 
679
}
 
680
 
 
681
void
 
682
ofproto_set_flow_restore_wait(bool flow_restore_wait_db)
 
683
{
 
684
    flow_restore_wait = flow_restore_wait_db;
 
685
}
 
686
 
 
687
bool
 
688
ofproto_get_flow_restore_wait(void)
 
689
{
 
690
    return flow_restore_wait;
 
691
}
 
692
 
643
693
 
644
694
/* Spanning Tree Protocol (STP) configuration. */
645
695
 
678
728
 *
679
729
 * Returns 0 if successful, otherwise a positive errno value.*/
680
730
int
681
 
ofproto_port_set_stp(struct ofproto *ofproto, uint16_t ofp_port,
 
731
ofproto_port_set_stp(struct ofproto *ofproto, ofp_port_t ofp_port,
682
732
                     const struct ofproto_port_stp_settings *s)
683
733
{
684
734
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
699
749
 *
700
750
 * Returns 0 if successful, otherwise a positive errno value.*/
701
751
int
702
 
ofproto_port_get_stp_status(struct ofproto *ofproto, uint16_t ofp_port,
 
752
ofproto_port_get_stp_status(struct ofproto *ofproto, ofp_port_t ofp_port,
703
753
                            struct ofproto_port_stp_status *s)
704
754
{
705
755
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
724
774
 *
725
775
 * Returns 0 if successful, otherwise a positive errno value. */
726
776
int
727
 
ofproto_port_set_queues(struct ofproto *ofproto, uint16_t ofp_port,
 
777
ofproto_port_set_queues(struct ofproto *ofproto, ofp_port_t ofp_port,
728
778
                        const struct ofproto_port_queue *queues,
729
779
                        size_t n_queues)
730
780
{
745
795
 
746
796
/* Clears the CFM configuration from 'ofp_port' on 'ofproto'. */
747
797
void
748
 
ofproto_port_clear_cfm(struct ofproto *ofproto, uint16_t ofp_port)
 
798
ofproto_port_clear_cfm(struct ofproto *ofproto, ofp_port_t ofp_port)
749
799
{
750
800
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
751
801
    if (ofport && ofproto->ofproto_class->set_cfm) {
760
810
 *
761
811
 * This function has no effect if 'ofproto' does not have a port 'ofp_port'. */
762
812
void
763
 
ofproto_port_set_cfm(struct ofproto *ofproto, uint16_t ofp_port,
 
813
ofproto_port_set_cfm(struct ofproto *ofproto, ofp_port_t ofp_port,
764
814
                     const struct cfm_settings *s)
765
815
{
766
816
    struct ofport *ofport;
782
832
    if (error) {
783
833
        VLOG_WARN("%s: CFM configuration on port %"PRIu16" (%s) failed (%s)",
784
834
                  ofproto->name, ofp_port, netdev_get_name(ofport->netdev),
785
 
                  strerror(error));
786
 
    }
 
835
                  ovs_strerror(error));
 
836
    }
 
837
}
 
838
 
 
839
/* Configures BFD on 'ofp_port' in 'ofproto'.  This function has no effect if
 
840
 * 'ofproto' does not have a port 'ofp_port'. */
 
841
void
 
842
ofproto_port_set_bfd(struct ofproto *ofproto, ofp_port_t ofp_port,
 
843
                     const struct smap *cfg)
 
844
{
 
845
    struct ofport *ofport;
 
846
    int error;
 
847
 
 
848
    ofport = ofproto_get_port(ofproto, ofp_port);
 
849
    if (!ofport) {
 
850
        VLOG_WARN("%s: cannot configure bfd on nonexistent port %"PRIu16,
 
851
                  ofproto->name, ofp_port);
 
852
        return;
 
853
    }
 
854
 
 
855
    error = (ofproto->ofproto_class->set_bfd
 
856
             ? ofproto->ofproto_class->set_bfd(ofport, cfg)
 
857
             : EOPNOTSUPP);
 
858
    if (error) {
 
859
        VLOG_WARN("%s: bfd configuration on port %"PRIu16" (%s) failed (%s)",
 
860
                  ofproto->name, ofp_port, netdev_get_name(ofport->netdev),
 
861
                  ovs_strerror(error));
 
862
    }
 
863
}
 
864
 
 
865
/* Populates 'status' with key value pairs indicating the status of the BFD
 
866
 * session on 'ofp_port'.  This information is intended to be populated in the
 
867
 * OVS database.  Has no effect if 'ofp_port' is not na OpenFlow port in
 
868
 * 'ofproto'. */
 
869
int
 
870
ofproto_port_get_bfd_status(struct ofproto *ofproto, ofp_port_t ofp_port,
 
871
                            struct smap *status)
 
872
{
 
873
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
 
874
    return (ofport && ofproto->ofproto_class->get_bfd_status
 
875
            ? ofproto->ofproto_class->get_bfd_status(ofport, status)
 
876
            : EOPNOTSUPP);
787
877
}
788
878
 
789
879
/* Checks the status of LACP negotiation for 'ofp_port' within ofproto.
791
881
 * 0 if LACP partner information is not current (generally indicating a
792
882
 * connectivity problem), or -1 if LACP is not enabled on 'ofp_port'. */
793
883
int
794
 
ofproto_port_is_lacp_current(struct ofproto *ofproto, uint16_t ofp_port)
 
884
ofproto_port_is_lacp_current(struct ofproto *ofproto, ofp_port_t ofp_port)
795
885
{
796
886
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
797
887
    return (ofport && ofproto->ofproto_class->port_is_lacp_current
996
1086
    ovs_assert(list_is_empty(&ofproto->pending));
997
1087
    ovs_assert(!ofproto->n_pending);
998
1088
 
 
1089
    if (ofproto->meters) {
 
1090
        meter_delete(ofproto, 1, ofproto->meter_features.max_meters);
 
1091
        free(ofproto->meters);
 
1092
    }
 
1093
 
999
1094
    connmgr_destroy(ofproto->connmgr);
1000
1095
 
1001
1096
    hmap_remove(&all_ofprotos, &ofproto->hmap_node);
1079
1174
    error = class->type_run ? class->type_run(datapath_type) : 0;
1080
1175
    if (error && error != EAGAIN) {
1081
1176
        VLOG_ERR_RL(&rl, "%s: type_run failed (%s)",
1082
 
                    datapath_type, strerror(error));
 
1177
                    datapath_type, ovs_strerror(error));
1083
1178
    }
1084
1179
    return error;
1085
1180
}
1096
1191
    error = class->type_run_fast ? class->type_run_fast(datapath_type) : 0;
1097
1192
    if (error && error != EAGAIN) {
1098
1193
        VLOG_ERR_RL(&rl, "%s: type_run_fast failed (%s)",
1099
 
                    datapath_type, strerror(error));
 
1194
                    datapath_type, ovs_strerror(error));
1100
1195
    }
1101
1196
    return error;
1102
1197
}
1124
1219
 
1125
1220
    error = p->ofproto_class->run(p);
1126
1221
    if (error && error != EAGAIN) {
1127
 
        VLOG_ERR_RL(&rl, "%s: run failed (%s)", p->name, strerror(error));
 
1222
        VLOG_ERR_RL(&rl, "%s: run failed (%s)", p->name, ovs_strerror(error));
1128
1223
    }
1129
1224
 
1130
1225
    if (p->ofproto_class->port_poll) {
1234
1329
    error = p->ofproto_class->run_fast ? p->ofproto_class->run_fast(p) : 0;
1235
1330
    if (error && error != EAGAIN) {
1236
1331
        VLOG_ERR_RL(&rl, "%s: fastpath run failed (%s)",
1237
 
                    p->name, strerror(error));
 
1332
                    p->name, ovs_strerror(error));
1238
1333
    }
1239
1334
    return error;
1240
1335
}
1428
1523
 * 'ofp_portp' is non-null). */
1429
1524
int
1430
1525
ofproto_port_add(struct ofproto *ofproto, struct netdev *netdev,
1431
 
                 uint16_t *ofp_portp)
 
1526
                 ofp_port_t *ofp_portp)
1432
1527
{
1433
 
    uint16_t ofp_port = ofp_portp ? *ofp_portp : OFPP_NONE;
 
1528
    ofp_port_t ofp_port = ofp_portp ? *ofp_portp : OFPP_NONE;
1434
1529
    int error;
1435
1530
 
1436
1531
    error = ofproto->ofproto_class->port_add(ofproto, netdev);
1437
1532
    if (!error) {
1438
1533
        const char *netdev_name = netdev_get_name(netdev);
1439
1534
 
1440
 
        simap_put(&ofproto->ofp_requests, netdev_name, ofp_port);
 
1535
        simap_put(&ofproto->ofp_requests, netdev_name,
 
1536
                  ofp_to_u16(ofp_port));
1441
1537
        update_port(ofproto, netdev_name);
1442
1538
    }
1443
1539
    if (ofp_portp) {
1473
1569
/* Deletes port number 'ofp_port' from the datapath for 'ofproto'.
1474
1570
 * Returns 0 if successful, otherwise a positive errno. */
1475
1571
int
1476
 
ofproto_port_del(struct ofproto *ofproto, uint16_t ofp_port)
 
1572
ofproto_port_del(struct ofproto *ofproto, ofp_port_t ofp_port)
1477
1573
{
1478
1574
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
1479
1575
    const char *name = ofport ? netdev_get_name(ofport->netdev) : "<unknown>";
1539
1635
 *
1540
1636
 * This is a helper function for in-band control and fail-open. */
1541
1637
int
1542
 
ofproto_flow_mod(struct ofproto *ofproto, const struct ofputil_flow_mod *fm)
 
1638
ofproto_flow_mod(struct ofproto *ofproto, struct ofputil_flow_mod *fm)
1543
1639
{
1544
1640
    return handle_flow_mod__(ofproto, NULL, fm, NULL);
1545
1641
}
1610
1706
    sset_destroy(&devnames);
1611
1707
}
1612
1708
 
1613
 
static uint16_t
 
1709
static ofp_port_t
1614
1710
alloc_ofp_port(struct ofproto *ofproto, const char *netdev_name)
1615
1711
{
1616
 
    uint16_t ofp_port;
1617
 
    uint16_t end_port_no = ofproto->alloc_port_no;
1618
 
 
1619
 
    ofp_port = simap_get(&ofproto->ofp_requests, netdev_name);
1620
 
    ofp_port = ofp_port ? ofp_port : OFPP_NONE;
1621
 
 
1622
 
    if (ofp_port >= ofproto->max_ports
1623
 
            || bitmap_is_set(ofproto->ofp_port_ids, ofp_port)) {
 
1712
    uint16_t max_ports = ofp_to_u16(ofproto->max_ports);
 
1713
    uint16_t port_idx;
 
1714
 
 
1715
    port_idx = simap_get(&ofproto->ofp_requests, netdev_name);
 
1716
    if (!port_idx) {
 
1717
        port_idx = UINT16_MAX;
 
1718
    }
 
1719
 
 
1720
    if (port_idx >= max_ports
 
1721
        || bitmap_is_set(ofproto->ofp_port_ids, port_idx)) {
 
1722
        uint16_t end_port_no = ofp_to_u16(ofproto->alloc_port_no);
 
1723
        uint16_t alloc_port_no = end_port_no;
 
1724
 
1624
1725
        /* Search for a free OpenFlow port number.  We try not to
1625
1726
         * immediately reuse them to prevent problems due to old
1626
1727
         * flows. */
1627
1728
        for (;;) {
1628
 
            if (++ofproto->alloc_port_no >= ofproto->max_ports) {
1629
 
                ofproto->alloc_port_no = 0;
 
1729
            if (++alloc_port_no >= max_ports) {
 
1730
                alloc_port_no = 0;
1630
1731
            }
1631
 
            if (!bitmap_is_set(ofproto->ofp_port_ids,
1632
 
                               ofproto->alloc_port_no)) {
1633
 
                ofp_port = ofproto->alloc_port_no;
 
1732
            if (!bitmap_is_set(ofproto->ofp_port_ids, alloc_port_no)) {
 
1733
                port_idx = alloc_port_no;
 
1734
                ofproto->alloc_port_no = u16_to_ofp(alloc_port_no);
1634
1735
                break;
1635
1736
            }
1636
 
            if (ofproto->alloc_port_no == end_port_no) {
 
1737
            if (alloc_port_no == end_port_no) {
1637
1738
                return OFPP_NONE;
1638
1739
            }
1639
1740
        }
1640
1741
    }
1641
 
    bitmap_set1(ofproto->ofp_port_ids, ofp_port);
1642
 
    return ofp_port;
 
1742
    bitmap_set1(ofproto->ofp_port_ids, port_idx);
 
1743
    return u16_to_ofp(port_idx);
1643
1744
}
1644
1745
 
1645
1746
static void
1646
 
dealloc_ofp_port(const struct ofproto *ofproto, uint16_t ofp_port)
 
1747
dealloc_ofp_port(const struct ofproto *ofproto, ofp_port_t ofp_port)
1647
1748
{
1648
 
    if (ofp_port < ofproto->max_ports) {
1649
 
        bitmap_set0(ofproto->ofp_port_ids, ofp_port);
 
1749
    if (ofp_to_u16(ofp_port) < ofp_to_u16(ofproto->max_ports)) {
 
1750
        bitmap_set0(ofproto->ofp_port_ids, ofp_to_u16(ofp_port));
1650
1751
    }
1651
1752
}
1652
1753
 
1668
1769
                     "cannot be opened (%s)",
1669
1770
                     ofproto->name,
1670
1771
                     ofproto_port->name, ofproto_port->ofp_port,
1671
 
                     ofproto_port->name, strerror(error));
 
1772
                     ofproto_port->name, ovs_strerror(error));
1672
1773
        return NULL;
1673
1774
    }
1674
1775
 
1734
1835
    ofport->change_seq = netdev_change_seq(netdev);
1735
1836
    ofport->pp = *pp;
1736
1837
    ofport->ofp_port = pp->port_no;
 
1838
    ofport->created = time_msec();
1737
1839
 
1738
1840
    /* Add port to 'p'. */
1739
 
    hmap_insert(&p->ports, &ofport->hmap_node, hash_int(ofport->ofp_port, 0));
 
1841
    hmap_insert(&p->ports, &ofport->hmap_node,
 
1842
                hash_ofp_port(ofport->ofp_port));
1740
1843
    shash_add(&p->port_by_name, netdev_name, ofport);
1741
1844
 
1742
1845
    update_mtu(p, ofport);
1751
1854
 
1752
1855
error:
1753
1856
    VLOG_WARN_RL(&rl, "%s: could not add port %s (%s)",
1754
 
                 p->name, netdev_name, strerror(error));
 
1857
                 p->name, netdev_name, ovs_strerror(error));
1755
1858
    if (ofport) {
1756
1859
        ofport_destroy__(ofport);
1757
1860
    } else {
1812
1915
}
1813
1916
 
1814
1917
void
1815
 
ofproto_port_unregister(struct ofproto *ofproto, uint16_t ofp_port)
 
1918
ofproto_port_unregister(struct ofproto *ofproto, ofp_port_t ofp_port)
1816
1919
{
1817
1920
    struct ofport *port = ofproto_get_port(ofproto, ofp_port);
1818
1921
    if (port) {
1856
1959
}
1857
1960
 
1858
1961
struct ofport *
1859
 
ofproto_get_port(const struct ofproto *ofproto, uint16_t ofp_port)
 
1962
ofproto_get_port(const struct ofproto *ofproto, ofp_port_t ofp_port)
1860
1963
{
1861
1964
    struct ofport *port;
1862
1965
 
1863
 
    HMAP_FOR_EACH_IN_BUCKET (port, hmap_node,
1864
 
                             hash_int(ofp_port, 0), &ofproto->ports) {
 
1966
    HMAP_FOR_EACH_IN_BUCKET (port, hmap_node, hash_ofp_port(ofp_port),
 
1967
                             &ofproto->ports) {
1865
1968
        if (port->ofp_port == ofp_port) {
1866
1969
            return port;
1867
1970
        }
1898
2001
    netdev = (!ofproto_port_query_by_name(ofproto, name, &ofproto_port)
1899
2002
              ? ofport_open(ofproto, &ofproto_port, &pp)
1900
2003
              : NULL);
 
2004
 
1901
2005
    if (netdev) {
1902
2006
        port = ofproto_get_port(ofproto, ofproto_port.ofp_port);
1903
2007
        if (port && !strcmp(netdev_get_name(port->netdev), name)) {
1959
2063
            node = shash_find(&init_ofp_ports, name);
1960
2064
            if (node) {
1961
2065
                const struct iface_hint *iface_hint = node->data;
1962
 
                simap_put(&p->ofp_requests, name, iface_hint->ofp_port);
 
2066
                simap_put(&p->ofp_requests, name,
 
2067
                          ofp_to_u16(iface_hint->ofp_port));
1963
2068
            }
1964
2069
 
1965
2070
            netdev = ofport_open(p, &ofproto_port, &pp);
2083
2188
/* Returns true if 'rule' has an OpenFlow OFPAT_OUTPUT or OFPAT_ENQUEUE action
2084
2189
 * that outputs to 'port' (output to OFPP_FLOOD and OFPP_ALL doesn't count). */
2085
2190
bool
2086
 
ofproto_rule_has_out_port(const struct rule *rule, uint16_t port)
 
2191
ofproto_rule_has_out_port(const struct rule *rule, ofp_port_t port)
2087
2192
{
2088
2193
    return (port == OFPP_ANY
2089
2194
            || ofpacts_output_to_port(rule->ofpacts, rule->ofpacts_len, port));
2092
2197
/* Returns true if a rule related to 'op' has an OpenFlow OFPAT_OUTPUT or
2093
2198
 * OFPAT_ENQUEUE action that outputs to 'out_port'. */
2094
2199
bool
2095
 
ofoperation_has_out_port(const struct ofoperation *op, uint16_t out_port)
 
2200
ofoperation_has_out_port(const struct ofoperation *op, ofp_port_t out_port)
2096
2201
{
2097
2202
    if (ofproto_rule_has_out_port(op->rule, out_port)) {
2098
2203
        return true;
2121
2226
 *
2122
2227
 * Takes ownership of 'packet'. */
2123
2228
static int
2124
 
rule_execute(struct rule *rule, uint16_t in_port, struct ofpbuf *packet)
 
2229
rule_execute(struct rule *rule, ofp_port_t in_port, struct ofpbuf *packet)
2125
2230
{
2126
2231
    struct flow flow;
 
2232
    union flow_in_port in_port_;
2127
2233
 
2128
2234
    ovs_assert(ofpbuf_headroom(packet) >= sizeof(struct ofp10_packet_in));
2129
2235
 
2130
 
    flow_extract(packet, 0, 0, NULL, in_port, &flow);
 
2236
    in_port_.ofp_port = in_port;
 
2237
    flow_extract(packet, 0, 0, NULL, &in_port_, &flow);
2131
2238
    return rule->ofproto->ofproto_class->rule_execute(rule, &flow, packet);
2132
2239
}
2133
2240
 
2238
2345
    uint16_t flags = ntohs(osc->flags);
2239
2346
 
2240
2347
    if (ofconn_get_type(ofconn) != OFCONN_PRIMARY
2241
 
        || ofconn_get_role(ofconn) != NX_ROLE_SLAVE) {
 
2348
        || ofconn_get_role(ofconn) != OFPCR12_ROLE_SLAVE) {
2242
2349
        enum ofp_config_flags cur = ofproto->frag_handling;
2243
2350
        enum ofp_config_flags next = flags & OFPC_FRAG_MASK;
2244
2351
 
2272
2379
reject_slave_controller(struct ofconn *ofconn)
2273
2380
{
2274
2381
    if (ofconn_get_type(ofconn) == OFCONN_PRIMARY
2275
 
        && ofconn_get_role(ofconn) == NX_ROLE_SLAVE) {
 
2382
        && ofconn_get_role(ofconn) == OFPCR12_ROLE_SLAVE) {
2276
2383
        return OFPERR_OFPBRC_EPERM;
2277
2384
    } else {
2278
2385
        return 0;
2279
2386
    }
2280
2387
}
2281
2388
 
 
2389
/* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
 
2390
 * 'ofpacts'.  If found, returns its meter ID; if not, returns 0.
 
2391
 *
 
2392
 * This function relies on the order of 'ofpacts' being correct (as checked by
 
2393
 * ofpacts_verify()). */
 
2394
static uint32_t
 
2395
find_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
 
2396
{
 
2397
    const struct ofpact *a;
 
2398
 
 
2399
    OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
 
2400
        enum ovs_instruction_type inst;
 
2401
 
 
2402
        inst = ovs_instruction_type_from_ofpact_type(a->type);
 
2403
        if (a->type == OFPACT_METER) {
 
2404
            return ofpact_get_METER(a)->meter_id;
 
2405
        } else if (inst > OVSINST_OFPIT13_METER) {
 
2406
            break;
 
2407
        }
 
2408
    }
 
2409
 
 
2410
    return 0;
 
2411
}
 
2412
 
 
2413
/* Checks that the 'ofpacts_len' bytes of actions in 'ofpacts' are appropriate
 
2414
 * for a packet with the prerequisites satisfied by 'flow' in table 'table_id'.
 
2415
 * 'flow' may be temporarily modified, but is restored at return.
 
2416
 */
 
2417
static enum ofperr
 
2418
ofproto_check_ofpacts(struct ofproto *ofproto,
 
2419
                      const struct ofpact ofpacts[], size_t ofpacts_len,
 
2420
                      struct flow *flow, uint8_t table_id)
 
2421
{
 
2422
    enum ofperr error;
 
2423
    uint32_t mid;
 
2424
 
 
2425
    error = ofpacts_check(ofpacts, ofpacts_len, flow, ofproto->max_ports,
 
2426
                          table_id);
 
2427
    if (error) {
 
2428
        return error;
 
2429
    }
 
2430
 
 
2431
    mid = find_meter(ofpacts, ofpacts_len);
 
2432
    if (mid && ofproto_get_provider_meter_id(ofproto, mid) == UINT32_MAX) {
 
2433
        return OFPERR_OFPMMFC_INVALID_METER;
 
2434
    }
 
2435
    return 0;
 
2436
}
 
2437
 
2282
2438
static enum ofperr
2283
2439
handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh)
2284
2440
{
2288
2444
    uint64_t ofpacts_stub[1024 / 8];
2289
2445
    struct ofpbuf ofpacts;
2290
2446
    struct flow flow;
 
2447
    union flow_in_port in_port_;
2291
2448
    enum ofperr error;
2292
2449
 
2293
2450
    COVERAGE_INC(ofproto_packet_out);
2303
2460
    if (error) {
2304
2461
        goto exit_free_ofpacts;
2305
2462
    }
2306
 
    if (po.in_port >= p->max_ports && po.in_port < OFPP_MAX) {
 
2463
    if (ofp_to_u16(po.in_port) >= ofp_to_u16(p->max_ports)
 
2464
        && ofp_to_u16(po.in_port) < ofp_to_u16(OFPP_MAX)) {
2307
2465
        error = OFPERR_OFPBRC_BAD_PORT;
2308
2466
        goto exit_free_ofpacts;
2309
2467
    }
2321
2479
    }
2322
2480
 
2323
2481
    /* Verify actions against packet, then send packet if successful. */
2324
 
    flow_extract(payload, 0, 0, NULL, po.in_port, &flow);
2325
 
    error = ofpacts_check(po.ofpacts, po.ofpacts_len, &flow, p->max_ports);
 
2482
    in_port_.ofp_port = po.in_port;
 
2483
    flow_extract(payload, 0, 0, NULL, &in_port_, &flow);
 
2484
    error = ofproto_check_ofpacts(p, po.ofpacts, po.ofpacts_len, &flow, 0);
2326
2485
    if (!error) {
2327
2486
        error = p->ofproto_class->packet_out(p, payload, &flow,
2328
2487
                                             po.ofpacts, po.ofpacts_len);
2346
2505
    toggle = (config ^ port->pp.config) & mask;
2347
2506
    if (toggle & OFPUTIL_PC_PORT_DOWN) {
2348
2507
        if (config & OFPUTIL_PC_PORT_DOWN) {
2349
 
            netdev_turn_flags_off(port->netdev, NETDEV_UP, true);
 
2508
            netdev_turn_flags_off(port->netdev, NETDEV_UP, NULL);
2350
2509
        } else {
2351
 
            netdev_turn_flags_on(port->netdev, NETDEV_UP, true);
 
2510
            netdev_turn_flags_on(port->netdev, NETDEV_UP, NULL);
2352
2511
        }
2353
2512
        toggle &= ~OFPUTIL_PC_PORT_DOWN;
2354
2513
    }
2491
2650
{
2492
2651
    struct ofputil_port_stats ops = { .port_no = port->pp.port_no };
2493
2652
 
 
2653
    calc_duration(port->created, time_msec(),
 
2654
                  &ops.duration_sec, &ops.duration_nsec);
 
2655
 
2494
2656
    /* Intentionally ignore return value, since errors will set
2495
2657
     * 'stats' to all-1s, which is correct for OpenFlow, and
2496
2658
     * netdev_get_stats() will log errors. */
2506
2668
    struct ofproto *p = ofconn_get_ofproto(ofconn);
2507
2669
    struct ofport *port;
2508
2670
    struct list replies;
2509
 
    uint16_t port_no;
 
2671
    ofp_port_t port_no;
2510
2672
    enum ofperr error;
2511
2673
 
2512
2674
    error = ofputil_decode_port_stats_request(request, &port_no);
2550
2712
    return 0;
2551
2713
}
2552
2714
 
2553
 
static void
2554
 
calc_flow_duration__(long long int start, long long int now,
2555
 
                     uint32_t *sec, uint32_t *nsec)
 
2715
static uint32_t
 
2716
hash_cookie(ovs_be64 cookie)
 
2717
{
 
2718
    return hash_2words((OVS_FORCE uint64_t)cookie >> 32,
 
2719
                       (OVS_FORCE uint64_t)cookie);
 
2720
}
 
2721
 
 
2722
static void
 
2723
cookies_insert(struct ofproto *ofproto, struct rule *rule)
 
2724
{
 
2725
    hindex_insert(&ofproto->cookies, &rule->cookie_node,
 
2726
                  hash_cookie(rule->flow_cookie));
 
2727
}
 
2728
 
 
2729
static void
 
2730
cookies_remove(struct ofproto *ofproto, struct rule *rule)
 
2731
{
 
2732
    hindex_remove(&ofproto->cookies, &rule->cookie_node);
 
2733
}
 
2734
 
 
2735
static void
 
2736
ofproto_rule_change_cookie(struct ofproto *ofproto, struct rule *rule,
 
2737
                           ovs_be64 new_cookie)
 
2738
{
 
2739
    if (new_cookie != rule->flow_cookie) {
 
2740
        cookies_remove(ofproto, rule);
 
2741
 
 
2742
        rule->flow_cookie = new_cookie;
 
2743
 
 
2744
        cookies_insert(ofproto, rule);
 
2745
    }
 
2746
}
 
2747
 
 
2748
static void
 
2749
calc_duration(long long int start, long long int now,
 
2750
              uint32_t *sec, uint32_t *nsec)
2556
2751
{
2557
2752
    long long int msecs = now - start;
2558
2753
    *sec = msecs / 1000;
2642
2837
collect_rules_loose(struct ofproto *ofproto, uint8_t table_id,
2643
2838
                    const struct match *match,
2644
2839
                    ovs_be64 cookie, ovs_be64 cookie_mask,
2645
 
                    uint16_t out_port, struct list *rules)
 
2840
                    ofp_port_t out_port, struct list *rules)
2646
2841
{
2647
2842
    struct oftable *table;
2648
2843
    struct cls_rule cr;
2655
2850
 
2656
2851
    list_init(rules);
2657
2852
    cls_rule_init(&cr, match, 0);
 
2853
 
 
2854
    if (cookie_mask == htonll(UINT64_MAX)) {
 
2855
        struct rule *rule;
 
2856
 
 
2857
        HINDEX_FOR_EACH_WITH_HASH (rule, cookie_node, hash_cookie(cookie),
 
2858
                                   &ofproto->cookies) {
 
2859
            if (table_id != rule->table_id && table_id != 0xff) {
 
2860
                continue;
 
2861
            }
 
2862
            if (ofproto_rule_is_hidden(rule)) {
 
2863
                continue;
 
2864
            }
 
2865
            if (cls_rule_is_loose_match(&rule->cr, &cr.match)) {
 
2866
                if (rule->pending) {
 
2867
                    error = OFPROTO_POSTPONE;
 
2868
                    goto exit;
 
2869
                }
 
2870
                if (rule->flow_cookie == cookie /* Hash collisions possible. */
 
2871
                    && ofproto_rule_has_out_port(rule, out_port)) {
 
2872
                    list_push_back(rules, &rule->ofproto_node);
 
2873
                }
 
2874
            }
 
2875
        }
 
2876
        goto exit;
 
2877
    }
 
2878
 
2658
2879
    FOR_EACH_MATCHING_TABLE (table, table_id, ofproto) {
2659
2880
        struct cls_cursor cursor;
2660
2881
        struct rule *rule;
2693
2914
collect_rules_strict(struct ofproto *ofproto, uint8_t table_id,
2694
2915
                     const struct match *match, unsigned int priority,
2695
2916
                     ovs_be64 cookie, ovs_be64 cookie_mask,
2696
 
                     uint16_t out_port, struct list *rules)
 
2917
                     ofp_port_t out_port, struct list *rules)
2697
2918
{
2698
2919
    struct oftable *table;
2699
2920
    struct cls_rule cr;
2706
2927
 
2707
2928
    list_init(rules);
2708
2929
    cls_rule_init(&cr, match, priority);
 
2930
 
 
2931
    if (cookie_mask == htonll(UINT64_MAX)) {
 
2932
        struct rule *rule;
 
2933
 
 
2934
        HINDEX_FOR_EACH_WITH_HASH (rule, cookie_node, hash_cookie(cookie),
 
2935
                                   &ofproto->cookies) {
 
2936
            if (table_id != rule->table_id && table_id != 0xff) {
 
2937
                continue;
 
2938
            }
 
2939
            if (ofproto_rule_is_hidden(rule)) {
 
2940
                continue;
 
2941
            }
 
2942
            if (cls_rule_equal(&rule->cr, &cr)) {
 
2943
                if (rule->pending) {
 
2944
                    error = OFPROTO_POSTPONE;
 
2945
                    goto exit;
 
2946
                }
 
2947
                if (rule->flow_cookie == cookie /* Hash collisions possible. */
 
2948
                    && ofproto_rule_has_out_port(rule, out_port)) {
 
2949
                    list_push_back(rules, &rule->ofproto_node);
 
2950
                }
 
2951
            }
 
2952
        }
 
2953
        goto exit;
 
2954
    }
 
2955
 
2709
2956
    FOR_EACH_MATCHING_TABLE (table, table_id, ofproto) {
2710
2957
        struct rule *rule;
2711
2958
 
2771
3018
        fs.priority = rule->cr.priority;
2772
3019
        fs.cookie = rule->flow_cookie;
2773
3020
        fs.table_id = rule->table_id;
2774
 
        calc_flow_duration__(rule->created, now, &fs.duration_sec,
2775
 
                             &fs.duration_nsec);
 
3021
        calc_duration(rule->created, now, &fs.duration_sec, &fs.duration_nsec);
2776
3022
        fs.idle_timeout = rule->idle_timeout;
2777
3023
        fs.hard_timeout = rule->hard_timeout;
2778
3024
        fs.idle_age = age_secs(now - rule->used);
2843
3089
    ofproto->ofproto_class->get_netflow_ids(ofproto, engine_type, engine_id);
2844
3090
}
2845
3091
 
2846
 
/* Checks the fault status of CFM for 'ofp_port' within 'ofproto'.  Returns a
2847
 
 * bitmask of 'cfm_fault_reason's to indicate a CFM fault (generally
2848
 
 * indicating a connectivity problem).  Returns zero if CFM is not faulted,
2849
 
 * and -1 if CFM is not enabled on 'ofp_port'. */
2850
 
int
2851
 
ofproto_port_get_cfm_fault(const struct ofproto *ofproto, uint16_t ofp_port)
2852
 
{
2853
 
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
2854
 
    return (ofport && ofproto->ofproto_class->get_cfm_fault
2855
 
            ? ofproto->ofproto_class->get_cfm_fault(ofport)
2856
 
            : -1);
2857
 
}
2858
 
 
2859
 
/* Checks the operational status reported by the remote CFM endpoint of
2860
 
 * 'ofp_port'  Returns 1 if operationally up, 0 if operationally down, and -1
2861
 
 * if CFM is not enabled on 'ofp_port' or does not support operational status.
2862
 
 */
2863
 
int
2864
 
ofproto_port_get_cfm_opup(const struct ofproto *ofproto, uint16_t ofp_port)
2865
 
{
2866
 
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
2867
 
    return (ofport && ofproto->ofproto_class->get_cfm_opup
2868
 
            ? ofproto->ofproto_class->get_cfm_opup(ofport)
2869
 
            : -1);
2870
 
}
2871
 
 
2872
 
/* Gets the MPIDs of the remote maintenance points broadcasting to 'ofp_port'
2873
 
 * within 'ofproto'.  Populates 'rmps' with an array of MPIDs owned by
2874
 
 * 'ofproto', and 'n_rmps' with the number of MPIDs in 'rmps'.  Returns a
2875
 
 * number less than 0 if CFM is not enabled on 'ofp_port'. */
2876
 
int
2877
 
ofproto_port_get_cfm_remote_mpids(const struct ofproto *ofproto,
2878
 
                                  uint16_t ofp_port, const uint64_t **rmps,
2879
 
                                  size_t *n_rmps)
2880
 
{
2881
 
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
2882
 
 
2883
 
    *rmps = NULL;
2884
 
    *n_rmps = 0;
2885
 
    return (ofport && ofproto->ofproto_class->get_cfm_remote_mpids
2886
 
            ? ofproto->ofproto_class->get_cfm_remote_mpids(ofport, rmps,
2887
 
                                                           n_rmps)
2888
 
            : -1);
2889
 
}
2890
 
 
2891
 
/* Checks the health of the CFM for 'ofp_port' within 'ofproto'.  Returns an
2892
 
 * integer value between 0 and 100 to indicate the health of the port as a
2893
 
 * percentage which is the average of cfm health of all the remote_mpids or
2894
 
 * returns -1 if CFM is not enabled on 'ofport'. */
2895
 
int
2896
 
ofproto_port_get_cfm_health(const struct ofproto *ofproto, uint16_t ofp_port)
2897
 
{
2898
 
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
2899
 
    return (ofport && ofproto->ofproto_class->get_cfm_health
2900
 
            ? ofproto->ofproto_class->get_cfm_health(ofport)
2901
 
            : -1);
 
3092
/* Checks the status of CFM configured on 'ofp_port' within 'ofproto'.  Returns
 
3093
 * true if the port's CFM status was successfully stored into '*status'.
 
3094
 * Returns false if the port did not have CFM configured, in which case
 
3095
 * '*status' is indeterminate.
 
3096
 *
 
3097
 * The caller must provide and owns '*status', and must free 'status->rmps'. */
 
3098
bool
 
3099
ofproto_port_get_cfm_status(const struct ofproto *ofproto, ofp_port_t ofp_port,
 
3100
                            struct ofproto_cfm_status *status)
 
3101
{
 
3102
    struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
 
3103
    return (ofport
 
3104
            && ofproto->ofproto_class->get_cfm_status
 
3105
            && ofproto->ofproto_class->get_cfm_status(ofport, status));
2902
3106
}
2903
3107
 
2904
3108
static enum ofperr
3086
3290
 * if any. */
3087
3291
static enum ofperr
3088
3292
add_flow(struct ofproto *ofproto, struct ofconn *ofconn,
3089
 
         const struct ofputil_flow_mod *fm, const struct ofp_header *request)
 
3293
         struct ofputil_flow_mod *fm, const struct ofp_header *request)
3090
3294
{
3091
3295
    struct oftable *table;
3092
3296
    struct ofopgroup *group;
3125
3329
        return OFPERR_OFPBRC_EPERM;
3126
3330
    }
3127
3331
 
 
3332
    /* Verify actions. */
 
3333
    error = ofproto_check_ofpacts(ofproto, fm->ofpacts, fm->ofpacts_len,
 
3334
                                  &fm->match.flow, table_id);
 
3335
    if (error) {
 
3336
        return error;
 
3337
    }
 
3338
 
3128
3339
    /* Allocate new rule and initialize classifier rule. */
3129
3340
    rule = ofproto->ofproto_class->rule_alloc();
3130
3341
    if (!rule) {
3131
3342
        VLOG_WARN_RL(&rl, "%s: failed to create rule (%s)",
3132
 
                     ofproto->name, strerror(error));
 
3343
                     ofproto->name, ovs_strerror(error));
3133
3344
        return ENOMEM;
3134
3345
    }
3135
3346
    cls_rule_init(&rule->cr, &fm->match, fm->priority);
3163
3374
       and OFPFF13_NO_BYT_COUNTS */
3164
3375
    rule->ofpacts = xmemdup(fm->ofpacts, fm->ofpacts_len);
3165
3376
    rule->ofpacts_len = fm->ofpacts_len;
 
3377
    rule->meter_id = find_meter(rule->ofpacts, rule->ofpacts_len);
 
3378
    list_init(&rule->meter_list_node);
3166
3379
    rule->evictable = true;
3167
3380
    rule->eviction_group = NULL;
3168
3381
    list_init(&rule->expirable);
3208
3421
            op->group->n_running--;
3209
3422
            ofoperation_destroy(rule->pending);
3210
3423
        } else if (evict) {
3211
 
            delete_flow__(evict, group);
 
3424
            delete_flow__(evict, group, OFPRR_EVICTION);
3212
3425
        }
3213
3426
        ofopgroup_submit(group);
3214
3427
    }
3233
3446
 * Returns 0 on success, otherwise an OpenFlow error code. */
3234
3447
static enum ofperr
3235
3448
modify_flows__(struct ofproto *ofproto, struct ofconn *ofconn,
3236
 
               const struct ofputil_flow_mod *fm,
3237
 
               const struct ofp_header *request, struct list *rules)
 
3449
               struct ofputil_flow_mod *fm, const struct ofp_header *request,
 
3450
               struct list *rules)
3238
3451
{
3239
3452
    struct ofopgroup *group;
3240
3453
    struct rule *rule;
3245
3458
    LIST_FOR_EACH (rule, ofproto_node, rules) {
3246
3459
        struct ofoperation *op;
3247
3460
        bool actions_changed;
3248
 
        ovs_be64 new_cookie;
3249
3461
 
3250
3462
        /* FIXME: Implement OFPFF12_RESET_COUNTS */
3251
3463
 
3256
3468
            continue;
3257
3469
        }
3258
3470
 
 
3471
        /* Verify actions. */
 
3472
        error = ofpacts_check(fm->ofpacts, fm->ofpacts_len, &fm->match.flow,
 
3473
                              ofproto->max_ports, rule->table_id);
 
3474
        if (error) {
 
3475
            return error;
 
3476
        }
 
3477
 
3259
3478
        actions_changed = !ofpacts_equal(fm->ofpacts, fm->ofpacts_len,
3260
3479
                                         rule->ofpacts, rule->ofpacts_len);
3261
 
        new_cookie = (fm->new_cookie != htonll(UINT64_MAX)
3262
 
                      ? fm->new_cookie
3263
 
                      : rule->flow_cookie);
3264
3480
 
3265
3481
        op = ofoperation_create(group, rule, OFOPERATION_MODIFY, 0);
3266
 
        rule->flow_cookie = new_cookie;
 
3482
 
 
3483
        if (fm->modify_cookie && fm->new_cookie != htonll(UINT64_MAX)) {
 
3484
            ofproto_rule_change_cookie(ofproto, rule, fm->new_cookie);
 
3485
        }
3267
3486
        if (actions_changed) {
3268
3487
            op->ofpacts = rule->ofpacts;
3269
3488
            op->ofpacts_len = rule->ofpacts_len;
 
3489
            op->meter_id = rule->meter_id;
3270
3490
            rule->ofpacts = xmemdup(fm->ofpacts, fm->ofpacts_len);
3271
3491
            rule->ofpacts_len = fm->ofpacts_len;
 
3492
            rule->meter_id = find_meter(rule->ofpacts, rule->ofpacts_len);
3272
3493
            rule->ofproto->ofproto_class->rule_modify_actions(rule);
3273
3494
        } else {
3274
3495
            ofoperation_complete(op, 0);
3281
3502
 
3282
3503
static enum ofperr
3283
3504
modify_flows_add(struct ofproto *ofproto, struct ofconn *ofconn,
3284
 
                 const struct ofputil_flow_mod *fm,
3285
 
                 const struct ofp_header *request)
 
3505
                 struct ofputil_flow_mod *fm, const struct ofp_header *request)
3286
3506
{
3287
3507
    if (fm->cookie_mask != htonll(0) || fm->new_cookie == htonll(UINT64_MAX)) {
3288
3508
        return 0;
3297
3517
 * if any. */
3298
3518
static enum ofperr
3299
3519
modify_flows_loose(struct ofproto *ofproto, struct ofconn *ofconn,
3300
 
                   const struct ofputil_flow_mod *fm,
 
3520
                   struct ofputil_flow_mod *fm,
3301
3521
                   const struct ofp_header *request)
3302
3522
{
3303
3523
    struct list rules;
3322
3542
 * if any. */
3323
3543
static enum ofperr
3324
3544
modify_flow_strict(struct ofproto *ofproto, struct ofconn *ofconn,
3325
 
                   const struct ofputil_flow_mod *fm,
 
3545
                   struct ofputil_flow_mod *fm,
3326
3546
                   const struct ofp_header *request)
3327
3547
{
3328
3548
    struct list rules;
3346
3566
/* OFPFC_DELETE implementation. */
3347
3567
 
3348
3568
static void
3349
 
delete_flow__(struct rule *rule, struct ofopgroup *group)
 
3569
delete_flow__(struct rule *rule, struct ofopgroup *group,
 
3570
              enum ofp_flow_removed_reason reason)
3350
3571
{
3351
3572
    struct ofproto *ofproto = rule->ofproto;
3352
3573
 
3353
 
    ofproto_rule_send_removed(rule, OFPRR_DELETE);
 
3574
    ofproto_rule_send_removed(rule, reason);
3354
3575
 
3355
 
    ofoperation_create(group, rule, OFOPERATION_DELETE, OFPRR_DELETE);
 
3576
    ofoperation_create(group, rule, OFOPERATION_DELETE, reason);
3356
3577
    oftable_remove_rule(rule);
3357
3578
    ofproto->ofproto_class->rule_destruct(rule);
3358
3579
}
3362
3583
 * Returns 0 on success, otherwise an OpenFlow error code. */
3363
3584
static enum ofperr
3364
3585
delete_flows__(struct ofproto *ofproto, struct ofconn *ofconn,
3365
 
               const struct ofp_header *request, struct list *rules)
 
3586
               const struct ofp_header *request, struct list *rules,
 
3587
               enum ofp_flow_removed_reason reason)
3366
3588
{
3367
3589
    struct rule *rule, *next;
3368
3590
    struct ofopgroup *group;
3369
3591
 
3370
3592
    group = ofopgroup_create(ofproto, ofconn, request, UINT32_MAX);
3371
3593
    LIST_FOR_EACH_SAFE (rule, next, ofproto_node, rules) {
3372
 
        delete_flow__(rule, group);
 
3594
        delete_flow__(rule, group, reason);
3373
3595
    }
3374
3596
    ofopgroup_submit(group);
3375
3597
 
3390
3612
                                fm->out_port, &rules);
3391
3613
    return (error ? error
3392
3614
            : !list_is_empty(&rules) ? delete_flows__(ofproto, ofconn, request,
3393
 
                                                      &rules)
 
3615
                                                      &rules, OFPRR_DELETE)
3394
3616
            : 0);
3395
3617
}
3396
3618
 
3408
3630
                                 fm->out_port, &rules);
3409
3631
    return (error ? error
3410
3632
            : list_is_singleton(&rules) ? delete_flows__(ofproto, ofconn,
3411
 
                                                         request, &rules)
 
3633
                                                         request, &rules,
 
3634
                                                         OFPRR_DELETE)
3412
3635
            : 0);
3413
3636
}
3414
3637
 
3426
3649
    fr.cookie = rule->flow_cookie;
3427
3650
    fr.reason = reason;
3428
3651
    fr.table_id = rule->table_id;
3429
 
    calc_flow_duration__(rule->created, time_msec(),
3430
 
                         &fr.duration_sec, &fr.duration_nsec);
 
3652
    calc_duration(rule->created, time_msec(),
 
3653
                  &fr.duration_sec, &fr.duration_nsec);
3431
3654
    fr.idle_timeout = rule->idle_timeout;
3432
3655
    fr.hard_timeout = rule->hard_timeout;
3433
3656
    rule->ofproto->ofproto_class->rule_get_stats(rule, &fr.packet_count,
3495
3718
    error = ofputil_decode_flow_mod(&fm, oh, ofconn_get_protocol(ofconn),
3496
3719
                                    &ofpacts);
3497
3720
    if (!error) {
3498
 
        error = ofpacts_check(fm.ofpacts, fm.ofpacts_len,
3499
 
                              &fm.match.flow, ofproto->max_ports);
3500
 
    }
3501
 
    if (!error) {
3502
3721
        error = handle_flow_mod__(ofproto, ofconn, &fm, oh);
3503
3722
    }
3504
3723
    if (error) {
3539
3758
 
3540
3759
static enum ofperr
3541
3760
handle_flow_mod__(struct ofproto *ofproto, struct ofconn *ofconn,
3542
 
                  const struct ofputil_flow_mod *fm,
3543
 
                  const struct ofp_header *oh)
 
3761
                  struct ofputil_flow_mod *fm, const struct ofp_header *oh)
3544
3762
{
3545
3763
    if (ofproto->n_pending >= 50) {
3546
3764
        ovs_assert(!list_is_empty(&ofproto->pending));
3576
3794
static enum ofperr
3577
3795
handle_role_request(struct ofconn *ofconn, const struct ofp_header *oh)
3578
3796
{
3579
 
    struct ofputil_role_request rr;
 
3797
    struct ofputil_role_request request;
 
3798
    struct ofputil_role_request reply;
3580
3799
    struct ofpbuf *buf;
3581
 
    uint32_t role;
3582
3800
    enum ofperr error;
3583
3801
 
3584
 
    error = ofputil_decode_role_message(oh, &rr);
 
3802
    error = ofputil_decode_role_message(oh, &request);
3585
3803
    if (error) {
3586
3804
        return error;
3587
3805
    }
3588
3806
 
3589
 
    if (rr.request_current_role_only) {
3590
 
        role = ofconn_get_role(ofconn); /* NX_ROLE_* */
3591
 
        goto reply;
3592
 
    }
3593
 
 
3594
 
    role = rr.role;
3595
 
 
3596
 
    if (ofconn_get_role(ofconn) != role
3597
 
        && ofconn_has_pending_opgroups(ofconn)) {
3598
 
        return OFPROTO_POSTPONE;
3599
 
    }
3600
 
 
3601
 
    if (rr.have_generation_id) {
3602
 
        if (!ofconn_set_master_election_id(ofconn, rr.generation_id)) {
3603
 
            return OFPERR_OFPRRFC_STALE;
3604
 
        }
3605
 
    }
3606
 
 
3607
 
    ofconn_set_role(ofconn, role);
3608
 
 
3609
 
reply:
3610
 
    buf = ofputil_encode_role_reply(oh, role);
 
3807
    if (request.role != OFPCR12_ROLE_NOCHANGE) {
 
3808
        if (ofconn_get_role(ofconn) != request.role
 
3809
            && ofconn_has_pending_opgroups(ofconn)) {
 
3810
            return OFPROTO_POSTPONE;
 
3811
        }
 
3812
 
 
3813
        if (request.have_generation_id
 
3814
            && !ofconn_set_master_election_id(ofconn, request.generation_id)) {
 
3815
                return OFPERR_OFPRRFC_STALE;
 
3816
        }
 
3817
 
 
3818
        ofconn_set_role(ofconn, request.role);
 
3819
    }
 
3820
 
 
3821
    reply.role = ofconn_get_role(ofconn);
 
3822
    reply.have_generation_id = ofconn_get_master_election_id(
 
3823
        ofconn, &reply.generation_id);
 
3824
    buf = ofputil_encode_role_reply(oh, &reply);
3611
3825
    ofconn_send_reply(ofconn, buf);
3612
3826
 
3613
3827
    return 0;
3980
4194
    return 0;
3981
4195
}
3982
4196
 
 
4197
/* Meters implementation.
 
4198
 *
 
4199
 * Meter table entry, indexed by the OpenFlow meter_id.
 
4200
 * These are always dynamically allocated to allocate enough space for
 
4201
 * the bands.
 
4202
 * 'created' is used to compute the duration for meter stats.
 
4203
 * 'list rules' is needed so that we can delete the dependent rules when the
 
4204
 * meter table entry is deleted.
 
4205
 * 'provider_meter_id' is for the provider's private use.
 
4206
 */
 
4207
struct meter {
 
4208
    long long int created;      /* Time created. */
 
4209
    struct list rules;          /* List of "struct rule_dpif"s. */
 
4210
    ofproto_meter_id provider_meter_id;
 
4211
    uint16_t flags;             /* Meter flags. */
 
4212
    uint16_t n_bands;           /* Number of meter bands. */
 
4213
    struct ofputil_meter_band *bands;
 
4214
};
 
4215
 
 
4216
/*
 
4217
 * This is used in instruction validation at flow set-up time,
 
4218
 * as flows may not use non-existing meters.
 
4219
 * This is also used by ofproto-providers to translate OpenFlow meter_ids
 
4220
 * in METER instructions to the corresponding provider meter IDs.
 
4221
 * Return value of UINT32_MAX signifies an invalid meter.
 
4222
 */
 
4223
uint32_t
 
4224
ofproto_get_provider_meter_id(const struct ofproto * ofproto,
 
4225
                              uint32_t of_meter_id)
 
4226
{
 
4227
    if (of_meter_id && of_meter_id <= ofproto->meter_features.max_meters) {
 
4228
        const struct meter *meter = ofproto->meters[of_meter_id];
 
4229
        if (meter) {
 
4230
            return meter->provider_meter_id.uint32;
 
4231
        }
 
4232
    }
 
4233
    return UINT32_MAX;
 
4234
}
 
4235
 
 
4236
static void
 
4237
meter_update(struct meter *meter, const struct ofputil_meter_config *config)
 
4238
{
 
4239
    free(meter->bands);
 
4240
 
 
4241
    meter->flags = config->flags;
 
4242
    meter->n_bands = config->n_bands;
 
4243
    meter->bands = xmemdup(config->bands,
 
4244
                           config->n_bands * sizeof *meter->bands);
 
4245
}
 
4246
 
 
4247
static struct meter *
 
4248
meter_create(const struct ofputil_meter_config *config,
 
4249
             ofproto_meter_id provider_meter_id)
 
4250
{
 
4251
    struct meter *meter;
 
4252
 
 
4253
    meter = xzalloc(sizeof *meter);
 
4254
    meter->provider_meter_id = provider_meter_id;
 
4255
    meter->created = time_msec();
 
4256
    list_init(&meter->rules);
 
4257
 
 
4258
    meter_update(meter, config);
 
4259
 
 
4260
    return meter;
 
4261
}
 
4262
 
 
4263
static void
 
4264
meter_delete(struct ofproto *ofproto, uint32_t first, uint32_t last)
 
4265
{
 
4266
    uint32_t mid;
 
4267
    for (mid = first; mid <= last; ++mid) {
 
4268
        struct meter *meter = ofproto->meters[mid];
 
4269
        if (meter) {
 
4270
            ofproto->meters[mid] = NULL;
 
4271
            ofproto->ofproto_class->meter_del(ofproto,
 
4272
                                              meter->provider_meter_id);
 
4273
            free(meter->bands);
 
4274
            free(meter);
 
4275
        }
 
4276
    }
 
4277
}
 
4278
 
 
4279
static enum ofperr
 
4280
handle_add_meter(struct ofproto *ofproto, struct ofputil_meter_mod *mm)
 
4281
{
 
4282
    ofproto_meter_id provider_meter_id = { UINT32_MAX };
 
4283
    struct meter **meterp = &ofproto->meters[mm->meter.meter_id];
 
4284
    enum ofperr error;
 
4285
 
 
4286
    if (*meterp) {
 
4287
        return OFPERR_OFPMMFC_METER_EXISTS;
 
4288
    }
 
4289
 
 
4290
    error = ofproto->ofproto_class->meter_set(ofproto, &provider_meter_id,
 
4291
                                              &mm->meter);
 
4292
    if (!error) {
 
4293
        ovs_assert(provider_meter_id.uint32 != UINT32_MAX);
 
4294
        *meterp = meter_create(&mm->meter, provider_meter_id);
 
4295
    }
 
4296
    return 0;
 
4297
}
 
4298
 
 
4299
static enum ofperr
 
4300
handle_modify_meter(struct ofproto *ofproto, struct ofputil_meter_mod *mm)
 
4301
{
 
4302
    struct meter *meter = ofproto->meters[mm->meter.meter_id];
 
4303
    enum ofperr error;
 
4304
 
 
4305
    if (!meter) {
 
4306
        return OFPERR_OFPMMFC_UNKNOWN_METER;
 
4307
    }
 
4308
 
 
4309
    error = ofproto->ofproto_class->meter_set(ofproto,
 
4310
                                              &meter->provider_meter_id,
 
4311
                                              &mm->meter);
 
4312
    ovs_assert(meter->provider_meter_id.uint32 != UINT32_MAX);
 
4313
    if (!error) {
 
4314
        meter_update(meter, &mm->meter);
 
4315
    }
 
4316
    return error;
 
4317
}
 
4318
 
 
4319
static enum ofperr
 
4320
handle_delete_meter(struct ofconn *ofconn, const struct ofp_header *oh,
 
4321
                    struct ofputil_meter_mod *mm)
 
4322
{
 
4323
    struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
 
4324
    uint32_t meter_id = mm->meter.meter_id;
 
4325
    uint32_t first, last;
 
4326
    struct list rules;
 
4327
 
 
4328
    if (meter_id == OFPM13_ALL) {
 
4329
        first = 1;
 
4330
        last = ofproto->meter_features.max_meters;
 
4331
    } else {
 
4332
        if (!meter_id || meter_id > ofproto->meter_features.max_meters) {
 
4333
            return 0;
 
4334
        }
 
4335
        first = last = meter_id;
 
4336
    }
 
4337
 
 
4338
    /* First delete the rules that use this meter.  If any of those rules are
 
4339
     * currently being modified, postpone the whole operation until later. */
 
4340
    list_init(&rules);
 
4341
    for (meter_id = first; meter_id <= last; ++meter_id) {
 
4342
        struct meter *meter = ofproto->meters[meter_id];
 
4343
        if (meter && !list_is_empty(&meter->rules)) {
 
4344
            struct rule *rule;
 
4345
 
 
4346
            LIST_FOR_EACH (rule, meter_list_node, &meter->rules) {
 
4347
                if (rule->pending) {
 
4348
                    return OFPROTO_POSTPONE;
 
4349
                }
 
4350
                list_push_back(&rules, &rule->ofproto_node);
 
4351
            }
 
4352
        }
 
4353
    }
 
4354
    if (!list_is_empty(&rules)) {
 
4355
        delete_flows__(ofproto, ofconn, oh, &rules, OFPRR_METER_DELETE);
 
4356
    }
 
4357
 
 
4358
    /* Delete the meters. */
 
4359
    meter_delete(ofproto, first, last);
 
4360
 
 
4361
    return 0;
 
4362
}
 
4363
 
 
4364
static enum ofperr
 
4365
handle_meter_mod(struct ofconn *ofconn, const struct ofp_header *oh)
 
4366
{
 
4367
    struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
 
4368
    struct ofputil_meter_mod mm;
 
4369
    uint64_t bands_stub[256 / 8];
 
4370
    struct ofpbuf bands;
 
4371
    uint32_t meter_id;
 
4372
    enum ofperr error;
 
4373
 
 
4374
    error = reject_slave_controller(ofconn);
 
4375
    if (error) {
 
4376
        return error;
 
4377
    }
 
4378
 
 
4379
    ofpbuf_use_stub(&bands, bands_stub, sizeof bands_stub);
 
4380
 
 
4381
    error = ofputil_decode_meter_mod(oh, &mm, &bands);
 
4382
    if (error) {
 
4383
        goto exit_free_bands;
 
4384
    }
 
4385
 
 
4386
    meter_id = mm.meter.meter_id;
 
4387
 
 
4388
    if (mm.command != OFPMC13_DELETE) {
 
4389
        /* Fails also when meters are not implemented by the provider. */
 
4390
        if (!meter_id || meter_id > ofproto->meter_features.max_meters) {
 
4391
            error = OFPERR_OFPMMFC_INVALID_METER;
 
4392
            goto exit_free_bands;
 
4393
        }
 
4394
        if (mm.meter.n_bands > ofproto->meter_features.max_bands) {
 
4395
            error = OFPERR_OFPMMFC_OUT_OF_BANDS;
 
4396
            goto exit_free_bands;
 
4397
        }
 
4398
    }
 
4399
 
 
4400
    switch (mm.command) {
 
4401
    case OFPMC13_ADD:
 
4402
        error = handle_add_meter(ofproto, &mm);
 
4403
        break;
 
4404
 
 
4405
    case OFPMC13_MODIFY:
 
4406
        error = handle_modify_meter(ofproto, &mm);
 
4407
        break;
 
4408
 
 
4409
    case OFPMC13_DELETE:
 
4410
        error = handle_delete_meter(ofconn, oh, &mm);
 
4411
        break;
 
4412
 
 
4413
    default:
 
4414
        error = OFPERR_OFPMMFC_BAD_COMMAND;
 
4415
        break;
 
4416
    }
 
4417
 
 
4418
exit_free_bands:
 
4419
    ofpbuf_uninit(&bands);
 
4420
    return error;
 
4421
}
 
4422
 
 
4423
static enum ofperr
 
4424
handle_meter_features_request(struct ofconn *ofconn,
 
4425
                              const struct ofp_header *request)
 
4426
{
 
4427
    struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
 
4428
    struct ofputil_meter_features features;
 
4429
    struct ofpbuf *b;
 
4430
 
 
4431
    if (ofproto->ofproto_class->meter_get_features) {
 
4432
        ofproto->ofproto_class->meter_get_features(ofproto, &features);
 
4433
    } else {
 
4434
        memset(&features, 0, sizeof features);
 
4435
    }
 
4436
    b = ofputil_encode_meter_features_reply(&features, request);
 
4437
 
 
4438
    ofconn_send_reply(ofconn, b);
 
4439
    return 0;
 
4440
}
 
4441
 
 
4442
static enum ofperr
 
4443
handle_meter_request(struct ofconn *ofconn, const struct ofp_header *request,
 
4444
                     enum ofptype type)
 
4445
{
 
4446
    struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
 
4447
    struct list replies;
 
4448
    uint64_t bands_stub[256 / 8];
 
4449
    struct ofpbuf bands;
 
4450
    uint32_t meter_id, first, last;
 
4451
 
 
4452
    ofputil_decode_meter_request(request, &meter_id);
 
4453
 
 
4454
    if (meter_id == OFPM13_ALL) {
 
4455
        first = 1;
 
4456
        last = ofproto->meter_features.max_meters;
 
4457
    } else {
 
4458
        if (!meter_id || meter_id > ofproto->meter_features.max_meters ||
 
4459
            !ofproto->meters[meter_id]) {
 
4460
            return OFPERR_OFPMMFC_UNKNOWN_METER;
 
4461
        }
 
4462
        first = last = meter_id;
 
4463
    }
 
4464
 
 
4465
    ofpbuf_use_stub(&bands, bands_stub, sizeof bands_stub);
 
4466
    ofpmp_init(&replies, request);
 
4467
 
 
4468
    for (meter_id = first; meter_id <= last; ++meter_id) {
 
4469
        struct meter *meter = ofproto->meters[meter_id];
 
4470
        if (!meter) {
 
4471
            continue; /* Skip non-existing meters. */
 
4472
        }
 
4473
        if (type == OFPTYPE_METER_STATS_REQUEST) {
 
4474
            struct ofputil_meter_stats stats;
 
4475
 
 
4476
            stats.meter_id = meter_id;
 
4477
 
 
4478
            /* Provider sets the packet and byte counts, we do the rest. */
 
4479
            stats.flow_count = list_size(&meter->rules);
 
4480
            calc_duration(meter->created, time_msec(),
 
4481
                          &stats.duration_sec, &stats.duration_nsec);
 
4482
            stats.n_bands = meter->n_bands;
 
4483
            ofpbuf_clear(&bands);
 
4484
            stats.bands
 
4485
                = ofpbuf_put_uninit(&bands,
 
4486
                                    meter->n_bands * sizeof *stats.bands);
 
4487
 
 
4488
            if (!ofproto->ofproto_class->meter_get(ofproto,
 
4489
                                                   meter->provider_meter_id,
 
4490
                                                   &stats)) {
 
4491
                ofputil_append_meter_stats(&replies, &stats);
 
4492
            }
 
4493
        } else { /* type == OFPTYPE_METER_CONFIG_REQUEST */
 
4494
            struct ofputil_meter_config config;
 
4495
 
 
4496
            config.meter_id = meter_id;
 
4497
            config.flags = meter->flags;
 
4498
            config.n_bands = meter->n_bands;
 
4499
            config.bands = meter->bands;
 
4500
            ofputil_append_meter_config(&replies, &config);
 
4501
        }
 
4502
    }
 
4503
 
 
4504
    ofconn_send_replies(ofconn, &replies);
 
4505
    ofpbuf_uninit(&bands);
 
4506
    return 0;
 
4507
}
 
4508
 
3983
4509
static enum ofperr
3984
4510
handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
3985
4511
{
4015
4541
    case OFPTYPE_FLOW_MOD:
4016
4542
        return handle_flow_mod(ofconn, oh);
4017
4543
 
 
4544
    case OFPTYPE_METER_MOD:
 
4545
        return handle_meter_mod(ofconn, oh);
 
4546
 
4018
4547
    case OFPTYPE_BARRIER_REQUEST:
4019
4548
        return handle_barrier_request(ofconn, oh);
4020
4549
 
4073
4602
    case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
4074
4603
        return handle_flow_monitor_request(ofconn, oh);
4075
4604
 
 
4605
    case OFPTYPE_METER_STATS_REQUEST:
 
4606
    case OFPTYPE_METER_CONFIG_STATS_REQUEST:
 
4607
        return handle_meter_request(ofconn, oh, type);
 
4608
 
 
4609
    case OFPTYPE_METER_FEATURES_STATS_REQUEST:
 
4610
        return handle_meter_features_request(ofconn, oh);
 
4611
 
4076
4612
        /* FIXME: Change the following once they are implemented: */
4077
4613
    case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
4078
4614
    case OFPTYPE_GET_ASYNC_REQUEST:
4079
 
    case OFPTYPE_METER_MOD:
4080
 
    case OFPTYPE_GROUP_REQUEST:
4081
 
    case OFPTYPE_GROUP_DESC_REQUEST:
4082
 
    case OFPTYPE_GROUP_FEATURES_REQUEST:
4083
 
    case OFPTYPE_METER_REQUEST:
4084
 
    case OFPTYPE_METER_CONFIG_REQUEST:
4085
 
    case OFPTYPE_METER_FEATURES_REQUEST:
4086
 
    case OFPTYPE_TABLE_FEATURES_REQUEST:
 
4615
    case OFPTYPE_GROUP_STATS_REQUEST:
 
4616
    case OFPTYPE_GROUP_DESC_STATS_REQUEST:
 
4617
    case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
 
4618
    case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
4087
4619
        return OFPERR_OFPBRC_BAD_TYPE;
4088
4620
 
4089
4621
    case OFPTYPE_HELLO:
4107
4639
    case OFPTYPE_FLOW_MONITOR_RESUMED:
4108
4640
    case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
4109
4641
    case OFPTYPE_GET_ASYNC_REPLY:
4110
 
    case OFPTYPE_GROUP_REPLY:
4111
 
    case OFPTYPE_GROUP_DESC_REPLY:
4112
 
    case OFPTYPE_GROUP_FEATURES_REPLY:
4113
 
    case OFPTYPE_METER_REPLY:
4114
 
    case OFPTYPE_METER_CONFIG_REPLY:
4115
 
    case OFPTYPE_METER_FEATURES_REPLY:
4116
 
    case OFPTYPE_TABLE_FEATURES_REPLY:
 
4642
    case OFPTYPE_GROUP_STATS_REPLY:
 
4643
    case OFPTYPE_GROUP_DESC_STATS_REPLY:
 
4644
    case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
 
4645
    case OFPTYPE_METER_STATS_REPLY:
 
4646
    case OFPTYPE_METER_CONFIG_STATS_REPLY:
 
4647
    case OFPTYPE_METER_FEATURES_STATS_REPLY:
 
4648
    case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
4117
4649
    default:
4118
4650
        return OFPERR_OFPBRC_BAD_TYPE;
4119
4651
    }
4120
4652
}
4121
4653
 
4122
4654
static bool
4123
 
handle_openflow(struct ofconn *ofconn, struct ofpbuf *ofp_msg)
 
4655
handle_openflow(struct ofconn *ofconn, const struct ofpbuf *ofp_msg)
4124
4656
{
4125
4657
    int error = handle_openflow__(ofconn, ofp_msg);
4126
4658
    if (error && error != OFPROTO_POSTPONE) {
4220
4752
        LIST_FOR_EACH (op, group_node, &group->ops) {
4221
4753
            if (op->type != OFOPERATION_DELETE) {
4222
4754
                struct ofpbuf *packet;
4223
 
                uint16_t in_port;
 
4755
                ofp_port_t in_port;
4224
4756
 
4225
4757
                error = ofconn_pktbuf_retrieve(group->ofconn, group->buffer_id,
4226
4758
                                               &packet, &in_port);
4306
4838
            if (!op->error) {
4307
4839
                rule->modified = time_msec();
4308
4840
            } else {
4309
 
                rule->flow_cookie = op->flow_cookie;
 
4841
                ofproto_rule_change_cookie(ofproto, rule, op->flow_cookie);
4310
4842
                if (op->ofpacts) {
4311
4843
                    free(rule->ofpacts);
4312
4844
                    rule->ofpacts = op->ofpacts;
4461
4993
        }
4462
4994
        VLOG_WARN("%s: could not get MAC address for %s (%s)",
4463
4995
                  ofproto->name, netdev_get_name(port->netdev),
4464
 
                  strerror(error));
 
4996
                  ovs_strerror(error));
4465
4997
    }
4466
4998
    return ofproto->fallback_dpid;
4467
4999
}
4835
5367
    struct oftable *table = &ofproto->tables[rule->table_id];
4836
5368
 
4837
5369
    classifier_remove(&table->cls, &rule->cr);
 
5370
    if (rule->meter_id) {
 
5371
        list_remove(&rule->meter_list_node);
 
5372
    }
 
5373
    cookies_remove(ofproto, rule);
4838
5374
    eviction_group_remove_rule(rule);
4839
5375
    if (!list_is_empty(&rule->expirable)) {
4840
5376
        list_remove(&rule->expirable);
4841
5377
    }
 
5378
    if (!list_is_empty(&rule->meter_list_node)) {
 
5379
        list_remove(&rule->meter_list_node);
 
5380
    }
4842
5381
}
4843
5382
 
4844
5383
/* Inserts 'rule' into its oftable.  Removes any existing rule from 'rule''s
4855
5394
    if (may_expire) {
4856
5395
        list_insert(&ofproto->expirable, &rule->expirable);
4857
5396
    }
4858
 
 
 
5397
    cookies_insert(ofproto, rule);
 
5398
    if (rule->meter_id) {
 
5399
        struct meter *meter = ofproto->meters[rule->meter_id];
 
5400
        list_insert(&meter->rules, &rule->meter_list_node);
 
5401
    }
4859
5402
    victim = rule_from_cls_rule(classifier_replace(&table->cls, &rule->cr));
4860
5403
    if (victim) {
 
5404
        if (victim->meter_id) {
 
5405
            list_remove(&victim->meter_list_node);
 
5406
        }
 
5407
        cookies_remove(ofproto, victim);
 
5408
 
4861
5409
        if (!list_is_empty(&victim->expirable)) {
4862
5410
            list_remove(&victim->expirable);
4863
5411
        }
4973
5521
 * device as a VLAN splinter for VLAN ID 'vid'.  If 'realdev_ofp_port' is zero,
4974
5522
 * then the VLAN device is un-enslaved. */
4975
5523
int
4976
 
ofproto_port_set_realdev(struct ofproto *ofproto, uint16_t vlandev_ofp_port,
4977
 
                         uint16_t realdev_ofp_port, int vid)
 
5524
ofproto_port_set_realdev(struct ofproto *ofproto, ofp_port_t vlandev_ofp_port,
 
5525
                         ofp_port_t realdev_ofp_port, int vid)
4978
5526
{
4979
5527
    struct ofport *ofport;
4980
5528
    int error;
5000
5548
    if (error) {
5001
5549
        VLOG_WARN("%s: setting realdev on port %"PRIu16" (%s) failed (%s)",
5002
5550
                  ofproto->name, vlandev_ofp_port,
5003
 
                  netdev_get_name(ofport->netdev), strerror(error));
 
5551
                  netdev_get_name(ofport->netdev), ovs_strerror(error));
5004
5552
    }
5005
5553
    return error;
5006
5554
}