Implement async FIB table manipulation

Implementation reuses the status information from NdnStatusOperation and
uses XSLT for basic preprocessing.

Change-Id: Id3dba1779e02451772d09bdc919fdc68475171a9
diff --git a/osx/MainMenu.xib b/osx/MainMenu.xib
index 3687eed..5f23e85 100644
--- a/osx/MainMenu.xib
+++ b/osx/MainMenu.xib
@@ -33,16 +33,19 @@
         <customObject id="0yn-TQ-4SC" userLabel="Preference Delegate" customClass="PreferenceDelegate">
             <connections>
                 <outlet property="endpointText" destination="xpw-xe-S74" id="9Rb-zh-uE8"/>
+                <outlet property="fibTableView" destination="cwE-tM-0QM" id="9gU-Sg-Qgk"/>
                 <outlet property="forwardingSettingsView" destination="lQz-E7-PRx" id="d1y-fe-mMm"/>
                 <outlet property="generalSettingsView" destination="A7D-GN-X5W" id="paQ-iM-qEx"/>
                 <outlet property="namePrefixText" destination="Nr4-e2-zkN" id="2Nt-9H-SpG"/>
                 <outlet property="preferencesPanel" destination="coQ-VU-5RU" id="tZs-5C-1La"/>
                 <outlet property="prefixRegistrationSheet" destination="tRY-ba-DfO" id="FJr-yW-O1r"/>
                 <outlet property="securitySettingsView" destination="o3g-Q4-BEo" id="UDh-Kj-DYk"/>
+                <outlet property="tableController" destination="M6P-hs-Leb" id="Odo-he-xJv"/>
                 <outlet property="tunnelCombobox" destination="xrn-ng-SrO" id="cCr-A0-gR2"/>
             </connections>
         </customObject>
         <customObject id="Hcg-fF-E5x" customClass="LaunchAtLoginController"/>
+        <customObject id="M6P-hs-Leb" customClass="FibTableController"/>
         <menu id="ovl-jc-kIR">
             <items>
                 <menuItem title="NDN disconnected" id="yhj-L6-nZL">
@@ -181,11 +184,11 @@
             </connections>
         </window>
         <customView id="A7D-GN-X5W">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="348"/>
+            <rect key="frame" x="0.0" y="0.0" width="480" height="247"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <box autoresizesSubviews="NO" borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="dPr-jz-Nc2">
-                    <rect key="frame" x="17" y="227" width="446" height="103"/>
+                    <rect key="frame" x="17" y="126" width="446" height="103"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <view key="contentView">
                         <rect key="frame" x="1" y="1" width="444" height="101"/>
@@ -261,7 +264,7 @@
                     <color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                 </box>
                 <box autoresizesSubviews="NO" title="Box" borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="p9d-6I-rmw">
-                    <rect key="frame" x="17" y="152" width="446" height="73"/>
+                    <rect key="frame" x="17" y="51" width="446" height="73"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <view key="contentView">
                         <rect key="frame" x="1" y="1" width="444" height="71"/>
@@ -316,10 +319,10 @@
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8C0-3r-hw7">
-                    <rect key="frame" x="11" y="210" width="458" height="33"/>
+                    <rect key="frame" x="17" y="210" width="446" height="33"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <constraints>
-                        <constraint firstAttribute="height" constant="33" id="tR1-xN-eLn"/>
+                        <constraint firstAttribute="height" constant="33" id="Yi6-p4-aJY"/>
                     </constraints>
                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="FIB" id="zB2-9L-OLy">
                         <font key="font" size="30" name="LucidaGrande"/>
@@ -327,22 +330,22 @@
                         <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
                     </textFieldCell>
                 </textField>
-                <scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pwe-zt-TSj">
-                    <rect key="frame" x="20" y="53" width="441" height="149"/>
+                <scrollView horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="pwe-zt-TSj">
+                    <rect key="frame" x="20" y="53" width="440" height="149"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                    <clipView key="contentView" id="sSD-vM-Ynn">
-                        <rect key="frame" x="1" y="17" width="439" height="131"/>
+                    <clipView key="contentView" copiesOnScroll="NO" id="sSD-vM-Ynn">
+                        <rect key="frame" x="1" y="17" width="438" height="131"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" headerView="LTh-Cz-kn3" id="cwE-tM-0QM">
-                                <rect key="frame" x="0.0" y="0.0" width="439" height="131"/>
+                            <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" headerView="LTh-Cz-kn3" id="cwE-tM-0QM">
+                                <rect key="frame" x="0.0" y="0.0" width="438" height="131"/>
                                 <autoresizingMask key="autoresizingMask"/>
                                 <size key="intercellSpacing" width="3" height="2"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
                                 <tableColumns>
