aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-plugin/src/host_stack/cbr_proto.c
blob: b87f2573c8c12a7a21656df1c6551e227af3843e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "host_stack.h"
#include "inlines.h"

#define WINDOW_SIZE 200

typedef struct hicn_hs_cbr_proto_data_
{
  u64 next_seq_number;
  u16 window_size;
  u16 in_flight_interests;
} hicn_hs_cbr_proto_data_t;

#define proto_data(ctx) ((hicn_hs_cbr_proto_data_t *)(ctx->hs_proto_data))

static void
reset_protocol(hicn_hs_cbr_proto_data_t *proto_data)
{
  proto_data->in_flight_interests = 0;
  proto_data->window_size = WINDOW_SIZE;
  proto_data->next_seq_number = 0;
}

static void
schedule_next_interests(hicn_hs_ctx_t *ctx)
{
  hicn_hs_cbr_proto_data_t *data = proto_data(ctx);
  u32 scheduled_interests = 0;

  if (data->in_flight_interests < data->window_size)
    scheduled_interests = hicn_hs_send_interests(ctx, data->next_seq_number,
                                                 data->window_size - data->in_flight_interests);

  data->in_flight_interests += scheduled_interests;
  data->next_seq_number += scheduled_interests;
}

u32 cbr_proto_init(hicn_hs_ctx_t *ctx)
{
  if (ctx->running)
    return -1;

  hicn_hs_cbr_proto_data_t *data = proto_data(ctx);

  reset_protocol(data);
  schedule_next_interests(ctx);
  ctx->running = 1;

  return 0;
}

u32 cbr_proto_on_data(hicn_hs_ctx_t *ctx, u16 n_data)
{
  hicn_hs_cbr_proto_data_t *data = proto_data(ctx);
  data->in_flight_interests -= n_data;
  schedule_next_interests(ctx);
  return 0;
}

u32 cbr_proto_on_interest(hicn_hs_ctx_t *ctx)
{
  return 0;
}

u32 cbr_proto_interest_timeout(hicn_hs_ctx_t *ctx)
{
  return 0;
}

u32 cbr_proto_event(hicn_hs_ctx_t *ctx, hicn_hs_proto_event_t event)
{
  return 0;
}

hicn_hs_proto_t cbr_proto = {
    .init = cbr_proto_init,
    .rcv_data = cbr_proto_on_data,
    .rcv_interest = cbr_proto_on_interest,
    .on_interest_timeout = cbr_proto_interest_timeout,
    .event = cbr_proto_event,
    .options = {
        .is_stream = 1}};