   global_rib = ->
     JSON.parse(exec('gobgp -j global rib'))
 
+  flowspec_rib = ->
+    JSON.parse(exec('gobgp -j global rib -a ipv4-flowspec'))
+
   communities = (prefix) ->
     table = global_rib()
     paths = table.filter (i) -> i['prefix']==prefix


      table = global_rib()
      expect(table.length).to.equal 1
      expect(table[0]['prefix']).to.equal '10.0.0.0/24'

      expect(communities('10.0.0.0/24')).to.eql [4294967042]

    it 'shows the RIB', ->
      exec 'gobgp global rib add 10.0.0.0/24'

      gobgp.getRib family: 'ipv4-unicast', (err, table) ->
        expect(table['type']).to.equal 'GLOBAL'

        expect(table['destinations'].length).to.equal 1

        path = table['destinations'][0]
        expect(path['prefix']).to.equal PREFIX

    it 'withdraws a route', ->
      exec "gobgp global rib add #{PREFIX}"
      expect(global_rib()).not.to.be.empty

      gobgp.modPath family: 'ipv4-unicast', withdraw: true, PREFIX

      expect(global_rib()).to.be.empty


  describe 'family ipv4-flowspec', ->
    it 'originates a route', ->
      expect(flowspec_rib()).to.be.empty

      gobgp.modPath family: 'ipv4-flowspec', FLOWSPEC_PREFIX

      table = flowspec_rib()
      expect(table.length).to.equal 1
      expect(table[0].prefix).to.equal "[source:#{PREFIX}]"

    it 'shows the RIB', ->  # TODO: This does actually nothing. Usechai-as-promised
      exec "gobgp global rib -a ipv4-flowspec add #{FLOWSPEC_PREFIX}"

      gobgp.getRib family: 'ipv4-flowspec', (err, table) ->
        expect(table.type).to.equal 'GLOBAL'
        expect(table.family).to.equal 65669
        expect(table.destinations.length).to.equal 1

        path = table.destinations[0]
        expect(path.prefix).to.equal "[source:#{PREFIX}]"
        expect(path.paths[0].attrs[2].value[0].rate).to.equal 10000

    it 'withdraws a route', ->
      exec "gobgp global rib -a ipv4-flowspec add #{FLOWSPEC_PREFIX}"
      expect(flowspec_rib()).not.to.be.empty

      gobgp.modPath family: 'ipv4-flowspec', withdraw: true, FLOWSPEC_PREFIX

      expect(flowspec_rib()).to.be.empty