-                                    <tableColumn width="209.12890625" minWidth="40" maxWidth="1000" id="uNg-7f-0Fn">
-                                        <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
+                                    <tableColumn editable="NO" width="217.93359375" minWidth="40" maxWidth="1000" id="uNg-7f-0Fn">
+                                        <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="NDN prefix">
                                             <font key="font" metaFont="smallSystem"/>
                                             <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
@@ -352,10 +355,10 @@
                                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
-                                        <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
+                                        <tableColumnResizingMask key="resizingMask" userResizable="YES"/>
                                     </tableColumn>
-                                    <tableColumn width="224" minWidth="40" maxWidth="1000" id="Lyf-oJ-Usx">
-                                        <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
+                                    <tableColumn editable="NO" width="45.0703125" minWidth="40" maxWidth="1000" id="Lyf-oJ-Usx">
+                                        <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Face ID">
                                             <font key="font" metaFont="smallSystem"/>
                                             <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
@@ -365,23 +368,39 @@
                                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                         </textFieldCell>
-                                        <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
+                                        <tableColumnResizingMask key="resizingMask" userResizable="YES"/>
+                                    </tableColumn>
+                                    <tableColumn editable="NO" width="145.61328125" minWidth="10" maxWidth="3.4028234663852886e+38" id="qRZ-T3-vj8">
+                                        <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Endpoint">
+                                            <font key="font" metaFont="smallSystem"/>
+                                            <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
+                                            <color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
+                                        </tableHeaderCell>
+                                        <textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="jKf-Cl-jvW">
+                                            <font key="font" metaFont="system"/>
+                                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                            <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                        </textFieldCell>
+                                        <tableColumnResizingMask key="resizingMask" userResizable="YES"/>
                                     </tableColumn>
                                 </tableColumns>
+                                <connections>
+                                    <outlet property="dataSource" destination="M6P-hs-Leb" id="NbM-Xt-2RQ"/>
+                                </connections>
                             </tableView>
                         </subviews>
                         <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                     </clipView>
                     <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" id="l9T-JI-kUJ">
-                        <rect key="frame" x="1" y="1" width="0.0" height="16"/>
+                        <rect key="frame" x="-100" y="-100" width="438" height="16"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
-                    <scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" id="Ohc-CY-k3U">
-                        <rect key="frame" x="-15" y="17" width="16" height="0.0"/>
+                    <scroller key="verticalScroller" verticalHuggingPriority="750" id="Ohc-CY-k3U">
+                        <rect key="frame" x="423" y="17" width="16" height="131"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
                     <tableHeaderView key="headerView" id="LTh-Cz-kn3">
-                        <rect key="frame" x="0.0" y="0.0" width="439" height="17"/>
+                        <rect key="frame" x="0.0" y="0.0" width="438" height="17"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </tableHeaderView>
                 </scrollView>
@@ -397,10 +416,10 @@
                     </connections>
                 </button>
                 <button translatesAutoresizingMaskIntoConstraints="NO" id="gQI-Og-HTs">
-                    <rect key="frame" x="64" y="20" width="24" height="25"/>
+                    <rect key="frame" x="64" y="20" width="34" height="25"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <constraints>
-                        <constraint firstAttribute="width" constant="24" id="3O2-RL-Bwo"/>
+                        <constraint firstAttribute="width" constant="34" id="0LB-Iy-ql1"/>
                     </constraints>
                     <buttonCell key="cell" type="square" title="-" bezelStyle="shadowlessSquare" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="MLe-yE-kAQ">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -412,18 +431,16 @@
                 </button>
             </subviews>
             <constraints>
+                <constraint firstItem="pwe-zt-TSj" firstAttribute="top" secondItem="8C0-3r-hw7" secondAttribute="bottom" constant="8" symbolic="YES" id="14y-21-z0L"/>
                 <constraint firstItem="pwe-zt-TSj" firstAttribute="leading" secondItem="lQz-E7-PRx" secondAttribute="leading" constant="20" symbolic="YES" id="5me-XE-Y3X"/>
