Beispiel #1
0
static int
controller_func_internal(const char *bridge_str, const char *controller_str,
                         uint16_t type,
                         lagopus_result_t (*func)(struct bridge *, uint64_t dpid,
                             struct addrunion *)) {
  struct bridge *bridge;
  struct addrunion addr;
  lagopus_result_t result;
  uint64_t dpid = 0x00;

  /* Lookup bridge. */
  bridge = dpmgr_bridge_lookup(dpmgr, bridge_str);
  if (! bridge) {
    return CONFIG_FAILURE;
  }

  result = dpmgr_bridge_dpid_lookup(dpmgr, bridge_str, &dpid);
  if (result != LAGOPUS_RESULT_OK ) {
    return CONFIG_FAILURE;
  }

  addrunion_ipv4_set(&addr, controller_str);

  if (type == CONFSYS_MSG_TYPE_SET) {
    struct channel *chan;

    /* Add controller to dpmgr. */
    dpmgr_controller_add(dpmgr, bridge_str, controller_str);

    /* Register channel to dpmgr. */
    result = func(bridge, dpid, &addr);
    if (result != LAGOPUS_RESULT_OK) {
      lagopus_perror(result);
      return CONFIG_FAILURE;
    }

    /* Lookup channel from channel mgr and return. */
    result = channel_mgr_channel_lookup(bridge, &addr, &chan);
    if (result != LAGOPUS_RESULT_OK) {
      lagopus_perror(result);
      return CONFIG_FAILURE;
    }

  } else if (type == CONFSYS_MSG_TYPE_UNSET) {
    /* Delete controller from dpmgr. */
    dpmgr_controller_delete(dpmgr, bridge_str, controller_str);

    /* Remove channel from channel mgr. */
    result = channel_mgr_channel_delete(bridge, &addr);
    if (result != LAGOPUS_RESULT_OK) {
      lagopus_perror(result);
      return CONFIG_FAILURE;
    }
  }

  return CONFIG_SUCCESS;
}
Beispiel #2
0
struct channel *
create_data_channel(void) {
  static uint8_t cnt;
  char buf[256];
  struct channel *channel;
  struct session *session;
  struct addrunion addr;
  struct port port;
  uint64_t dpid = 0xabc;
  uint8_t port_hw_addr[OFP_ETH_ALEN] = {0xff, 0xff, 0xff,
                                        0xff, 0xff, 0xff
                                       };

  if (s_dpmgr == NULL) {
    s_dpmgr = dpmgr_alloc();
    dpmgr_bridge_add(s_dpmgr, "br0", dpid);
    dpmgr_controller_add(s_dpmgr, "br0", "127.0.0.1");
    port.ofp_port.port_no = 0;
    memcpy(port.ofp_port.hw_addr, port_hw_addr, OFP_ETH_ALEN);
    port.ifindex = 0;
    dpmgr_port_add(s_dpmgr, &port);
    dpmgr_bridge_port_add(s_dpmgr, "br0", 0, 0);
  }
  if (s_bridge == NULL) {
    s_bridge = dpmgr_bridge_lookup(s_dpmgr, "br0");
  }
  if (s_event_manager == NULL) {
    s_event_manager = event_manager_alloc();
    channel_mgr_initialize(s_event_manager);
  }

  snprintf(buf, sizeof(buf), "127.0.0.%u", cnt++);//XXX
  addrunion_ipv4_set(&addr, buf);
  channel_mgr_channel_add(s_bridge, dpid, &addr);
  channel_mgr_channel_lookup(s_bridge, &addr, &channel);


  session = channel_session_get(channel);
  session_write_set(session, s_write_tcp);
  session_sockfd_set(session, 3);

  channel_version_set(channel, 0x04);
  channel_xid_set(channel, s_xid);

  return channel;
}