Esempio n. 1
0
static void
send_packet( uint16_t destination_port, packet_in packet_in ) {
  openflow_actions *actions = create_actions();
  append_action_output( actions, destination_port, UINT16_MAX );

  struct ofp_match match;
  set_match_from_packet( &match, packet_in.in_port, 0, packet_in.data );

  buffer *flow_mod = create_flow_mod(
    get_transaction_id(),
    match,
    get_cookie(),
    OFPFC_ADD,
    60,
    0,
    UINT16_MAX,
    UINT32_MAX,
    OFPP_NONE,
    OFPFF_SEND_FLOW_REM,
    actions
  );
  send_openflow_message( packet_in.datapath_id, flow_mod );
  free_buffer( flow_mod );

  send_packet_out( packet_in, actions );

  delete_actions( actions );
}
Esempio n. 2
0
void
send_arp(struct arp *arp_pkt)
{
    struct rte_mbuf *mbuf = NULL;
    struct arp *arp_hdr = NULL;
    struct ether_hdr *eth = NULL;
    int i;

    mbuf = get_mbuf();
    assert(mbuf != NULL);
    arp_hdr = (struct arp *)rte_pktmbuf_prepend (mbuf, sizeof(struct arp));
    eth = (struct ether_hdr *)rte_pktmbuf_prepend (mbuf, sizeof(struct ether_hdr));
    logger(ARP, NORMAL, "Sending arp packet\n");
    memcpy(arp_hdr, arp_pkt, sizeof(struct arp));
    if(arp_pkt->opcode == ntohs(ARP_REQ)) {
        logger(ARP, ALL, "Sending arp request");
        eth->ether_type = htons(ETHER_TYPE_ARP);
        for(i=0; i<6; i++) {
            eth->d_addr.addr_bytes[i] = 0xff;
        }
        memcpy(&eth->s_addr.addr_bytes[0], arp_pkt->src_hw_add, sizeof(arp_pkt->hw_len));
    }
    if(arp_pkt->opcode == ntohs(ARP_REPLY)) {
        logger(ARP, ALL, "Sending arp reply");
        eth->ether_type = htons(ETHER_TYPE_ARP);
        for(i=0; i<6; i++) {
            eth->d_addr.addr_bytes[i] = 0xff;  // should not be a brodcast ideally. fix it.
        }
        // memcpy(&eth->d_addr.addr_bytes[0], arp_pkt->src_hw_add, sizeof(arp_pkt->hw_len));
        memcpy(&eth->s_addr.addr_bytes[0], arp_pkt->src_hw_add, sizeof(arp_pkt->hw_len));
    }
    send_packet_out(mbuf, 0);
}
Esempio n. 3
0
File: switch.c Progetto: iqm/apps
static void
output_packet( const buffer *packet, uint64_t dpid, uint16_t port_no ) {
  openflow_actions *actions = create_actions();
  append_action_output( actions, port_no, UINT16_MAX );

  send_packet_out( dpid, actions, packet );
  delete_actions( actions );
}
Esempio n. 4
0
static void
do_flooding( packet_in packet_in ) {
  openflow_actions *actions = create_actions();
  append_action_output( actions, OFPP_FLOOD, UINT16_MAX );

  send_packet_out( packet_in, actions );

  delete_actions( actions );
}
Esempio n. 5
0
File: switch.c Progetto: iqm/apps
static void
send_packet_out_for_each_switch( switch_info *sw, const buffer *packet, uint64_t dpid, uint16_t in_port ) {
  openflow_actions *actions = create_actions();
  int number_of_actions = foreach_port( sw->ports, build_packet_out_actions, actions, dpid, in_port );

  if ( number_of_actions > 0 ) {
    send_packet_out( sw->dpid, actions, packet );
  }
  delete_actions( actions );
}
Esempio n. 6
0
static void
send_packet_out_for_each_switch( switch_info *sw, void *user_data ) {
  openflow_actions *actions = create_actions();
  port_params params;
  params.switch_params = user_data;
  params.actions = actions;
  foreach_port( sw->ports, build_packet_out_actions, &params );

  // check if no action is build
  if ( actions->n_actions > 0 ) {
    const buffer *packet = params.switch_params->packet;
    send_packet_out( sw->dpid, actions, packet );
  }

  delete_actions( actions );
}
Esempio n. 7
0
static void
handle_packet_in( uint64_t datapath_id, packet_in message ) {
  UNUSED( datapath_id );
  packet_info packet_info = get_packet_info( message.data );
  traffic *db = message.user_data;

  uint8_t *macsa = packet_info.eth_macsa;
  uint8_t *macda = packet_info.eth_macda;

  learn_fdb( db->fdb, macsa, message.in_port );
  add_counter( db->counter, macsa, 1, message.data->length );
  uint16_t out_port = lookup_fdb( db->fdb, macda );
  if ( out_port != ENTRY_NOT_FOUND_IN_FDB ) {
     send_packet_out( datapath_id, &message, out_port );
     send_flow_mod( datapath_id, macsa, macda, out_port );
  }
  else {
     do_flooding( datapath_id, &message );
  }
}
Esempio n. 8
0
int
ether_out(unsigned char *dst_mac, char *src_mac, uint16_t ether_type, struct rte_mbuf *mbuf)
{
   int i = 0;
   struct ether_hdr *eth;
   eth = (struct ether_hdr *)rte_pktmbuf_prepend (mbuf, sizeof(struct ether_hdr)); 
   eth->ether_type = htons(ether_type);
   for(i=0;i<6;i++) {
      eth->d_addr.addr_bytes[i] = dst_mac[i];
   }
//   for(i=0;i<6;i++) {
   eth->s_addr.addr_bytes[0] = 0x6a;
   eth->s_addr.addr_bytes[1] = 0x9c;
   eth->s_addr.addr_bytes[2] = 0xba;
   eth->s_addr.addr_bytes[3] = 0xa0;
   eth->s_addr.addr_bytes[4] = 0x96;
   eth->s_addr.addr_bytes[5] = 0x24;
//   }
// fix this this should be automatically detect the network interface id.
   send_packet_out(mbuf, 0);
   static int counter_id = -1;
   if(counter_id == -1) {
      counter_id = create_counter("sent_rate");
   }
   int data_len = rte_pktmbuf_data_len(mbuf);

   counter_abs(counter_id, data_len);
   {
      static int counter_id = -1;
      if(counter_id == -1) {
         counter_id = create_counter("wire_sent");
      }
      int data_len = rte_pktmbuf_data_len(mbuf);
 
      counter_inc(counter_id, data_len);
   }
   (void) src_mac; // jusat to avoid warning
   src_mac = NULL;
   return 0;
}
Esempio n. 9
0
static void
output_packet( const buffer *packet, uint64_t dpid, uint16_t port_no, uint16_t out_vid ) {

  openflow_actions *actions = create_actions();
  uint16_t in_vid = VLAN_NONE;
  if ( packet_type_eth_vtag( packet ) ) {
    packet_info packet_info = get_packet_info( packet );
    in_vid = packet_info.vlan_vid;
  }
  if ( out_vid != in_vid ) {
    if ( in_vid != VLAN_NONE && out_vid == VLAN_NONE ) {
      append_action_strip_vlan( actions );
    }
    else {
      append_action_set_vlan_vid( actions, out_vid );
    }
  }
  const uint16_t max_len = UINT16_MAX;
  append_action_output( actions, port_no, max_len );

  send_packet_out( dpid, actions, packet );
  delete_actions( actions );
}
Esempio n. 10
0
int
ether_out(unsigned char *dst_mac, char *src_mac, uint16_t ether_type, struct rte_mbuf *mbuf)
{
   int i = 0;
   struct ether_hdr *eth;
   eth = (struct ether_hdr *)rte_pktmbuf_prepend (mbuf, sizeof(struct ether_hdr)); 
   eth->ether_type = htons(ether_type);
   for(i=0;i<6;i++) {
      eth->d_addr.addr_bytes[i] = dst_mac[i];
   }
//   for(i=0;i<6;i++) {
   eth->s_addr.addr_bytes[0] = 0x6a;
   eth->s_addr.addr_bytes[1] = 0x9c;
   eth->s_addr.addr_bytes[2] = 0xba;
   eth->s_addr.addr_bytes[3] = 0xa0;
   eth->s_addr.addr_bytes[4] = 0x96;
   eth->s_addr.addr_bytes[5] = 0x24;
//   }
// fix this this should be automatically detect the port id.
   send_packet_out(mbuf, 0);
   (void) src_mac; // jusat to avoid warning
   src_mac = NULL;
   return 0;
}
Esempio n. 11
0
static void
do_flooding( uint64_t datapath_id, packet_in *message ) {
  send_packet_out( datapath_id, message, OFPP_FLOOD );
}
Esempio n. 12
0
void tcp_msg_handler(struct q_node * qn, char* buffer,uint16_t total_len)
{
	send_packet_out(qn, 1111,0, buffer, total_len);
}
Esempio n. 13
0
void arp_msg_handler(struct q_node* qn, uint32_t xid, char* buffer, uint16_t total_len)
{
	uint64_t mac_addr = get_src_mac_addr(buffer);
	host_hash_value_add(qn->sw, 5, mac_addr);
	send_packet_out(qn, xid, 0, buffer, total_len);
}