-                <constraint firstItem="pwe-zt-TSj" firstAttribute="top" secondItem="8C0-3r-hw7" secondAttribute="bottom" constant="8" symbolic="YES" id="9V1-Nb-T1c"/>
-                <constraint firstAttribute="centerX" secondItem="8C0-3r-hw7" secondAttribute="centerX" id="B5J-y5-Jw0"/>
-                <constraint firstItem="gQI-Og-HTs" firstAttribute="top" secondItem="pwe-zt-TSj" secondAttribute="bottom" constant="8" symbolic="YES" id="DUz-1v-jfV"/>
-                <constraint firstItem="gQI-Og-HTs" firstAttribute="leading" secondItem="bzX-Tt-J0Y" secondAttribute="trailing" constant="10" symbolic="YES" id="G8c-bW-N9r"/>
-                <constraint firstItem="8C0-3r-hw7" firstAttribute="leading" secondItem="lQz-E7-PRx" secondAttribute="leading" constant="14" id="I06-Ye-yiY"/>
-                <constraint firstItem="8C0-3r-hw7" firstAttribute="top" secondItem="lQz-E7-PRx" secondAttribute="top" constant="10" id="Kh2-t8-I8t"/>
-                <constraint firstItem="pwe-zt-TSj" firstAttribute="top" secondItem="8C0-3r-hw7" secondAttribute="bottom" constant="8" id="M0q-Ge-laF"/>
-                <constraint firstAttribute="bottom" secondItem="gQI-Og-HTs" secondAttribute="bottom" constant="20" symbolic="YES" id="Sl7-Ea-MVs"/>
-                <constraint firstItem="gQI-Og-HTs" firstAttribute="leading" secondItem="lQz-E7-PRx" secondAttribute="leading" constant="64" id="WvQ-vg-YwD"/>
+                <constraint firstItem="8C0-3r-hw7" firstAttribute="top" secondItem="lQz-E7-PRx" secondAttribute="top" constant="10" id="Afe-2S-bU9"/>
+                <constraint firstItem="gQI-Og-HTs" firstAttribute="baseline" secondItem="bzX-Tt-J0Y" secondAttribute="baseline" id="Ibd-jx-qJJ"/>
+                <constraint firstItem="8C0-3r-hw7" firstAttribute="leading" secondItem="pwe-zt-TSj" secondAttribute="leading" id="SdO-zS-L0k"/>
+                <constraint firstItem="8C0-3r-hw7" firstAttribute="trailing" secondItem="pwe-zt-TSj" secondAttribute="trailing" id="VP4-2d-n2W"/>
+                <constraint firstItem="gQI-Og-HTs" firstAttribute="leading" secondItem="lQz-E7-PRx" secondAttribute="leading" constant="64" id="fcS-2H-k8g"/>
                 <constraint firstItem="bzX-Tt-J0Y" firstAttribute="top" secondItem="pwe-zt-TSj" secondAttribute="bottom" constant="8" symbolic="YES" id="gb4-7g-j6B"/>
-                <constraint firstItem="gQI-Og-HTs" firstAttribute="baseline" secondItem="bzX-Tt-J0Y" secondAttribute="baseline" id="nCo-gK-obk"/>
+                <constraint firstAttribute="bottom" secondItem="gQI-Og-HTs" secondAttribute="bottom" constant="20" symbolic="YES" id="tXT-xP-W3Z"/>
+                <constraint firstItem="gQI-Og-HTs" firstAttribute="leading" secondItem="bzX-Tt-J0Y" secondAttribute="trailing" constant="10" symbolic="YES" id="ueH-Fo-FuB"/>
                 <constraint firstItem="pwe-zt-TSj" firstAttribute="leading" secondItem="bzX-Tt-J0Y" secondAttribute="leading" id="upa-cN-R9y"/>
                 <constraint firstItem="pwe-zt-TSj" firstAttribute="centerX" secondItem="lQz-E7-PRx" secondAttribute="centerX" id="xhq-9c-a7S"/>
             </constraints>
diff --git a/osx/Resources/status-to-fib.xslt b/osx/Resources/status-to-fib.xslt
new file mode 100644
index 0000000..e4ad841
--- /dev/null
+++ b/osx/Resources/status-to-fib.xslt
@@ -0,0 +1,29 @@
+<xsl:stylesheet version = '1.0'
+                xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
+
+<xsl:template match="/ndnd">
+<fibs>
+<xsl:apply-templates select="forwarding/fentry" />
+</fibs>
+</xsl:template>
+
+<xsl:template match="fentry">
+<fib>
+<xsl:apply-templates select="dest/faceid" />
+<prefix><xsl:value-of select="prefix"/></prefix>
+</fib>
+</xsl:template>
+
+<xsl:template match="faceid">
+<xsl:variable name="id"><xsl:value-of select="." /></xsl:variable>
+<faceID><xsl:copy-of select="$id" /></faceID>
+<ip>
+<xsl:choose>
+  <xsl:when test="count(//face/ip[../faceid=$id]) &gt; 0"><xsl:value-of select="//face/ip[../faceid=$id]" />
+  </xsl:when>
+  <xsl:otherwise>app</xsl:otherwise>
+</xsl:choose>
+</ip>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/osx/fib-table-controller.h b/osx/fib-table-controller.h
new file mode 100644
index 0000000..1dd074f
--- /dev/null
+++ b/osx/fib-table-controller.h
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface FibTableController : NSObject <NSTableViewDataSource, NSXMLParserDelegate>
+{
+  NSXMLDocument *m_document;
+}
+
+@property NSTableView *m_tableView;
+
+- (void)loadStatus:(NSXMLDocument *)document;
+- (NSString *)getFaceByRowIndex:(NSInteger)index;
+- (NSString *)getPrefixByRowIndex:(NSInteger)index;
+
+@end
diff --git a/osx/fib-table-controller.mm b/osx/fib-table-controller.mm
new file mode 100644
index 0000000..2f8e96e
--- /dev/null
+++ b/osx/fib-table-controller.mm
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#include "config.h"
+#import "fib-table-controller.h"
+
+@implementation FibTableController
+
+- (void)loadStatus:(NSXMLDocument *)document
+{
+  m_document = document;
+}
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+  if (m_document == nil)
+    {
+      return 0;
+    }
+  else
+    {
+      return [[m_document rootElement] childCount];
+    }
+}
+
+-(id)tableView:(NSTableView *)aTableView
+  objectValueForTableColumn:(NSTableColumn *)aTableColumn 
+  row:(NSInteger)rowIndex
+{
+  NSXMLNode *element = [[m_document rootElement] childAtIndex:rowIndex];
+
+  if([[[aTableColumn headerCell] stringValue] isEqual:@"NDN prefix"])
+  {
+    return [[element childAtIndex:2] stringValue];
+  }
+  else if([[[aTableColumn headerCell] stringValue] isEqual:@"Face ID"])
+  {
+    return [[element childAtIndex:0] stringValue];
+  }
+  else if([[[aTableColumn headerCell] stringValue] isEqual:@"Endpoint"])
+  {
+    return [[element childAtIndex:1] stringValue];
+  }
+  
+  return nil;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////
+
+- (NSString *)getFaceByRowIndex:(NSInteger)index
+{
+  NSXMLNode *element = [[m_document rootElement] childAtIndex:index];
+  return [[element childAtIndex:0] stringValue];
+}
+
+- (NSString *)getPrefixByRowIndex:(NSInteger)index
+{
+  NSXMLNode *element = [[m_document rootElement] childAtIndex:index];
+  return [[element childAtIndex:2] stringValue];
+}
+
+@end
diff --git a/osx/menu-delegate.h b/osx/menu-delegate.h
index 994ed4c..27ced8c 100644
--- a/osx/menu-delegate.h
+++ b/osx/menu-delegate.h
@@ -18,6 +18,7 @@
   NSImage *m_connectedIcon;
   NSImage *m_disconnectedIcon;
   NSData  *m_statusXslt;
+  NSData  *m_statusToFibXslt;
 
   IBOutlet NSPopover *statusPopover;
 
diff --git a/osx/menu-delegate.mm b/osx/menu-delegate.mm
index 24102fd..c47e0b9 100644
--- a/osx/menu-delegate.mm
+++ b/osx/menu-delegate.mm
@@ -32,6 +32,7 @@
   m_connectedIcon = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"FlatConnected" ofType:@"png"]];
   m_disconnectedIcon = [[NSImage alloc] initWithContentsOfFile:[bundle pathForResource:@"FlatDisconnected" ofType:@"png"]];
   m_statusXslt = [NSData dataWithContentsOfFile:[bundle pathForResource:@"status" ofType:@"xslt"]];
+  m_statusToFibXslt = [NSData dataWithContentsOfFile:[bundle pathForResource:@"status-to-fib" ofType:@"xslt"]];
   
   NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 1.0
                       target: self
@@ -116,12 +117,18 @@
     [statusItem setImage:m_connectedIcon];
   }
 
-  NSXMLDocument *result = [document objectByApplyingXSLT:m_statusXslt
-                           arguments:nil
-                           error:nil];
+  NSXMLDocument *statusXml = [document objectByApplyingXSLT:m_statusXslt
+                              arguments:nil
+                              error:nil];
 
-  m_statusString = [[NSAttributedString alloc]initWithHTML:[result XMLData] documentAttributes:NULL];
+  NSXMLDocument *statusFibXml = [document objectByApplyingXSLT:m_statusToFibXslt
+                                 arguments:nil
+                                 error:nil];
+
+  m_statusString = [[NSAttributedString alloc]initWithHTML:[statusXml XMLData] documentAttributes:NULL];
   [daemonStatusHtml setAttributedStringValue:m_statusString];
+
+  [preferencesDelegate updateFibStatus:statusFibXml];
 }
 
 - (void)statusUnavailable:(id)none
@@ -134,7 +141,10 @@
     
     [statusItem setImage:m_disconnectedIcon];
   }
-  
+
+  [daemonStatusHtml setStringValue:@""];
+  [preferencesDelegate updateFibStatus:nil];
+
   [m_operationQueue addOperationWithBlock:^{
       NSTask *task = [[NSTask alloc] init];
       [task setLaunchPath: @NDND_START_COMMAND];
diff --git a/osx/preference-delegate.h b/osx/preference-delegate.h
index 4ecd46b..fdc48bd 100644
--- a/osx/preference-delegate.h
+++ b/osx/preference-delegate.h
@@ -7,12 +7,16 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#import "fib-table-controller.h"
 
 @interface PreferenceDelegate : NSObject
 {
   IBOutlet NSWindow *preferencesPanel;
   IBOutlet NSView *generalSettingsView;
+  
   IBOutlet NSView *forwardingSettingsView;
+  IBOutlet NSTableView *fibTableView;
+  
   IBOutlet NSView *securitySettingsView;
   IBOutlet NSView *testbedSettingsView;
   
@@ -20,6 +24,9 @@
   IBOutlet NSComboBox *tunnelCombobox;
   IBOutlet NSTextField *namePrefixText;
   IBOutlet NSTextField *endpointText;
+  
+  IBOutlet FibTableController *tableController;
+  NSOperationQueue *m_operationQueue;
 }
 
 @property BOOL allowSoftwareUpdates;
@@ -29,17 +36,18 @@
 -(IBAction)openGeneralSettings:(id)sender;
 -(IBAction)openForwardingSettings:(id)sender;
 -(IBAction)openSecuritySettings:(id)sender;
--(IBAction)openTestbedSettings:(id)sender;
 
 -(IBAction)switchSoftwareUpdates:(id)sender;
 -(IBAction)switchHubDiscovery:(id)sender;
--(IBAction)restartDaemon:(id)sender;
 
 -(IBAction)addFibEntry:(id)sender;
 -(IBAction)removeFibEntry:(id)sender;
--(IBAction) showFibEntrySheet:(id)sender;
+-(IBAction)showFibEntrySheet:(id)sender;
 -(IBAction)hideFibEntrySheet:(id)sender;
 
 -(IBAction)openRoutingStatusPage:(id)sender;
 -(IBAction)openTrafficMapPage:(id)sender;
+
+-(void)updateFibStatus:(NSXMLDocument*)status;
+
 @end
diff --git a/osx/preference-delegate.mm b/osx/preference-delegate.mm
index 2760908..b19e369 100644
--- a/osx/preference-delegate.mm
+++ b/osx/preference-delegate.mm
@@ -16,6 +16,11 @@
   [preferencesPanel setContentView:generalSettingsView];
   [preferencesPanel makeKeyAndOrderFront:sender];
   [preferencesPanel setLevel: NSStatusWindowLevel];
+  
+  if(m_operationQueue == nil)
+    m_operationQueue = [[NSOperationQueue alloc] init];
+  
+  tableController.m_tableView = fibTableView;
 }
 
 -(IBAction)openGeneralSettings:(id)sender
@@ -33,11 +38,6 @@
   [preferencesPanel setContentView:securitySettingsView];
 }
 
--(IBAction)openTestbedSettings:(id)sender
-{
-  [preferencesPanel setContentView:testbedSettingsView];
-}
-
 -(IBAction)switchSoftwareUpdates:(id)sender
 {
   if ([(NSButton*)sender state] == NSOnState)
@@ -62,20 +62,10 @@
   }
 }
 
--(IBAction)restartDaemon:(id)sender
+-(void)updateFibStatus:(NSXMLDocument*)status;
 {
-  /*daemonStarted = false;
-  [sender setTitle:@"Start"];
-  [connectionStatusText setStringValue:@"Disconnected"];
-    
-  NSTask *task = [[NSTask alloc] init];
-  [task setLaunchPath: NDND_STOP_COMMAND];
-  [task launch];
-    
-  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
-  NSString *path = [bundle pathForResource:@"FlatDisconnected" ofType:@"png"];
-  menuIcon = [[NSImage alloc] initWithContentsOfFile:path];
-  [statusItem setImage:menuIcon];*/
+  [tableController loadStatus:status];
+  [fibTableView reloadData];
 }
 
 -(IBAction)addFibEntry:(id)sender
@@ -83,40 +73,59 @@
   [NSApp endSheet:prefixRegistrationSheet];
   [prefixRegistrationSheet orderOut:sender];
   
-  NSString *operationName = @"add";
-  
   NSString *prefixName = [namePrefixText stringValue];
-  NSString *socketType = [tunnelCombobox itemObjectValueAtIndex:[tunnelCombobox indexOfSelectedItem]];
-  NSString *address = [endpointText stringValue];
+  NSString *tunnelType = [tunnelCombobox itemObjectValueAtIndex:[tunnelCombobox indexOfSelectedItem]];
+  NSString *endpoint = [endpointText stringValue];
+  
+  [m_operationQueue addOperationWithBlock:^{
+      NSTask *task = [[NSTask alloc] init];
+      [task setLaunchPath: @NDND_FIB_COMMAND];
+      [task setArguments: [NSArray arrayWithObjects: @"add", prefixName, tunnelType, endpoint, nil]];
+      [task launch];
+      [task waitUntilExit];
+    }];
 
-  NSArray *arguments = [NSArray arrayWithObjects: operationName, prefixName, socketType, address, nil];
-
-  NSTask *task = [[NSTask alloc] init];
-  [task setLaunchPath: @NDND_FIB_COMMAND];
-  [task setArguments: arguments];
-  [task launch];
 }
 
 -(IBAction)removeFibEntry:(id)sender
 {
+  NSInteger selectedRow = [fibTableView selectedRow];
+  
+  if(selectedRow == -1)
+    return;
+  
+  NSString *faceID = [tableController getFaceByRowIndex:selectedRow];
+  if (faceID == nil)
+    return;
 
+  NSString *prefix = [tableController getPrefixByRowIndex:selectedRow];
+  if (prefix == nil)
+    return;
+
+  [m_operationQueue addOperationWithBlock:^{
+      NSTask *task = [[NSTask alloc] init];
+      [task setLaunchPath: @NDND_FIB_COMMAND];
+      [task setArguments: [NSArray arrayWithObjects: @"del", prefix, @"face", faceID, nil]];
+      [task launch];
+      [task waitUntilExit];
+    }];
 }
 
 - (IBAction) showFibEntrySheet:(id)sender
 {
-    [NSApp beginSheet:prefixRegistrationSheet
+  [NSApp beginSheet:prefixRegistrationSheet
     modalForWindow:preferencesPanel
     modalDelegate:self
     didEndSelector:nil
     contextInfo:nil];
   
-    [tunnelCombobox selectItemAtIndex:0];
+  [tunnelCombobox selectItemAtIndex:0];
 }
 
 -(IBAction)hideFibEntrySheet:(id)sender
 {
-    [NSApp endSheet:prefixRegistrationSheet];
-    [prefixRegistrationSheet orderOut:sender];
+  [NSApp endSheet:prefixRegistrationSheet];
+  [prefixRegistrationSheet orderOut:sender];
 }